Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Binance API isn't pulling all rates #42

Open
rshambaugh opened this issue Mar 22, 2019 · 8 comments
Open

Binance API isn't pulling all rates #42

rshambaugh opened this issue Mar 22, 2019 · 8 comments

Comments

@rshambaugh
Copy link

I'm connected to the Binance API and the sheet updates, as expected. However, not all currencies in my account are pulling all data from Binance. For example, I have FUEL and WAN in my portfolio, and the script pulls the coin symbol name (FUEL, WAN), but no other data for that coin, including my balance, the full coin name, or trading rates. Here's a screenshot of those two rows in my sheet.

Screen Shot 2019-03-22 at 3 56 47 AM

@rshambaugh
Copy link
Author

Here's another example of what's showing up and now showing up:
Screen Shot 2019-03-22 at 8 12 33 AM

@emmtte
Copy link
Owner

emmtte commented Mar 22, 2019

Hi, and welcome.
Yes I saw that last time. Coinmarketcap change the api 2 or 3 month ago.
It's seems free api from coinmarketcap gave only the 100 first coins
We need to rewrite this coinmarketcap.js and use an API key now.
Need to log on https://coinmarketcap.com/api/ create an account and choose basic account.
I have no time at the moment to do this. May be one day... so need help

@emmtte
Copy link
Owner

emmtte commented Mar 22, 2019

just a patch if you need
put your API key after 'X-CMC_PRO_API_KEY': '<<<>>>'
replace API_coinmarketcap.gs
by this

 function getCoinData() {
  var options = {
    "muteHttpExceptions": true,
    "headers" : {
      'X-CMC_PRO_API_KEY': '<<<<your api key here>>>>'
    },
  }

  var url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency";
  var endpoint = "/listings/latest"; // endpoint
  var param = "?start=1&limit=500&cryptocurrency_type=tokens&convert=EUR"

  try {
      var response = UrlFetchApp.fetch(url + endpoint + param, options);
  } catch(e) {
    Logger.log("message:" + e.message + "\nfileName:" + e.fileName + "\nlineNumber:" + e.lineNumber + "\nstack:" + e.stack);
    return false;
  }
  Logger.log(response)
  var results = JSON.parse(response.getContentText());
  Logger.log(results)
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Sheet1");

  return setCryptocurrencyData(sheet, results);
}

function setCryptocurrencyData(sheet, results) {
    var num = results['data'].length;
    var coins = [];
      coins.push(['シンボル', '価格(BTC)', '24時間の出来高']);
    for (var i = 0; i < results['data'].length; i++) {
        var symbol = results['data'][i]["symbol"];
        //var price = results['data'][i]["quote"]["BTC"]["price"];
        //var volume_24h = results['data'][i]["quote"]["BTC"]["volume_24h"];
        coins.push([symbol]);
    }

    var range = sheet.getRange(1, 1, results['data'].length + 1, coins[0].length);
    //range.setValues(coins);
}

@rshambaugh
Copy link
Author

Thanks. I see what you're doing with the patch, but I'm not sure what you mean by

replace API_coinmarketcap.gs
by this

I don't have that .gs file in my scripts. And I don't see that function in the code. What am I missing?

@emmtte
Copy link
Owner

emmtte commented Mar 22, 2019

sorry, I mixed up some project
just replace the function coinmarketcap() in main.gs by this
Don't forget to replace the api key in the function

function coinmarketcap() {

var options = {"muteHttpExceptions": true,
               "headers" : {'X-CMC_PRO_API_KEY': '<<<<your api key here>>>>'}
               }

var url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest";
var param = "?&limit=500&convert=EUR"

try {
    var response = UrlFetchApp.fetch(url + param, options);
} catch(e) {
  Logger.log("message:" + e.message + "\nfileName:" + e.fileName + "\nlineNumber:" + e.lineNumber + "\nstack:" + e.stack);
  return false;
}

//original
//{price_usd=3868.11723075, symbol=BTC, last_updated=1546194083, 24h_volume_eur=4305415992.52, total_supply=17453237.0, 24h_volume_usd=4924724753.95, market_cap_eur=59021299995.0, price_btc=1.0, available_supply=17453237.0, market_cap_usd=67511166772.0, percent_change_1h=0.06, percent_change_24h=-0.58, name=Bitcoin, max_supply=21000000.0, rank=1, id=bitcoin, percent_change_7d=-3.66, price_eur=3381.6821484}

//{data=[{symbol=BTC, circulating_supply=17453225, last_updated=2018-12-30T18:08:22.000Z, total_supply=17453225, cmc_rank=1, platform=null, tags=[mineable], date_added=2013-04-28T00:00:00.000Z, quote={EUR={percent_change_1h=0.2303, last_updated=2018-12-30T18:09:00.000Z, percent_change_24h=-0.4681, market_cap=5.9089233308678444E10, price=3385.5767807198067, volume_24h=4.304593294505483E9, percent_change_7d=-3.7054}}, num_market_pairs=6722, name=Bitcoin, max_supply=21000000, id=1, slug=bitcoin}, {symbol=XRP, circulating_supply=4.0794121066E10, last_updated=2018-12-30T18:09:02.000Z, total_supply=9.9991738974E10, cmc_rank=2, platform=null, tags=[], date_added=2013-08-04T00:00:00.000Z, quote={EUR={percent_change_1h=0.0143, 
var text = response.getContentText();
var data = JSON.parse(text);

Logger.log(data)

var array = [];
for(var x in data.data){ 
array.push({'symbol': data.data[x].symbol,
            'rank':   data.data[x].cmc_rank,
            'name':   data.data[x].name,
'percent_change_1h':  data.data[x].quote.EUR.percent_change_1h,
'percent_change_24h': data.data[x].quote.EUR.percent_change_24h,
'percent_change_7d':  data.data[x].quote.EUR.percent_change_7d,
'price_eur':          data.data[x].quote.EUR.price})
}
Logger.log(array)
return array;
}

@rshambaugh
Copy link
Author

That's a step in the right direction, but lots of #NUM! errors in the Market sheet now.
Screen Shot 2019-03-22 at 2 11 02 PM

@emmtte
Copy link
Owner

emmtte commented Mar 22, 2019

On my side it works like you on this point.
The missing information are not useful.
I need to work on it but as I said I have no time for the moment to clean the code.

@nikosid
Copy link

nikosid commented Apr 5, 2021

The same issue here. Getting all the coins but with this #NUM! value

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants