Always cast ems `requid` values to `int`

dict_differ
Tyler Goodlet 2022-08-05 17:07:50 -04:00
parent 71cca4ceda
commit 334f512ad3
1 changed files with 18 additions and 14 deletions

View File

@ -42,7 +42,6 @@ from ib_insync.contract import (
from ib_insync.order import ( from ib_insync.order import (
Trade, Trade,
OrderStatus, OrderStatus,
Order,
) )
from ib_insync.objects import ( from ib_insync.objects import (
Fill, Fill,
@ -124,10 +123,11 @@ async def handle_order_requests(
f'An IB account number for name {account} is not found?\n' f'An IB account number for name {account} is not found?\n'
'Make sure you have all TWS and GW instances running.' 'Make sure you have all TWS and GW instances running.'
) )
await ems_order_stream.send(BrokerdError( await ems_order_stream.send(
oid=request_msg['oid'], BrokerdError(
symbol=request_msg['symbol'], oid=request_msg['oid'],
reason=f'No account found: `{account}` ?', symbol=request_msg['symbol'],
reason=f'No account found: `{account}` ?',
)) ))
continue continue
@ -148,6 +148,14 @@ async def handle_order_requests(
# validate # validate
order = BrokerdOrder(**request_msg) order = BrokerdOrder(**request_msg)
# 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..)
reqid = order.reqid
if reqid is not None:
reqid = int(reqid)
# call our client api to submit the order # call our client api to submit the order
reqid = client.submit_limit( reqid = client.submit_limit(
oid=order.oid, oid=order.oid,
@ -156,12 +164,7 @@ async def handle_order_requests(
action=order.action, action=order.action,
size=order.size, size=order.size,
account=acct_number, account=acct_number,
reqid=reqid,
# 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..)
reqid=order.reqid,
) )
if reqid is None: if reqid is None:
await ems_order_stream.send(BrokerdError( await ems_order_stream.send(BrokerdError(
@ -183,7 +186,7 @@ async def handle_order_requests(
elif action == 'cancel': elif action == 'cancel':
msg = BrokerdCancel(**request_msg) msg = BrokerdCancel(**request_msg)
client.submit_cancel(reqid=msg.reqid) client.submit_cancel(reqid=int(msg.reqid))
else: else:
log.error(f'Unknown order command: {request_msg}') log.error(f'Unknown order command: {request_msg}')
@ -493,8 +496,9 @@ async def trades_dialogue(
filled=0, filled=0,
reason='Existing live order', reason='Existing live order',
# this seems to not be necessarily up to date in the # this seems to not be necessarily up to date in
# execDetails event.. so we have to send it here I guess? # the execDetails event.. so we have to send it
# here I guess?
remaining=quant, remaining=quant,
broker_details={ broker_details={
'name': 'ib', 'name': 'ib',