BitMEX / api-connectors

Libraries for connecting to the BitMEX API.

Home Page:https://www.bitmex.com/app/restAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python ws object: Is there a difference in the speeds at which quote and trade data are updated?

ian-collab opened this issue · comments

Is there a difference in the speeds at which quote and trade data are updated in the Python ws object? Can you see another cause for the behaviour below?

2020-07-09 02:31:48,082 - root - INFO - Better Ticker: {'last': 9404.0, 'buy': 9404.0, 'sell': 9404.5, 'mid': 9404.0}
2020-07-09 02:31:48,598 - root - INFO - Better Ticker: {'last': 9399.0, 'buy': 9404.0, 'sell': 9404.5, 'mid': 9404.0}
2020-07-09 02:31:49,598 - root - INFO - Refreshed Better Ticker: {'last': 9399.0, 'buy': 9399.0, 'sell': 9399.5, 'mid': 9399.0}

The above log entries are from a slightly changed ticker object very similar to the one included in the python ws project.
In their polling of trade and quote data to populate the object, they are identical. First they poll the quote data for bid/ask (buy/sell) and then the quote data for last price.

Note that last price in the 2nd log entry is under the bid/ask volume.

The code concerned has just gone long 1 contract sometime in the 0.5 second between first and second log entries above. Yet buy and sell are apparently unchanged. I personally eyeballed the market action on a 10ms refresh in Sierra and did not see the market bounce back up. Additionally, in every instance of this behaviour viewed, buy/sell values are identical to the previous log entry. It is as though there is a lag between the trade data and the quote data being updated. Or else my order is being filled below bid/ask values (weird).

My solution is to have the code pause for 1 second on entry and refresh the ticker. That is the third log entry. Otherwise some code which is triggered by a favourable delta between last and buy prices is triggered when such delta seems not truly to exist, only that putative time delay between quote and trade data.

Actually, I just checked the object in a console inspector. There is almost always a time difference between last_trade and last_quote. Anywhere from the 1 second range out to 7 seconds that I saw in a quick review.

Surely the quote must change in volume and/or value every time a trade is executed? I don't understand. It seems inaccurate that they don't change at the same time.

Why does this time difference exist?
Is there any way to eliminate the time difference.