Attempt to handle existing order updates with ib backend

basic_orders
Tyler Goodlet 2021-03-06 16:33:56 -05:00
parent a1a1dec885
commit 2cabe1831c
1 changed files with 14 additions and 3 deletions

View File

@ -440,11 +440,19 @@ class Client:
# async to be consistent for the client proxy, and cuz why not. # async to be consistent for the client proxy, and cuz why not.
async def submit_limit( async def submit_limit(
self, self,
oid: str, # XXX: see return value # ignored since ib doesn't support defining your
# own order id
oid: str,
symbol: str, symbol: str,
price: float, price: float,
action: str, action: str,
size: int, size: int,
# XXX: by default 0 tells ``ib_insync`` methods that there is no
# existing order so ask the client to create a new one (which
# it seems to do by allocating an int counter - collision
# prone..)
brid: int = None,
) -> int: ) -> int:
"""Place an order and return integer request id provided by client. """Place an order and return integer request id provided by client.
@ -460,7 +468,7 @@ class Client:
trade = self.ib.placeOrder( trade = self.ib.placeOrder(
contract, contract,
Order( Order(
# orderId=oid, # stupid api devs.. orderId=brid or 0, # stupid api devs..
action=action.upper(), # BUY/SELL action=action.upper(), # BUY/SELL
orderType='LMT', orderType='LMT',
lmtPrice=price, lmtPrice=price,
@ -1226,6 +1234,9 @@ async def stream_trades(
# it's a trade event generated by TWS usage. # it's a trade event generated by TWS usage.
log.warning(f"TWS triggered trade:\n{pformat(msg)}") log.warning(f"TWS triggered trade:\n{pformat(msg)}")
msg['reqid'] = 'tws-' + msg['reqid'] msg['reqid'] = 'tws-' + str(-1 * msg['reqid'])
yield {'remote_trades': (event_name, msg)}
continue
yield {'local_trades': (event_name, msg)} yield {'local_trades': (event_name, msg)}