Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thomasbergernz/06a229b1670723e51d4e326e22034725 to your computer and use it in GitHub Desktop.
Save thomasbergernz/06a229b1670723e51d4e326e22034725 to your computer and use it in GitHub Desktop.
Updates a list of Google Sheets with the rate from Poloniex
// Updates the A2 cell of the APIPull tab of the given Google
// sheet with the corresponding rate pulled from Poloniex.
// The Google sheet ID is in the URL. E.g.:
// https://docs.google.com/spreadsheets/d/**this part of the url is the Sheet id***/edit#gid=685386329
function fetchTicker() {
var rates = [{ RATE: 'BTC_XRP', SheetID: 'your google sheet id for XRP'},
{ RATE: 'BTC_ETH', SheetID: 'your google sheet id for ETH' },
{ RATE: 'BTC_LTC', SheetID: 'your google sheet id for LTC' }
];
var url = 'https://poloniex.com/public?command=returnTicker';
var apiResponse = UrlFetchApp.fetch(url);
var rateData = JSON.parse(apiResponse.getContentText());
for(var rate in rates)
{
var sheet = SpreadsheetApp.openById(rates[rate].SheetID);
var apiTab = sheet.getSheetByName('APIPull');
// Clear existing data
apiTab.getRange('A2').clearContent();
var rateCode = rates[rate].RATE;
var rateValue = rateData[rateCode].highestBid;
rateCell = apiTab.getRange('A2');
rateCell.setValue(rateValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment