Skip to content

Instantly share code, notes, and snippets.

@Roman2K
Created January 6, 2014 17:23
Show Gist options
  • Save Roman2K/8286171 to your computer and use it in GitHub Desktop.
Save Roman2K/8286171 to your computer and use it in GitHub Desktop.
Drive > Spreadsheet > Tools > Script editor...
function onOpen() {
SpreadsheetApp.getActiveSpreadsheet().addMenu("Update", [
{name: "Prices", functionName: "updatePrices"}
]);
}
function updatePrices() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getRange('D2');
while (/^...\/...$/.test(cell.getValue())) {
var ticker = cell.getValue().replace('/', '_').toLowerCase();
var valueCell = sheet.getRange(cell.getRow(), cell.getColumn() + 1);
var url = 'https://btc-e.com/api/2/' + ticker + '/ticker';
Logger.log('Fetching last price for ' + ticker);
var lastPrice = JSON.parse(UrlFetchApp.fetch(url)).ticker.last;
Logger.log('Last price for ' + ticker + ' = ' + lastPrice);
valueCell.setValue(lastPrice);
cell = sheet.getRange(cell.getRow() + 1, cell.getColumn());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment