Market Data Download

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:

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:

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 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

First - in your variant Poolers you can read header of response X-MBX-USED-WEIGHT and calculate your limit by IP (wrong way)
Second - you can create listener… i think better is CandleStick, and you will have latest prices every time.

Don’t forget close Closeable

Hi @Chris_Rae, my take on this is that websocket is always recommended as it doesn’t have IP restriction and is much faster. However, if you want to keep using the REST request, note the following:

  • The GET /api/v3/ticker/price IP weight is 1 (single symbol) and 2 (all symbols).
  • With GET /api/v3/exchangeInfo, you’ll obtain IP rate limits:
            "rateLimitType": "REQUEST_WEIGHT",
            "interval": "MINUTE",
            "intervalNum": 1,
            "limit": 1200
            "rateLimitType": "RAW_REQUESTS",
            "interval": "MINUTE",
            "intervalNum": 5,
            "limit": 6100

You can estimate your total requests weight and number of requests and see if it passes the limitations above and keep track or to debug your IP usage, using X-MBX-USED-WEIGHT.

Side note: If you’re using binance-java-api, this is not officially maintained, we’re preparing our own connector to support Java.