Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccxtpro bug: the watched ohlcvs cache in OKX exchange not updated #22228

Closed
eurekawild opened this issue Apr 20, 2024 · 8 comments
Closed

ccxtpro bug: the watched ohlcvs cache in OKX exchange not updated #22228

eurekawild opened this issue Apr 20, 2024 · 8 comments
Assignees

Comments

@eurekawild
Copy link

Operating System

centos8

Programming Languages

Python

CCXT Version

4.2.100

Description

The cache of ohlcvs in OKX exchange are not updated after function watch_ohlcv() langched for a while(about 1 hour in my program), however the same code for Binance is well. I tried running it for several times and got the same fault in OKX and the right result in Binance.

Code

   await ex.watch_ohlcv(symbol, timeframe)
   while True:
       ohlcvs = ex.ohlcvs[symbol][timeframe]  # the candles info is not updated after the program running a while
         print(ohlcvs)

@carlosmiei
Copy link
Collaborator

Hello @eurekawild,

What's the best way of reproducing the issue? Do we have to wait an hour?

@carlosmiei carlosmiei self-assigned this Apr 20, 2024
@eurekawild
Copy link
Author

Hello @eurekawild,

What's the best way of reproducing the issue? Do we have to wait an hour?

I dont have a best way. In my program, the same code for Binance is well. Maybe something is wrong in OKX, like the frequency limit etc. Now I restart my program per one hour, It's OK for me.

@eurekawild
Copy link
Author

eurekawild commented Apr 21, 2024

async def symbol_loop(ex, symbol, timeframe):
    try:
        await ex.watch_ohlcv(symbol, timeframe)
    except Exception as e:
        traceback.print_exc()
        return
    cur_ohlcvs = await ex.fetch_ohlcv(symbol, timeframe, None,100)
    while True:
        latest_ohlcvs = ex.ohlcvs[symbol][timeframe]
        for ohlcv in latest_ohlcvs:
            last_ohlcv = cur_ohlcvs[-1]
            if ohlcv[0] > last_ohlcv[0]:
                cur_ohlcvs.append(ohlcv)
                cur_ohlcvs.pop(0)
            elif ohlcv[0] == last_ohlcv[0]:
                cur_ohlcvs[-1] = ohlcv
        print("cur ohlcvs:", cur_ohlcvs)
        await ex.sleep(5000)

This is the core code in my production environment. I just call the func watch_ohlcv() once, the func fetch_ohlcv() once. in the loop I just visit the ohlcv cache in ex. So I think it is not my code problem, and also not the question of the frequency limit. The code is simple and clear, but the ohlcvs stoped updating after the code runing an hour or two. So something is wrong in the func watch_ohlcv() in OKX exchange in my opinion.

@makarid
Copy link

makarid commented Apr 30, 2024

I can confirm the same. I am trying OKX watchOrderbook and it doesn't work but the same code for Bybit works. Version 4.3.11

Example code:
const exchange = new pro.okx({
"enableRateLimit": true,
"apiKey": okexApiKey,
"secret": okexSecret,
"password": okexPass,
});

watchOrderBooks(exchange, ["BTC-USDT-SWAP","ETH-USDT-SWAP"])

async function watchOrderBooks(exchange, perpSymbols) {
while (true) {
try {
for (const symbol of perpSymbols) {
console.log("Symbol: "+ symbol)
const orderbook = await exchange.watchOrderBook(symbol, 50)
}
} catch (e) {
logger.error (e.message)
}
}
}

If you run this code, the ETH-USDT-SWAP never console.logs.

@makarid
Copy link

makarid commented Apr 30, 2024

Also, when i am trying the same code without apikey i am getting okx requires "apiKey" credential. Does the OKX needs API keys for public orderbooks? By the way, it works on 4.1.11 version

@pcriadoperez
Copy link
Contributor

Hi @makarid , for the apiKey error you can set the params.depth to 'books' and that should fix it. I also opened a PR to default to it

pcriadoperez added a commit to pcriadoperez/ccxt that referenced this issue May 6, 2024
@pcriadoperez
Copy link
Contributor

Hi @makarid , I believe I found the problem, I think your api keys don't have VIP4 permission to use the depth channel books50-l2-tbt and the library wasn't throwing the error correctly so it appeared to be "stuck"

I opened one PR to default to the public channel and another to properly throw the error in this event. In the meantime the code should work if you use the depth channel books

@makarid
Copy link

makarid commented May 6, 2024

Thank you very much @pcriadoperez !

DelAnt pushed a commit to DelAnt/ccxt that referenced this issue May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants