Monday, 13 September 2021

Getting average volume for multiple coins within certain interval using sockets or REST

I am trying to get an average volume within certain interval of time using Binance API. For example, I want to have an average volume where time range would be defined like this (pseudo code):

startTime = now() - 24h - 20 min
endTime = now() - 20 min

And I have to do this for 200 trading pairs (eg all USDT related trading pairs).

I know I can make one API call per symbol (https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#klinecandlestick-data) to get this data using REST, like this:

  async function getKline(marketSymbol, timeInterval, limit) {
    var url = 'https://api.binance.com/api/v3/klines?symbol=' + marketSymbol
                   + '&interval=' + timeInterval
                   + '&startTime' + startTime
                   + '&endTime' + endTime
                   + '&limit=' + limit;
    
    const response = await fetch(url);
    const data = await response.json();
    
    return data;
  }

But cause I have to do this every minute, it would be 200 API calls per minute. And I am already using sockets to fetch candlestick data every two seconds for 200 pairs.

So I guess using REST api/v3/klines is not performant or a way to go here. I mean I know this request has a request weight that equals to 1, and I would be probably fine with restrictions and limits, but, is there some other way to go to get average volume within certain interval for multiple coins like in one single request, or in any way other than making that much API calls every minute?



from Getting average volume for multiple coins within certain interval using sockets or REST

No comments:

Post a Comment