BitMEX / sample-market-maker

Sample BitMEX Market Making Bot
Apache License 2.0
1.7k stars 757 forks source link

KeyError: 'clOrdID' #239

Closed derlykk closed 1 year ago

derlykk commented 1 year ago
Traceback (most recent call last):
  File "custom_bitmex_strategy.py", line 508, in <module>
    run()
  File "custom_bitmex_strategy.py", line 500, in run
    order_manager = CustomOrderManager()
  File "/home/admin/my_bitmex/market_maker.py", line 217, in __init__
    self.reset()
  File "/home/admin/my_bitmex/market_maker.py", line 221, in reset
    self.sanity_check()
  File "/home/admin/my_bitmex/market_maker.py", line 452, in sanity_check
    ticker = self.get_ticker()
  File "/home/admin/my_bitmex/market_maker.py", line 260, in get_ticker
    if ticker['buy'] == self.exchange.get_highest_buy()['price']:
  File "/home/admin/my_bitmex/market_maker.py", line 143, in get_highest_buy
    buys = [o for o in self.get_orders() if o['side'] == 'Buy']
  File "/home/admin/my_bitmex/market_maker.py", line 140, in get_orders
    return self.bitmex.open_orders()
  File "/home/admin/my_bitmex/bitmex.py", line 134, in wrapped
    return fn(self, *args, **kwargs)
  File "/home/admin/my_bitmex/bitmex.py", line 226, in open_orders
    return self.ws.open_orders(self.orderIDPrefix)
  File "/home/admin/my_bitmex/ws/ws_thread.py", line 118, in open_orders
    return [o for o in orders if str(o['clOrdID']).startswith(clOrdIDPrefix) and o['leavesQty'] > 0]
  File "/home/admin/my_bitmex/ws/ws_thread.py", line 118, in <listcomp>
    return [o for o in orders if str(o['clOrdID']).startswith(clOrdIDPrefix) and o['leavesQty'] > 0]
KeyError: 'clOrdID'

fixed it with replaceing line 117 in: https://github.com/BitMEX/sample-market-maker/blob/be124ebc90d7aa692bdf2f53e066bf5e7e25723f/market_maker/ws/ws_thread.py from return [o for o in orders if str(o['clOrdID']).startswith(clOrdIDPrefix) and o['leavesQty'] > 0] to return [o for o in orders if 'clOrdID' in o and str(o['clOrdID']).startswith(clOrdIDPrefix) and o['leavesQty'] > 0]

byshing commented 1 year ago

Hi @derlykk thanks for reporting. This fix has been applied 0bb5ddb. And included in release version 1.6.1.

https://pypi.org/project/bitmex-market-maker/1.6.1/