question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Polling Binance fetchTickers every 5 seconds triggers a ban

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
kroitorcommented, Jan 2, 2018

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.

4reactions
kroitorcommented, Jan 3, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Frequently Asked Questions - Binance
However, if you are sending a request that could be perceived as malicious, it could also result in a ban of a longer...
Read more >
Exchanges — ccxt 2.4.71 documentation
Most exchanges allow up to 1 or 2 requests per second. Exchanges may temporarily restrict your access to their API or ban you...
Read more >
Change Log – Binance API Documentation - GitHub Pages
Please use WebSocket Streams for live updates to avoid polling the API. ... WebSocket connections have a limit of 5 incoming messages per...
Read more >
python/ccxt/binance.py - searchcode
Please use the websocket for live updates to avoid polling the API. ... 523 '-3022': AccountSuspended, # You account's trading is banned.
Read more >
CCXT | PDF | Java Script | Software - Scribd
Most exchanges allow up to 1 or 2 requests per second. Exchanges may temporarily restrict your access to their API or ban you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found