gateio / gatews

Gate Websocket V4 SDK
89 stars 35 forks source link

Position WS updates vs. positions from REST #44

Closed LKresta closed 1 year ago

LKresta commented 1 year ago

Hello there,

Is there any reliable way to determine whether position notification from futures.positions WS channel represents state newer than information returned from REST API (/futures/{settle}/positions)? From what I saw the timestamp (in ms) is not enough - there can be multiple WS notifications sent with the same time_ms.

Thanks, L.

revilwang commented 1 year ago

It's a problem. I'll check if some additional information can be provided to correlate position with order notification, and, how position notification can distinguish from each other if multiple notifications are with the same time_ms

LKresta commented 1 year ago

Thanks. Are there at least some guarantees at the moment, as mentioned in https://github.com/gateio/gatews/issues/43? Like relative order of notifications, and their timestamps?

revilwang commented 1 year ago

From what I know, there is no absolute guarantees if there are multiple order&position notifications in 1ms for now. But I'll go for a second check.

LKresta commented 1 year ago

I see. Thanks for clarification & please let me know if you find anything usable.

revilwang commented 1 year ago

Confirmed the timestamp cannot be guaranteed to be exactly the same for positions, orders and trades. However, the update timestamp for each follows the sequence: position, user_trades, then order, which means if a trade happens, position will be updated, then user_trades, and lastly the order.

LKresta commented 1 year ago

Great, thanks - that's something I can work with :)

Cheers, L.

LKresta commented 1 year ago

Thanks; I'm observing slightly altered sequence though (on TestNet) - following a trade the first notification to arrive is for futures.usertrades, then futures.positions, then futures.orders (and then futures.balances). So more like user trades, position, and lastly the order...?

revilwang commented 1 year ago

Um, the information might be misleading. I think it might not help you. The update time occurred in the engine follows the sequence but not the time websocket pushed to client. For the latter, there is no sequence guarantee. 😢

LKresta commented 1 year ago

Ah, I see. Thanks for clarification!