bmoscon / cryptofeed

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

Bitmex - Trade Subscription giving an error on expiry #1011

Open pavs94 opened 5 months ago

pavs94 commented 5 months ago

Describe the bug Bitmex Trade subscription is crashing with a weird error in the library

To Reproduce Steps to reproduce the behavior:

f = FeedHandler()
f.add_feed(Bitmex(symbols=['BTC-USD-PERP'], channels=[TRADES], callbacks={TRADES: bitmex_trade}))

Expected behavior

Screenshots

File "/home/ubuntu/xxxxxx/venv/lib/python3.11/site-packages/cryptofeed/exchanges/bitmex.py", line 61, in _parse_symbol_data
3|Websocket Price trigger  |     s = Symbol(base, quote, type=stype, expiry_date=entry['expiry'])
3|Websocket Price trigger  |                                                     ~~~~~^^^^^^^^^^
KeyError: 'expiry'

Operating System:

Cryptofeed Version

caolanraff commented 4 months ago

I tried creating a PR for this fix but unfortunately I don't have the correct permissions. This is the required change in bitmex.py:

            if entry['typ'] == 'FFWCSX':
                stype = PERPETUAL
                expiry = None
            elif entry['typ'] == 'FFCCSX':
                stype = FUTURES
                expiry = entry['expiry']
            elif entry['typ'] == 'IFXXXP':
                stype = SPOT
                expiry = None
            else:
                LOG.info('Unsupported type %s for instrument %s', entry['typ'], entry['symbol'])

            s = Symbol(base, quote, type=stype, expiry_date=expiry)

As BitMEX no longer sends values in the instrument feed if they are null.