Pass correct instrument symbol in position msgs

open_order_loading
Tyler Goodlet 2022-08-16 11:19:21 -04:00
parent bafd2cb44f
commit 43bdd4d022
1 changed files with 6 additions and 23 deletions

View File

@ -253,15 +253,6 @@ class PaperBoi(Struct):
status='closed', status='closed',
filled=size, filled=size,
remaining=0 if order_complete else remaining, remaining=0 if order_complete else remaining,
# broker_details={
# 'paper_info': {
# 'oid': oid,
# },
# 'action': action,
# 'size': size,
# 'price': price,
# 'name': self.broker,
# },
) )
await self.ems_trades_stream.send(msg) await self.ems_trades_stream.send(msg)
@ -270,7 +261,10 @@ class PaperBoi(Struct):
pp = self._positions.setdefault( pp = self._positions.setdefault(
token, token,
Position( Position(
Symbol(key=symbol), Symbol(
key=symbol,
broker_info={self.broker: {}},
),
size=size, size=size,
ppu=price, ppu=price,
bsuid=symbol, bsuid=symbol,
@ -403,10 +397,8 @@ async def handle_order_requests(
) -> None: ) -> None:
# order_request: dict request_msg: dict
async for request_msg in ems_order_stream: async for request_msg in ems_order_stream:
# action = request_msg['action']
match request_msg: match request_msg:
case {'action': ('buy' | 'sell')}: case {'action': ('buy' | 'sell')}:
order = BrokerdOrder(**request_msg) order = BrokerdOrder(**request_msg)
@ -417,9 +409,7 @@ async def handle_order_requests(
' only a `paper` selection is valid' ' only a `paper` selection is valid'
) )
await ems_order_stream.send(BrokerdError( await ems_order_stream.send(BrokerdError(
# oid=request_msg['oid'],
oid=order.oid, oid=order.oid,
# symbol=request_msg['symbol'],
symbol=order.symbol, symbol=order.symbol,
reason=f'Paper only. No account found: `{account}` ?', reason=f'Paper only. No account found: `{account}` ?',
)) ))
@ -430,25 +420,18 @@ async def handle_order_requests(
# deliver ack that order has been submitted to broker routing # deliver ack that order has been submitted to broker routing
await ems_order_stream.send( await ems_order_stream.send(
BrokerdOrderAck( BrokerdOrderAck(
# ems order request id
oid=order.oid, oid=order.oid,
# broker specific request id
reqid=reqid, reqid=reqid,
) )
) )
# call our client api to submit the order # call our client api to submit the order
reqid = await client.submit_limit( reqid = await client.submit_limit(
oid=order.oid, oid=order.oid,
symbol=order.symbol, symbol=order.symbol,
price=order.price, price=order.price,
action=order.action, action=order.action,
size=order.size, size=order.size,
# XXX: by default 0 tells ``ib_insync`` methods that # XXX: by default 0 tells ``ib_insync`` methods that
# there is no existing order so ask the client to create # there is no existing order so ask the client to create
# a new one (which it seems to do by allocating an int # a new one (which it seems to do by allocating an int
@ -511,7 +494,7 @@ async def trades_dialogue(
pp_msgs.append(BrokerdPosition( pp_msgs.append(BrokerdPosition(
broker=broker, broker=broker,
account='paper', account='paper',
symbol=fqsn, symbol=pos.symbol.front_fqsn(),
size=pos.size, size=pos.size,
avg_price=pos.ppu, avg_price=pos.ppu,
)) ))