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.

okx rate-limit incorrect

See original GitHub issue
  • OS: linux
  • Programming Language version: python
  • CCXT version: 1.87.54

When using asyncio to retrieve a lot of leverage tiers - it becomes apparent that the rate-limit for that endpoint is incorrect. In my understanding, ccxt’s throttler should kick in based on configured rate-limits - and not make the requests to the exchange too often.

based on the below - i’d expect no output other than the “128” for the length of pairs.

import ccxt.async_support as ccxt_async
exchange = ccxt_async.okx({'options': {'defaultType': 'swap'}, 'enableRateLimit': True})

import asyncio
async def fetch_levt(p):
    try:
        return await exchange.fetch_market_leverage_tiers(p)
    except Exception as e:
        print(p)
        print(e)
        return None

async def test():
    lt = []
    m = await exchange.load_markets()
    for p in m.keys():
        if p.endswith(':USDT'):
            lt.append(fetch_levt(p))
    print(len(lt))
    await asyncio.gather(*lt, return_exceptions=True)

asyncio.run(test())
128
1INCH/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}
BSV/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}
ENJ/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}
ICP/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}
NFT/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}
SAND/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}
THETA/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}
XLM/USDT:USDT
okx {"msg":"Requests too frequent.","code":"50011"}

there are however quite some okx {"msg":"Requests too frequent.","code":"50011"} messages mixed in - causing a delay in operations.

Now obviously we can handle this and retry (freqtrade does so) - but it’s still slowing us down more than it should. It doesn’t seem “too far” off - but just slightly - enough to cause an exception on 8 out of 128 requests - so roughly one every 16 requests.

Based on the docs - the rate-limit for this endpoint should be Rate Limit: 10 requests per 2 seconds … it’s currently set to “2” - but it’s unclear to me what unit “2” is in. (https://github.com/ccxt/ccxt/blob/bbda875a9de4209535afe6987a14534204dcae42/js/okx.js#L170)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
xmatthiascommented, Jun 21, 2022

@frosty00 thanks, you’re right, i can no longer reproduce this - like - not at all from different locations. not with the version i highlighted the issue in the first place - so it’s not a ccxt change that caused this.

I suspect something on okx’s side changed (maybe they’re now less strict - or they fixed a bug on their side) - either way, i’ve now tried for 2 days from different locations / systems without ever running into this problem again, so i think this can be closed - as there’s nothing actionable.

1reaction
frosty00commented, Jun 20, 2022

What your experiencing is likely a known issue with ccxt asyncio in python, and it is being worked on to be fixed asap, due to the leaky bucket algorithm, which is implemented in the throttler, sometimes it sends an extra request or two, and some exchanges are extremely strict of this, and others are not.

Actually there is no issue here, it’s working as intended. It has the capacity for an extra request which allows markets to load faster

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overview – OKX API guide | OKX technical support
Our REST and WebSocket APIs use rate limits to protect our APIs against malicious usage so our trading platform can operate reliably and...
Read more >
Price Limit Rules in Spot Trading – Help center - OKX
The following price limit rules are added. 1. FOK(Fill-or-kill) price limit: If the user's market order/limit order placed in spot trading can ...
Read more >
2021-12-23 – OKX API guide | OKX technical support
Rate limit rule (Options only): UserID + Instrument Family. Changes below are to support Stop-loss or Take-profit close position orders feature.
Read more >
Non-Disclosed Broker – OKX API guide
Create a sub-account from the broker master account. Rate Limit: 40 requests per second. HTTP Request. POST /api/v5/broker/nd/create-subaccount.
Read more >
OKX Help Center | Customer service and helpdesk
Buy/Sell at your own rate ... Crypto P&L Analysis(My portfolio) FAQWhat should I do if I receive the "Incorrect Date of Birth" error...
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