It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
//Shrink an array down to at most 3 elements
//Helper function
function get3(info) {
//If you want more or less payouts, change this 3
while(info.length > 3)
info.shift();
return info;
}
//Fetches asset info based on ticker
function getInfo(ticker) {
return glbseCachedFetch("/api/asset/" + ticker);
}
//Fetches dividend info based on ticker
function getDiv(ticker) {
return glbseCachedFetch("/api/dividends/asset/" + ticker);
}
//Fetches the price of an asset
//Returns first non-zero price from the list of 24h average, 5 day average, 7 day average, or last trade
function getPrice(ticker) {
var info = getInfo(ticker);
return (info.t24havg/100000000) || (info.t5davg/100000000) || (info.t7davg/100000000) || (info.latest_trade/100000000);
}
//Gets the average dividend from passed in array
function getDivArray(info) {
Logger.log("Into getDivArray");
if(info === null) return null;
if(info.length == 0) return 0;
Logger.log("Not null or zero length");
var divTotal = 0;
for(var i = 0; i < info.length; i++) {
divTotal += info[i].pps;
Logger.log("Step " + i + "/" + info.length + " " + String(divTotal));
}
Logger.log(String(divTotal));
return divTotal / info.length / 100000000;
}
//Gets average dividend of all payouts
function getAvgDividend(ticker) {
Logger.log("Into getAvgDividend " + ticker);
var info = getDiv(ticker);
Logger.log(info);
Logger.log("Got Info");
return getDivArray(info);
}
//Gets Average dividend of last 3 payouts
function get3AvgDividend(ticker) {
var info = get3(getDiv(ticker));
return getDivArray(info);
}
//Fetches info from GLBSE, caches when fetched and attempts to use the cache
//Caches info for 30 minutes
function glbseCachedFetch(apiUrl) {
var publicCache = CacheService.getPublicCache();
var cached = publicCache.get("http://glbse.com" + apiUrl);
if(cached !== null && JSON.parse(cached).length > 1 ){
return JSON.parse(cached);
} else {
getSleep();
//Browser.msgBox("Fetching");
Logger.log("Fetching");
var response = UrlFetchApp.fetch("http://glbse.com"+apiUrl);
//check for status code
var result = response.getContentText();
if(response.getResponseCode() < 300)//Only save if good fetch
publicCache.put("http://glbse.com"+apiUrl, result, 60 * 30);//30 * 60 seconds - 30 minutes
return JSON.parse(result);
}
}
//Allows small delay between multiple fetches to lighten the load on GLBSE site
function getSleep() {
var delay = 50;
var date = new Date();
var now = date.getTime();
var cache = CacheService.getPublicCache();
var cacheKey = "sleepUntil";
var timeString = cache.get(cacheKey);
var time = parseInt(timeString);
var sleep = time - now;
Logger.log(cacheKey + " " + timeString);
Logger.log("parseInt " + time);
Logger.log("sleeping " + sleep);
if((timeString === null) || (timeString == "NaN") || (time === null) || (time == NaN) || (sleep < 0)) {
cache.put(cacheKey, String(now + delay));
} else {
cache.put(cacheKey, String(time + delay));
Utilities.sleep(sleep);
}
}
//Days between payouts, based on all payouts
function daysBetween(ticker) {
var info = getDiv(ticker);
if(info === null) return null;
if(info.length < 2) return Infinity;
var first = info[0];
var last = info.pop();
return (last.timestamp - first.timestamp) / info.length / 3600 / 24;
}
//Days between payouts, based on the last 3 payouts
function daysBetween3(ticker) {
var info = get3(getDiv(ticker));
if(info === null) return null;
if(info.length < 2) return Infinity;
var first = info[0];
var last = info.pop();
return (last.timestamp - first.timestamp) / info.length / 3600 / 24;
}
x = share_ask_price/average_dividend/average_time_between_dividends