Created
December 9, 2017 16:57
-
-
Save jonparker/8deaa9e106a20f63f59de6abff42ca92 to your computer and use it in GitHub Desktop.
Updates a list of Google Sheets with the rate from Poloniex
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
// 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