Last active
February 14, 2020 21:12
-
-
Save hesido/867185a25c962fc48e8709b64f312900 to your computer and use it in GitHub Desktop.
TradeOgre ticker script for Google Spreadsheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns Ticker Price From TradeOgre exchange | |
* Function accepts ranges as well, please use it to reduce server lookups, so it fetches data only once. | |
* | |
* @param {string} ticker name | |
* @param {string} ticker type | |
* @return {number} ticker price | |
* @customfunction | |
**/ | |
function ReturnTickerPrice(TickerName, TickerType) { | |
TickerType = TickerType || "bid"; | |
var marketdata = JSON.parse(UrlFetchApp.fetch("https://tradeogre.com/api/v1/markets").getContentText()); | |
if (TickerName.map) return TickerName.map(function(tname) {return TickerPriceForPair(tname);}); | |
else return TickerPriceForPair(TickerName); | |
function TickerPriceForPair(tickername, tickertype) { | |
tickertype = tickertype || TickerType; | |
if(Array.isArray(tickertype) && Array.isArray(tickertype[0])) { | |
return tickertype[0].map(function(tType) {return TickerPriceForPair(tickername, tType);}); | |
} | |
var tickerfilter = marketdata.filter(function(tkobj) {return tkobj[tickername];}); | |
var tickerobject = (tickerfilter[0] && tickerfilter[0][tickername]) || null; | |
return (tickerobject && tickerobject[tickertype]) || (tickerobject && tickertype) || "Ticker not found!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
https://docs.google.com/spreadsheets/d/1ZVhM6K48tA38InJVzqIx6GxykAxtcnknaAMmRXtNfPU/edit?usp=sharing