4
2
I'm trying to write a program using the Mt.Gox API to keep an up-to-date consistent view of their market depth. My current approach is as follows:
- Connect WebSocket and subscribe to depth updates
- Wait for 1 minute, collecting updates
- Request full market depth data via http://data.mtgox.com/api/1/BTCUSD/depth/full
- Merge the collected updates into the market data by time-stamp (more recent wins)
- Continue merging all future updates into data
After playing around with this for a while, I noticed that the full depth data download doesn't always match the data generated from updates. That's why I added the 1min delay, thinking that maybe the Mt.Gox server only updates the full depth data periodically, but doesn't generate it on the fly.
But even with this protocol, if I run the program twice in parallel, I end up seeing different data in both instances.
Any idea what I might be doing wrong?
Hi! I also tried to manage my own order book and have noticed that after having it run for a while, it accumulates entries that should have long been removed. But, I have so far only used the "depth" events' "total volume" field. Does the information included in the "trade" events actually not show up as "depth" events? Also, have you found the incremental volume information (positive vs. negative) to be more accurate than using the "total volume" field? Thanks! – Markus A. – 2013-06-11T18:27:53.420
so I resized that all trade events will have a corresponding depth event with negative volume. So just using depth events you can construct an order book by adding all depth objects with positive volume and removing objects with negative volume. To make sure they are the same I match the
price_intandamount_intfields before removing the object. I dont usetotal volumeat all, and have found this to work quite well. – Loourr – 2013-06-11T19:14:49.997Hmmm... I also used price_int to match the entries... let me try using amount_int instead of total volume to see if that's more reliable... Have you ever noticed any depth events arriving "out of order", i.e. you receive an event with a "now" timestamp that is earlier than the timestamp of a previously received event? – Markus A. – 2013-06-11T19:56:02.390
No, but I'll be keeping an eye out for it in the future. Also be sure you take the absolute value of the negative volumes before you compare them with existing orders. – Loourr – 2013-06-11T20:16:20.063