Skip to content

Instantly share code, notes, and snippets.

@yukihirai0505
Last active February 9, 2018 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukihirai0505/4b364debf6e834ffbc9999a954146f81 to your computer and use it in GitHub Desktop.
Save yukihirai0505/4b364debf6e834ffbc9999a954146f81 to your computer and use it in GitHub Desktop.
Get crypto currency data from zaif and binance
var BK = SpreadsheetApp.getActiveSpreadsheet(),
SHEET = BK.getSheetByName('portfolio'),
BTC_SYMBOL = 'BTC';
function onOpen() {
function showMenu() {
var menu = [
{name: "Get Crypto Currency Data", functionName: "setData"}
];
BK.addMenu("Custom Management", menu);
}
showMenu();
}
function setData() {
function fetchJson(url) {
return JSON.parse(UrlFetchApp.fetch(url));
}
function getBinancePrice(symbol) {
return fetchJson('https://api.binance.com/api/v3/ticker/price?symbol=' + symbol + BTC_SYMBOL).price;
}
var btcJpyPrice = //fetchJson('https://api.bitflyer.jp/v1/ticker').ltp,
fetchJson('https://api.zaif.jp/api/1/last_price/btc_jpy').last_price,
range = SHEET.getRange(2, 1, SHEET.getLastRow(), 7),
data = range.getValues().map(function (e) {
var symbol = e[0],
quality = e[1],
getBtcPrice = e[2];
if (symbol === BTC_SYMBOL) {
e[5] = btcJpyPrice;
e[6] = btcJpyPrice * quality;
return e;
}
Logger.log(symbol);
if (symbol) {
var btcPrice = getBinancePrice(symbol);
Logger.log(btcPrice);
if (btcPrice) {
var jpy = btcPrice * btcJpyPrice;
e[3] = btcPrice;
e[4] = (btcPrice / getBtcPrice) - 1;
e[5] = jpy;
e[6] = jpy * quality;
e
}
}
return e;
});
range.setValues(data);
}

下記の情報を取得して、 自分が所有している仮想通貨の現在価格を算出する

  1. ZaifAPIからビットコインの最終取引価格を取得
  2. Biannceから現在の取引価格を取得
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment