kucoin-python-sdk icon indicating copy to clipboard operation
kucoin-python-sdk copied to clipboard

get_ticker timestamps incorrect?

Open john-robert opened this issue 3 years ago • 1 comments

Every 5 seconds I retrieve the ticker of HNT-USDT. It seems the times returned from the request are off and also jump back and forth. Here is the code:

import time
import datetime
from kucoin.client import Client

kucoin_client = Client('', '', '')

i = 0
while True:

    start = time.time()      # now in seconds

    kucoin_ticker = kucoin_client.get_ticker('IOTA-USDT')
    kucoin_time = float(kucoin_ticker['time'])

    time_system = datetime.datetime.fromtimestamp( start )
    time_ticker = datetime.datetime.fromtimestamp( kucoin_ticker['time'] / 1000 )

    print(f'time of now: {time_system}')
    print(f'time ticker: {time_ticker}')
    print()

    # break condition
    wait = 5 - (time.time() - start)  # wait 5 seconds minus execution time of iteration
    time.sleep(wait)
    i += 1
    if i >= 20:
        break

The code results in an output like so:

time of now: 2022-01-07 09:50:20 time ticker : 2022-01-07 09:50:12

time of now: 2022-01-07 09:50:25 time ticker : 2022-01-07 09:50:12

time of now: 2022-01-07 09:50:30 time ticker : 2022-01-07 09:50:12

time of now: 2022-01-07 09:50:35 time ticker : 2022-01-07 09:50:32

time of now: 2022-01-07 09:50:40 time ticker : 2022-01-07 09:50:40

time of now: 2022-01-07 09:50:45 time ticker : 2022-01-07 09:50:35

As can be seen, the "time of now" behaves as expected (increasxing by 5 seconds each), however, the ticker times jump back and forth for which I have no explanation. For assets with high volatility (e.g. BTC, ETH) this problem does not occur. I therefore suspect it's related to the last price made, still that wouldn't explain why the ticker times can jump also backwards in time when it shouldn't (see last two ticker times). Any idea / explanation why this is observed? Thanks!

john-robert avatar Jan 07 '22 08:01 john-robert

In this case, you can get the latest data by taking the largest timestamp. ALL data is correct, but since the server has multiple nodes, each node has its own cache time, so the data is correct, but the node time is different

codewc avatar Jan 09 '22 12:01 codewc

Since this issue has already been addressed and there have been no updates for a long time, we will now close it. If you need any further assistance, feel free to ask!

ISAAC-XXYYZZ avatar Jul 29 '24 12:07 ISAAC-XXYYZZ