Hi all,
I am building a Java based trading bot that requires market price data every 5 seconds. I was using the Rest API to do this by pausing a thread for 5 seconds then making a call to BinanceApiRestClient.getAllPrices() and inserting the price data into a data structure for processing.
All was working well, however I got the following exception from Binance:
com.binance.api.client.exception.BinanceApiException:
Too much request weight used; current limit is 1200 request weight per 1 MINUTE.
Please use the websocket for live updates to avoid polling the API.
So, I have 2 options;
Option 1:
I can bypass the Binance ApiRestClient and simply use a HTTP request of the following URL: https://api.binance.com/api/v3/ticker/price
This will give me the data I need. However, I will not know if I am going over my weight limit until my IP address is banned. Remember that I need to poll this URL every 5 seconds, 24/7.
Option 2:
I can use a WebSocket and subscribe to the AllMarketMiniTickersEvent stream with the following Java code:
BinanceApiWebSocketClient CLIENT_WS = BinanceApiClientFactory.newInstance().newWebSocketClient();
Closeable BINANCE_WS = CLIENT_WS.onAllMarketMiniTickersEvent( (List<MiniTickerEvent> response) ->
{
for( MiniTickerEvent ticker : response ) {
System.out.print( ticker.getSymbol() + ":" + ticker.getClosePrice() + ", " );
}
}
);
However, using the WebSocket stream will end up using far more data (about 7 or 8 time more) than I need - I just need symbol and price. (I had to modify the BinanceApiWebSocketClient Class and build the MiniTickerStream Class myself as the were missing in the Binance API download)
So my question is, will I be OK if I poll https://api.binance.com/api/v3/ticker/price every 5 seconds or do I need to use the WebSocket?
I would much rather use the the HTTP request to the URL, but I don’t want my IP to be banned. Remember, this system will be running 24/7