dydxprotocol / dydx-v3-python

Python client for dYdX (API v3)
Apache License 2.0
306 stars 176 forks source link

WebSocket : OrderBook : Data sent is pre-maching-engine data, yielding "invalid" order books #221

Open kgoderis opened 9 months ago

kgoderis commented 9 months ago

Just seeking a confirmation, but it seems that the updates sent over the web socket are updates of the order book before they got matched by the exchange matching engine. I observe for example message sequences such as this one:

{
  "type" : "channel_data",
  "connection_id" : "17acef48-0628-4d2a-9115-5e8574a03418",
  "message_id" : 550589,
  "id" : "ETH-USD",
  "channel" : "v3_orderbook",
  "contents" : {
    "offset" : "36003283357",
    "bids" : [ ],
    "asks" : [ [ "2244.1", "21.982" ] ]
  }
} 
{
  "type" : "channel_data",
  "connection_id" : "17acef48-0628-4d2a-9115-5e8574a03418",
  "message_id" : 550600,
  "id" : "ETH-USD",
  "channel" : "v3_orderbook",
  "contents" : {
    "offset" : "36003283744",
    "bids" : [ [ "2244.1", "8.154" ] ],
    "asks" : [ ]
  }
} 

When performing the updates to an order book structure stored by the client, you would end up with an order book whereby the nearest bid and ask are at the same level, and thus equal to the mid price, e.g. spread would be 0. IMO this should never be the case

Later on I get:

{
  "type" : "channel_data",
  "connection_id" : "17acef48-0628-4d2a-9115-5e8574a03418",
  "message_id" : 550625,
  "id" : "ETH-USD",
  "channel" : "v3_orderbook",
  "contents" : {
    "offset" : "36003283370",
    "bids" : [ ],
    "asks" : [ [ "2244.1", "20" ] ]
  }
} 
{
  "type" : "channel_data",
  "connection_id" : "17acef48-0628-4d2a-9115-5e8574a03418",
  "message_id" : 550634,
  "id" : "ETH-USD",
  "channel" : "v3_orderbook",
  "contents" : {
    "offset" : "36003283425",
    "bids" : [ ],
    "asks" : [ [ "2244.1", "0" ] ]
  }
} 

Expected behaviour would that updates are sent after matching by the matching-engine, so that the bids @ 2244.1 level is to 0, and the ask is set at the open amount after matching

Is this by design?