Author

Topic: MtGox and Bitstamp timestamps for each trade and depth item - how do they work? (Read 1772 times)

newbie
Activity: 47
Merit: 0
(I hope this question belongs here, if not - advise me which subforum it should go)

I'm building a trading app and one issue I faced is timestamps for trades on the exchanges. I'm not sure I understand how they work.
Here's the way I tried to use them in the app which seems to produce odd results:

1. I connect to the streaming API for both trades and depth and start receiving data. At this point the orderbook in my app is empty, so I don't update anything, I just put the updates from the stream into a queue.
2. Load the full depth orderbook, remember the timestamp.
3. Release the queue of trades and orderbook changes, update the app orderbook. For each update, check if the timestamp is smaller (that is older) than the timestamp of the full depth orderbook I just downloaded. If it is, do not allow this item to update the orderbook, since it already has it.

In fact, the check in #3 keeps checking even later, when the queue is empty and only new data comes in from the stream. Problem is, it looks like both MtGox and Bitstamp keep sending "old" items into the stream many minutes after I downloaded the full depth order book. Even more odd is that when I do not allow those allegedly older updates from updating the orderbook of my app, it starts to look different from what I see on, say, Bitcoinwisdom. If I turn off this timestamps check, Bitstamp starts to look fine and orderbook is exactly the same as it is displayed on Bitcoinwisdom. Gox looks weird in both cases (with or without timestamp check) but I suspect this is due to some other issue.

Any ideas?
Jump to: