kucoin-api-docs icon indicating copy to clipboard operation
kucoin-api-docs copied to clipboard

Correct procedure for Level-2 market data calibration

Open MartyIX opened this issue 4 years ago • 2 comments

Hi,

https://docs.kucoin.com/#level-2-market-data contains:

Calibration procedure:

  1. After receiving the websocket Level 2 data flow, cache the data.
  2. Initiate a REST request to get the snapshot data of Level 2 order book.
  3. Playback the cached Level 2 data flow.
  4. Apply the new Level 2 data flow to the local snapshot to ensure that the sequence of the new Level 2 update lines up with the sequence of the previous Level 2 data. Discard all the message prior to that sequence, and then playback the change to snapshot.
  5. Update the level2 full data based on sequence according to the price and size. If the price is 0, ignore the messages and update the sequence. If the size=0, update the sequence and remove the price of which the size is 0 out of level 2. For other cases, please update the price.

I'm not sure how to correctly proceed in step 3 and 5 as the example JSON update message in the docs does not help me:

{
    "type":"message",
    "topic":"/market/level2:BTC-USDT",
    "subject":"trade.l2update",
    "data":{

        "sequenceStart":1545896669105,
        "sequenceEnd":1545896669106,
        "symbol":"BTC-USDT",
        "changes":{

            "asks":[["6","1","1545896669105"]],           //price, size, sequence
            "bids":[["4","1","1545896669106"]]
        }
    }
}

My questions are:

  1. Are changes.asks (in the JSON above) and changes.bids sorted by price or by sequence numbers or not sorted at all?
  2. Can I apply updates in changes for asks first and then for bids? Or do I need to merge changes.asks and changes.bids, sort by sequence numbers and apply update change after another?
  3. Is there any sample how to correctly implement the calibration procedure mentioned in https://docs.kucoin.com/#level-2-market-data?

Thank you!

MartyIX avatar Jun 11 '21 12:06 MartyIX

Hi

  1. They are stored with sequence number
  2. you can apply update one after another
  3. we are making one. I will post it on Leraning Center channel

progressivehed avatar Jun 08 '22 13:06 progressivehed

where you able to solve this problem?

yahdielo avatar Feb 06 '23 20:02 yahdielo