ccxt: Polling Binance fetchTickers every 5 seconds triggers a ban

I tried use param {enableRateLimit: true} to handle rate limit. A strange thing about ‘binance’: when I call fetchTickers() to polling tickers (e.g., every 5 seconds), it will throw an error {"code":-1003,"msg":"Way too many requests; IP banned until 1514883415037."} This should not happened, 5 seconds should not trigger limit. Is there some extra info to explain this? I tried find information from ccxt and binance api docs, no idea.

Ref to: #929

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 15 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Hi!

Binance uses a Machine Learning rate-limiting algorithm that scores your requests against an average user and accounts for the weight of each call.

From Binance:

For users who are having issues with temporary trading bans: Our risk management system is a machine learning system; there are no “hard rules” we can give you to follow. Trading behavior is evaluted against the “average user” and if you deviate too far, you’ll get a trading ban ranging from 5 minutes to 3 days. To help you understand how the system works: imagine there’s an “abuse score”. Your abuse score goes up if:

  1. You front run the book.
  2. You spam orders/cancels very quickly without trading.
  3. Your “conversation rate” is low; “conversation rate” is ‘numTrades / (orders + cancels)’ over 24hours.
  4. Your “weight” is low; “weight” is ‘totalTradedQty / (orders + cancels)’ over 24hours.
  5. When trading on symbols that have BNB as the base or quote asset, the amount of abuse score you get for deviating from the norm on the above is amplified. This is not a complete/exhaustive list of the metrics evaluted, but this should help point you in the right direction.

From their tech team:

Ninj0r, [04.12.17 10:44]
You're rated against "average user"

Ninj0r, [04.12.17 10:44]
and how far you deviate.

Ninj0r, [04.12.17 10:44]
So there's no "You can X in Y amount of time"

Ninj0r, [04.12.17 10:44]
it's an ML algo

Igor Kroitor, [04.12.17 10:45]
yes, I understand what machine learning is, of course, but is there a practically-deduced 
limit that we can use to protect ourselves from getting banned (if that happens)?

Ninj0r, [04.12.17 12:48]
Past the guidelines I gave in the API, no. That's what we can offer at this time.

Next, if you go here: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#24hr-ticker-price-change-statistics

You will notice that they have a special weight for the “all tickers” endpoint:

binance-api-docs

They say, that if you’re fetching all tickers, the rate limit should be multiplied by the amount of active traded symbols. They have 234 active symbols, so, it looks like you should not be polling their tickers more than once in 234 seconds. It’s a unique endpoint in terms of rate limiting. Unfortunately, there isn’t an easy workaround for this, if you’re mixing your requests. If you are only doing one type of fetchTickers() request, then you can raise the rateLimit to 234 000 milliseconds (once in 234 seconds).

Let me know if this answers your question or not.

Hi, @eMDi101 ! Thanks for the notice! The thing is: we are talking of the allBookTickers endpoint. The library of sammchardy uses the allPrices endpoint – that one does not return full info, it will output price info only, without 24h ohlcv.

Now, in ccxt we support both endpoints, the allBookTickers + the allPrices, but for the tickers we use allBookTickers by default because it gives us 24h stats – that is more than just prices: https://github.com/ccxt/ccxt/blob/master/python/ccxt/binance.py#L98

Next, if you look carefully through each endpoint here:

… you will quickly notice two things:

  1. Both allPrices and allBookTickers are now renamed to new endpoints, therefore both ccxt and sammchardy are outdated, but we are working on the update in ccxt (will be there in several hours).
  2. The rate limiting for 24h stats is much more restrictive than for price-only tickers. This explains the difference that you were asking about.

We are also going to switch to price-only tickers by default for Binance in one of the upcoming releases. Will update you here.