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:
- Created a year ago
- Reactions:1
- Comments:6 (6 by maintainers)
@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.
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