Skip to content

Instantly share code, notes, and snippets.

@kmikiy
Last active June 16, 2022 12:17

Revisions

  1. kmikiy revised this gist Aug 10, 2020. 1 changed file with 2 additions and 21 deletions.
    23 changes: 2 additions & 21 deletions crypto.gs
    Original file line number Diff line number Diff line change
    @@ -7,31 +7,12 @@ function BINANCE_PRICE(coinsymbol, pair) {
    return data.price
    }

    function CRYPTOPIA_PRICE(coinsymbol, pair) {
    var url = "https://www.cryptopia.co.nz/api/GetMarket/"+coinsymbol.toUpperCase()+"_"+pair.toUpperCase()
    var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
    var json = response.getContentText();
    var data = JSON.parse(json);
    return data.Data.LastPrice
    }

    function CRYPTO_PRICE(site, symbol, pair) {
    if (site.toLowerCase() == "binance") {
    return BINANCE_PRICE(symbol, pair)
    }
    if (site.toLowerCase() == "cryptopia") {
    return CRYPTOPIA_PRICE(symbol, pair)
    }
    return 0
    }


    /*
    USAGE example
    Enter:
    =CRYPTO_PRICE("Binance","ELF","BTC")
    =BINANCE_PRICE("LTC", "BTC")
    in a cell to get the last trade price of ELF/BTC on binance
    in a cell to get the last trade price of LTC/BTC on binance
    */
  2. kmikiy revised this gist Jan 16, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions crypto.gs
    Original file line number Diff line number Diff line change
    @@ -29,9 +29,9 @@ function CRYPTO_PRICE(site, symbol, pair) {
    /*
    USAGE example
    Enter in a cell
    Enter:
    =CRYPTO_PRICE("Binance","ELF","BTC")
    to get the last trade price of ELF/BTC on binance
    in a cell to get the last trade price of ELF/BTC on binance
    */
  3. kmikiy created this gist Jan 15, 2018.
    37 changes: 37 additions & 0 deletions crypto.gs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@

    function BINANCE_PRICE(coinsymbol, pair) {
    var url = "https://api.binance.com/api/v3/ticker/price?symbol="+coinsymbol.toUpperCase()+pair.toUpperCase()
    var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
    var json = response.getContentText();
    var data = JSON.parse(json);
    return data.price
    }

    function CRYPTOPIA_PRICE(coinsymbol, pair) {
    var url = "https://www.cryptopia.co.nz/api/GetMarket/"+coinsymbol.toUpperCase()+"_"+pair.toUpperCase()
    var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
    var json = response.getContentText();
    var data = JSON.parse(json);
    return data.Data.LastPrice
    }

    function CRYPTO_PRICE(site, symbol, pair) {
    if (site.toLowerCase() == "binance") {
    return BINANCE_PRICE(symbol, pair)
    }
    if (site.toLowerCase() == "cryptopia") {
    return CRYPTOPIA_PRICE(symbol, pair)
    }
    return 0
    }


    /*
    USAGE example
    Enter in a cell
    =CRYPTO_PRICE("Binance","ELF","BTC")
    to get the last trade price of ELF/BTC on binance
    */