Bitcoin Forum
May 04, 2024, 12:35:47 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  

Warning: Moderators do not remove likely scams. You must use your own brain: caveat emptor. Watch out for Ponzi schemes. Do not invest more than you can afford to lose.

Pages: « 1 2 [3]  All
  Print  
Author Topic: GBLSE assets data spreadsheet  (Read 4678 times)
btharper
Sr. Member
****
Offline Offline

Activity: 389
Merit: 250



View Profile
June 04, 2012, 07:45:12 PM
 #41

This is what I've been using, hopefully it helps some
Code:
//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;
}
These are the functions I'm using in my sheet, and while I'm not quite ready to show off the whole thing I hope this might be helpful to someone. I'm looking to get these published to the gallergy, but approval takes a while. These can be used regularly in a sheet as a docs formula or as a function on other scripts. These may be used as if under any license or as public domain where available.

Tips to 18ef54UQ3t9ieqU3MebyqMHjCpzKrZzS5N are greatly appreciated if you've got the spare coin and find these useful.
1714826147
Hero Member
*
Offline Offline

Posts: 1714826147

View Profile Personal Message (Offline)

Ignore
1714826147
Reply with quote  #2

1714826147
Report to moderator
1714826147
Hero Member
*
Offline Offline

Posts: 1714826147

View Profile Personal Message (Offline)

Ignore
1714826147
Reply with quote  #2

1714826147
Report to moderator
There are several different types of Bitcoin clients. The most secure are full nodes like Bitcoin Core, which will follow the rules of the network no matter what miners do. Even if every miner decided to create 1000 bitcoins per block, full nodes would stick to the rules and reject those blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714826147
Hero Member
*
Offline Offline

Posts: 1714826147

View Profile Personal Message (Offline)

Ignore
1714826147
Reply with quote  #2

1714826147
Report to moderator
Tritonio (OP)
Hero Member
*****
Offline Offline

Activity: 640
Merit: 500


Vanity of vanities; all is vanity...


View Profile
June 05, 2012, 12:42:08 PM
 #42

So I was fooling around and made this: http://snipurl.com/glbsedata

Interesting, thank you. Please update that we pay dividends every 30 days, and that we are ID verified on the GLBSE. Thanks!

Done and done. You broke up your last divident payment into three payments though so it is a bit messed up. If you pay in a single payment next month it will be fine. But the code currently just picks the last payment and uses that alone.
Tritonio (OP)
Hero Member
*****
Offline Offline

Activity: 640
Merit: 500


Vanity of vanities; all is vanity...


View Profile
June 05, 2012, 12:45:20 PM
 #43

Added market capitalization. Which is (last price)*(securities issued). Is that correct?



It is not correct. As number of securities you can use the number of shares for which dividend was paid last time, but as a lot of assets didn't pay any dividend yet and also some of them are bought back on a monthly basis (PPT bonds) just after dividend payment, you have no way to find out exact number of shares outstanding on the market until GLBSE will show this number or issuers of those assets will tell you (if you want to update those numbers manually)

You can check the thread I started here: https://bitcointalk.org/index.php?topic=84399.0

I've hid the column for now. I'll consider putting it back in the future. Maybe I'll only do it for those that pay dividents since I can get that data automatically.
Tritonio (OP)
Hero Member
*****
Offline Offline

Activity: 640
Merit: 500


Vanity of vanities; all is vanity...


View Profile
June 05, 2012, 01:45:17 PM
 #44

Now it also gets the days between dividents automatically and uses the API to get everything.

BTW a little tip about the colors in the spreadsheet. They are mostly useful for me. Blue means that they are updated by the script in the background. Yellow are cells with formulas. And green are cells updated manually by me when needed.

I also added some more assets.
Tritonio (OP)
Hero Member
*****
Offline Offline

Activity: 640
Merit: 500


Vanity of vanities; all is vanity...


View Profile
June 09, 2012, 01:58:57 PM
 #45

Updated the OP with more links to different formats (HTML,PDF,CSV,TSV).  Wink
Use the CSV to import to Excel and do shorting by any column etc...
Tritonio (OP)
Hero Member
*****
Offline Offline

Activity: 640
Merit: 500


Vanity of vanities; all is vanity...


View Profile
June 22, 2012, 10:43:23 PM
 #46

More assets added.  Grin
Tritonio (OP)
Hero Member
*****
Offline Offline

Activity: 640
Merit: 500


Vanity of vanities; all is vanity...


View Profile
July 06, 2012, 01:46:38 AM
 #47

Again, added 11 more assets to the list. They will be up to date in a few minutes.
Pages: « 1 2 [3]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!