I want to have local copy of mtgox market depth snapshot. So I request full market depth data (
https://data.mtgox.com/api/2/BTCEUR/money/depth/full) and connect to websocket (ws://websocket.mtgox.com/mtgox?Currency=USD). But it's not obvious how to apply realtime update to snapshot correctly.
It seems that full mtgox snapshot is updated each 3 minutes on mtgox server, so I buffer depth updates for about 5 minutes, fetch full depth snapshot and try to apply buffered updates. Updates with time stamps lesser than snapshot's time stamp are ignored.
Realtime update has price and total volume, so I find this price in my local snapshot and set new volume for item. If updated volume is zero I remove item from book. But sometimes I receive updates for prices that do not present in my local snapshot. So I guess something wrong with my algorithm.
The question is what are rules for merging market depth updates into depth snapshot?