Use `str(cmd.symbol)` for fqme on cancels, add `_nowait()` method names

pre_overruns_ctxcancelled
Tyler Goodlet 2023-03-22 10:40:48 -04:00
parent 71019ad54b
commit b1e241781e
1 changed files with 27 additions and 5 deletions

View File

@ -64,7 +64,7 @@ class OrderBook(Struct):
_from_order_book: trio.abc.ReceiveChannel _from_order_book: trio.abc.ReceiveChannel
_sent_orders: dict[str, Order] = {} _sent_orders: dict[str, Order] = {}
def send( def send_nowait(
self, self,
msg: Order | dict, msg: Order | dict,
@ -73,6 +73,15 @@ class OrderBook(Struct):
self._to_ems.send_nowait(msg) self._to_ems.send_nowait(msg)
return msg return msg
# TODO: make this an async version..
def send(
self,
msg: Order | dict,
) -> dict:
log.warning('USE `.send_nowait()` instead!')
return self.send_nowait(msg)
def send_update( def send_update(
self, self,
@ -86,10 +95,14 @@ class OrderBook(Struct):
self._to_ems.send_nowait(msg) self._to_ems.send_nowait(msg)
return cmd return cmd
def cancel(self, uuid: str) -> bool: def cancel_nowait(
"""Cancel an order (or alert) in the EMS. self,
uuid: str,
) -> bool:
'''
Cancel an order (or alert) in the EMS.
""" '''
cmd = self._sent_orders.get(uuid) cmd = self._sent_orders.get(uuid)
if not cmd: if not cmd:
log.error( log.error(
@ -97,12 +110,21 @@ class OrderBook(Struct):
f'Maybe there is a stale entry or line?\n' f'Maybe there is a stale entry or line?\n'
f'You should report this as a bug!' f'You should report this as a bug!'
) )
fqme = str(cmd.symbol)
msg = Cancel( msg = Cancel(
oid=uuid, oid=uuid,
symbol=cmd.symbol, symbol=fqme,
) )
self._to_ems.send_nowait(msg) self._to_ems.send_nowait(msg)
# TODO: make this an async version..
def cancel(
self,
uuid: str,
) -> bool:
log.warning('USE `.cancel_nowait()` instead!')
return self.cancel_nowait(uuid)
_orders: OrderBook = None _orders: OrderBook = None