Skip to content

Instantly share code, notes, and snippets.

@yukihirai0505
Last active January 12, 2018 11:04
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/de452c6d3ee399e3b62673c85f5c0af8 to your computer and use it in GitHub Desktop.
Save yukihirai0505/de452c6d3ee399e3b62673c85f5c0af8 to your computer and use it in GitHub Desktop.
Binance(バイナンス)の銘柄情報取得プログラム
var BK = SpreadsheetApp.getActiveSpreadsheet(),
SHEET = BK.getSheetByName('portfolio');
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));
}
var btcJpyPrice = fetchJson('https://api.zaif.jp/api/1/last_price/btc_jpy').last_price,
binancePrices = fetchJson('https://api.binance.com/api/v1/ticker/allPrices').filter(function (e) {
if (e.symbol.match(/BTC$/gi)) {
return e;
}
}),
marketCap = fetchJson('https://api.coinmarketcap.com/v1/ticker/?limit=0'),
data = binancePrices.map(function (e) {
var symbol = e.symbol.slice(0, -3),
price = e.price * btcJpyPrice,
cap = marketCap.filter(function (cap) {
if (symbol === cap.symbol) {
return cap;
}
});
if (cap.length > 0) {
var capData = cap[0];
return [symbol, price, capData.total_supply, capData.max_supply, capData.rank];
} else {
return [symbol, price, "", "", ""];
}
});
SHEET.getRange(2, 1, data.length, 5).setValues(data);
}

Binance(バイナンス)に上場している仮想通貨において 以下の情報を取得するプログラム

  1. 時価総額順位
  2. 価格
  3. 供給量
  • ビットコインはZaif(ザイフ)の最終取引価格を使用
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment