semashkinvg / Bitmex.NET

Wrapper for BitMEX.com REST & WebSocket API
MIT License
52 stars 26 forks source link

Question about WS subscription #9

Closed GitteryCoder closed 6 years ago

GitteryCoder commented 6 years ago

Hi Semashkinvg,

In my code I did this:

bitmexApiSocketService.Subscribe(BitmexApiSubscriptionInfo<IEnumerable<OrderBookDto>>.Create(SubscriptionType.orderBookL2, a => { foreach(var d in a) Console.WriteLine(d.ToStr()); })); }

This gave me the output:

BITMX Entry: XBTUSD id:15599217800 side:Sell size:10000 price:7822
BITMX Entry: XBTUSD id:15599217900 side:Sell size:3130 price:7821
BITMX Entry: XBTUSD id:15599218000 side:Sell size:800 price:7820
BITMX Entry: XBTUSD id:15599218050 side:Sell size:50 price:7819.5
BITMX Entry: XBTUSD id:15599218250 side:Sell size:575 price:7817.5
BITMX Entry: XBTUSD id:15599218300 side:Sell size:30 price:7817
...
BITMX Entry: XBTUSD id:15599227400 side:Sell size:6792 price:0
BITMX Entry: XBTUSD id:15599231250 side:Sell size:9864 price:0
BITMX Entry: XBTUSD id:15599235100 side:Sell size:6867 price:0
BITMX Entry: XBTUSD id:15599238900 side:Sell size:6592 price:0

Questions:

  1. There is no indication of whether the action is "partial", "update", "delete" or "insert". Am I supposed to make the guess that if price is 0 then it is an "update", and if size is 0 then it is a "delete" etc?

  2. Also according to https://www.bitmex.com/app/wsAPI#subscriptions I should discard all data before "partial" but how can I know whether a message is "partial" or "insert"?

  3. If I subscribe to orderBook10, all I get are zero entries. Why?

    BITMX Entry: EOSU18 id:0 side: size:0 price:0
    BITMX Entry: ETHU18 id:0 side: size:0 price:0
    BITMX Entry: ETHUSD id:0 side: size:0 price:0
    BITMX Entry: LTCU18 id:0 side: size:0 price:0
    BITMX Entry: TRXU18 id:0 side: size:0 price:0
    BITMX Entry: XBTJPY id:0 side: size:0 price:0
    BITMX Entry: XRPU18 id:0 side: size:0 price:0
    BITMX Entry: XBTKRW id:0 side: size:0 price:0
    BITMX Entry: XBTZ18 id:0 side: size:0 price:0
    BITMX Entry: TRXU18 id:0 side: size:0 price:0
    BITMX Entry: TRXU18 id:0 side: size:0 price:0
semashkinvg commented 6 years ago

hi @GitteryCoder, I think the question you raised is quite important and it's definitely worth investigating it carefully. It's crucial not just to know if these are bugs or not, but also to add some description of the API to this repository. I know that handling order book changes is a key point in the most of the trading strategies, so I will come back to you soon. All the exchanges provide order book updates with a different way, so, I think it's important to describe what's the best way to handle order book using Bitmex API

Thanks,

semashkinvg commented 6 years ago

HI @GitteryCoder, See the answers below,

  1. To provide for the developers better way to handle all this action types, I wrapped the result DTO into BitmexSocketDataMessage . In addition, I added examples (check out the app) and a short description how to handle order book L2.

  2. "Discard Partial action" - not always, for instance, Partial action brings full depth snapshot of the order book within L2 subscription (2100 rows for XBTUSD). So, I would recommend to you here to make a decision case by case

  3. "If I subscribe to orderBook10, all I get are zero entries. Why?" - that happened because you used the wrong model, it should have been OrderBookSocketDto, but within the last commit, I renamed the class to make naming a bit more explicit and now it's OrderBook10Dto. To be even more specific and avoid bugs like yours, I added BitmetSocketSubscriptions. Please use it when you create a subscription request to be sure that you specify the appropriate model for the subscription.