twelvedata / twelvedata-python

Twelve Data Python Client - Financial data API & WebSocket
https://twelvedata.com
MIT License
392 stars 57 forks source link

[Bug] Websocket data has future timestamp? #79

Closed jbonilla-tao closed 4 months ago

jbonilla-tao commented 5 months ago

Seems to be a new issue. The timestamp of websocket messages is occassionally greater than the current time.

Please see error logs of my application:

468|ptn       | 2024-05-29 14:38:01.657 |      ERROR       | Received TD websocket data in the future SPX. lag_ms -16343 Ignoring this data.
468|ptn       | 2024-05-29 14:38:07.589 |      ERROR       | Received TD websocket data in the future SPX. lag_ms -13411 Ignoring this data.
468|ptn       | 2024-05-29 14:38:08.403 |      ERROR       | Received TD websocket data in the future FTSE. lag_ms -12597 Ignoring this data.
468|ptn       | 2024-05-29 14:38:14.150 |      ERROR       | Received TD websocket data in the future FTSE. lag_ms -7850 Ignoring this data.
468|ptn       | 2024-05-29 14:38:24.903 |      ERROR       | Received TD websocket data in the future GDAXI. lag_ms -97 Ignoring this data.

relevant code

            price = float(event['price'])
            timestamp_ms = int(event['timestamp']) * 1000
            lag_time_ms = TimeUtil.now_in_millis() - timestamp_ms
            if lag_time_ms < 0:
                bt.logging.error(f"Received TD websocket data in the future {symbol}. lag_ms {lag_time_ms} Ignoring this data.")
                return
midasSSS commented 4 months ago

This issue should be resolved as of now.