`order_mode`: broad rename book -> client

pre_overruns_ctxcancelled
Tyler Goodlet 2023-04-08 19:22:53 -04:00
parent 13123b71ac
commit ac6eac046a
1 changed files with 21 additions and 18 deletions

View File

@ -1,5 +1,5 @@
# piker: trading gear for hackers # piker: trading gear for hackers
# Copyright (C) Tyler Goodlet (in stewardship for piker0) # Copyright (C) Tyler Goodlet (in stewardship for pikers)
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -123,7 +123,7 @@ class OrderMode:
chart: ChartPlotWidget # type: ignore # noqa chart: ChartPlotWidget # type: ignore # noqa
hist_chart: ChartPlotWidget # type: ignore # noqa hist_chart: ChartPlotWidget # type: ignore # noqa
nursery: trio.Nursery # used by ``ui._position`` code? nursery: trio.Nursery # used by ``ui._position`` code?
book: OrderClient client: OrderClient
lines: LineEditor lines: LineEditor
arrows: ArrowEditor arrows: ArrowEditor
multistatus: MultiStatus multistatus: MultiStatus
@ -409,13 +409,13 @@ class OrderMode:
# send order cmd to ems # send order cmd to ems
if send_msg: if send_msg:
self.book.send_nowait(order) self.client.send_nowait(order)
else: else:
# just register for control over this order # just register for control over this order
# TODO: some kind of mini-perms system here based on # TODO: some kind of mini-perms system here based on
# an out-of-band tagging/auth sub-sys for multiplayer # an out-of-band tagging/auth sub-sys for multiplayer
# order control? # order control?
self.book._sent_orders[order.oid] = order self.client._sent_orders[order.oid] = order
return dialog return dialog
@ -443,7 +443,7 @@ class OrderMode:
size = dialog.order.size size = dialog.order.size
# NOTE: sends modified order msg to EMS # NOTE: sends modified order msg to EMS
self.book.update_nowait( self.client.update_nowait(
uuid=line.dialog.uuid, uuid=line.dialog.uuid,
price=level, price=level,
size=size, size=size,
@ -559,7 +559,7 @@ class OrderMode:
) -> None: ) -> None:
msg = self.book._sent_orders.pop(uuid, None) msg = self.client._sent_orders.pop(uuid, None)
if msg is not None: if msg is not None:
self.lines.remove_line(uuid=uuid) self.lines.remove_line(uuid=uuid)
@ -615,7 +615,7 @@ class OrderMode:
dialog.last_status_close = cancel_status_close dialog.last_status_close = cancel_status_close
ids.append(oid) ids.append(oid)
self.book.cancel_nowait(uuid=oid) self.client.cancel_nowait(uuid=oid)
return ids return ids
@ -682,7 +682,7 @@ async def open_order_mode(
multistatus = chart.window().status_bar multistatus = chart.window().status_bar
done = multistatus.open_status('starting order mode..') done = multistatus.open_status('starting order mode..')
book: OrderClient client: OrderClient
trades_stream: tractor.MsgStream trades_stream: tractor.MsgStream
# The keys in this dict **must** be in set our set of "normalized" # The keys in this dict **must** be in set our set of "normalized"
@ -693,8 +693,11 @@ async def open_order_mode(
# spawn EMS actor-service # spawn EMS actor-service
async with ( async with (
open_ems(fqsn, loglevel=loglevel) as ( open_ems(
book, fqsn,
loglevel=loglevel,
) as (
client,
trades_stream, trades_stream,
position_msgs, position_msgs,
brokerd_accounts, brokerd_accounts,
@ -821,7 +824,7 @@ async def open_order_mode(
chart, chart,
hist_chart, hist_chart,
tn, tn,
book, client,
lines, lines,
arrows, arrows,
multistatus, multistatus,
@ -873,7 +876,7 @@ async def open_order_mode(
for msg in msgs: for msg in msgs:
await process_trade_msg( await process_trade_msg(
mode, mode,
book, client,
msg, msg,
) )
@ -907,7 +910,7 @@ async def open_order_mode(
await process_trade_msg( await process_trade_msg(
mode, mode,
book, client,
msg, msg,
) )
@ -915,7 +918,7 @@ async def open_order_mode(
process_trades_and_update_ui, process_trades_and_update_ui,
trades_stream, trades_stream,
mode, mode,
book, client,
) )
yield mode yield mode
@ -925,7 +928,7 @@ async def process_trades_and_update_ui(
trades_stream: tractor.MsgStream, trades_stream: tractor.MsgStream,
mode: OrderMode, mode: OrderMode,
book: OrderClient, client: OrderClient,
) -> None: ) -> None:
@ -934,14 +937,14 @@ async def process_trades_and_update_ui(
async for msg in trades_stream: async for msg in trades_stream:
await process_trade_msg( await process_trade_msg(
mode, mode,
book, client,
msg, msg,
) )
async def process_trade_msg( async def process_trade_msg(
mode: OrderMode, mode: OrderMode,
book: OrderClient, client: OrderClient,
msg: dict, msg: dict,
) -> tuple[Dialog, Status]: ) -> tuple[Dialog, Status]:
@ -1079,7 +1082,7 @@ async def process_trade_msg(
case Status(resp='fill'): case Status(resp='fill'):
# handle out-of-piker fills reporting? # handle out-of-piker fills reporting?
order: Order = book._sent_orders.get(oid) order: Order = client._sent_orders.get(oid)
if not order: if not order:
log.warning(f'order {oid} is unknown') log.warning(f'order {oid} is unknown')
order = msg.req order = msg.req