Store positions globally and deliver on ctx connects

open_order_loading
Tyler Goodlet 2022-08-14 16:39:35 -04:00
parent c4af706d51
commit 317610e00a
1 changed files with 15 additions and 2 deletions

View File

@ -482,6 +482,7 @@ _sells: dict[
tuple[float, str, str], tuple[float, str, str],
] ]
] = {} ] = {}
_positions: dict[str, Position] = {}
@tractor.context @tractor.context
@ -503,10 +504,22 @@ async def trades_dialogue(
) as feed, ) as feed,
): ):
pp_msgs: list[BrokerdPosition] = []
pos: Position
token: str # f'{symbol}.{self.broker}'
for token, pos in _positions.items():
pp_msgs.append(BrokerdPosition(
broker=broker,
account='paper',
symbol=fqsn,
size=pos.size,
avg_price=pos.ppu,
))
# TODO: load paper positions per broker from .toml config file # TODO: load paper positions per broker from .toml config file
# and pass as symbol to position data mapping: ``dict[str, dict]`` # and pass as symbol to position data mapping: ``dict[str, dict]``
# await ctx.started(all_positions) # await ctx.started(all_positions)
await ctx.started(({}, ['paper'])) await ctx.started((pp_msgs, ['paper']))
async with ( async with (
ctx.open_stream() as ems_stream, ctx.open_stream() as ems_stream,
@ -521,7 +534,7 @@ async def trades_dialogue(
_reqids=_reqids, _reqids=_reqids,
# TODO: load paper positions from ``positions.toml`` # TODO: load paper positions from ``positions.toml``
_positions={}, _positions=_positions,
# TODO: load postions from ledger file # TODO: load postions from ledger file
_trade_ledger={}, _trade_ledger={},