bmoscon / cryptofeed

Cryptocurrency Exchange Websocket Data Feed Handler
Other
2.14k stars 668 forks source link

Fix instrument types in symbol parsing on Bitmex. #981

Closed agijsberts closed 1 year ago

agijsberts commented 1 year ago

Description of code - what bug does this fix / what feature does this add?

This fix resolves two related bugs in the symbol handling for Bitmex. Firstly, it properly decodes instrument types, including disambiguating SPOT and PERPETUAL symbols. Since both have the same counter and base currency, formerly the spot instrument would overwrite the perpetual instrument simply because it came later in the active instruments rest endpoint. For example, during parsing the normalized symbol BTC-USDT-PERP would first (correctly) refer to Bitmex instrument XBTUSDT and later be overwritten to refer to Bitmex's spot market XBT_USDT (yes, the naming is indeed confusing).

This fix resolves a second bug, in that Bitmex has two ETH-USD-PERP instruments, namely ETHUSD and ETHUSD_ETH. Also in this case the latter, much less active instrument would overwrite the former. In case of ambiguity, this fix therefore gives precedence to the first match.

I think this PR will resolve https://github.com/bmoscon/cryptofeed/issues/905. Note that the instrument types were taking from the official documentation. An obvious consequence of this fix is that cryptofeed will support Bitmex's spot markets.