Cerca
WebSocket API v1 - Example order book transcript
An example transcript of the WebSocket API v1 order book feed, with an explanation of each message and the resulting change to the order book, is as follows:
 
1. Initial Snapshot
The initial snapshot message:
[0,{"as":[["5711.80000","8.13439401","1557070784.848047"],["5712.20000","2.00000000","1557070757.056750"],["5712.80000","0.30000000","1557070783.806432"],["5713.00000","3.29800000","1557070774.281619"],["5713.10000","1.00000000","1557070741.315583"],["5713.90000","1.00000000","1557070698.840502"],["5714.70000","0.50000000","1557070743.861074"],["5715.20000","1.00000000","1557070697.871150"],["5716.60000","1.22700000","1557070775.294557"],["5716.80000","0.35000000","1557070749.823148"]],"bs":[["5711.70000","0.00749800","1557070712.848376"],["5709.20000","3.30000000","1557070766.260894"],["5708.30000","0.75483907","1557070781.425374"],["5708.20000","5.00000000","1557070780.762871"],["5707.80000","2.50000000","1557070722.912548"],["5707.40000","4.33000000","1557070732.546143"],["5707.00000","0.00200000","1557070604.962840"],["5706.90000","1.17300000","1557070715.529722"],["5706.40000","0.85600000","1557070777.204262"],["5706.30000","1.00000000","1557070753.118938"]]},"book-10","XBT/USD"]
provides the following initial order book:
Screenshot_2021-06-08_at_07.52.08.png
 
2. Update/delete/insert message
The first update message modifies the bid side of the order book, by updating the existing price level 5709.2, deleting the existing price level 5708.2 and inserting (pulling into scope) the new price level 5705.9:
[0,{"b":[["5709.20000","3.00000000","1557070785.898642"],["5708.20000","0.00000000","1557070786.010118"],["5705.90000","7.62400000","1557070783.582385","r"]], "c":"2470128591"},"book-10","XBT/USD"]
which gives the following updated order book:
Screenshot_2021-06-08_at_07.54.06.png
3. Update/insert message
The next update message modifies the bid side of the order book, by updating the existing price level 5709.2, and inserting the new price level 5709.4 (which has the side effect of moving all of the subsequent price levels outwards by one level and pushing price level 5705.9 back out of scope):
[0,{"b":[["5709.20000","8.00000000","1557070786.250425"],["5709.40000","0.30000000","1557070786.259115"]], "c":"4148072505"},"book-10","XBT/USD"]
which causes the following updated order book:
Screenshot_2021-06-08_at_07.55.20.png
4. Delete/insert message
The next update message changes the bid side of the order book, by deleting price level 5708.3 and inserting (pulling back into scope) price level 5705.9:
[0,{"b":[["5708.30000","0.00000000","1557070786.389495"],["5705.90000","7.62400000","1557070783.582385","r"]], "c":"3093569863"},"book-10","XBT/USD"]
which gives the following updated order book:
Screenshot_2021-06-08_at_07.56.51.png
and so on ad infinitum until the order book feed is unsubscribed or the WebSocket connection is terminated.
Example code (in Python) that implements a command line order book client and illustrates the logic of maintaining a valid order book is available for review and for download:
 
The decimal and thousands separators shown in this article may differ from the formats displayed on our trading platforms. Review our article on how we use points and commas for more information.