Pass position msg to tracker, append fill msgs

ordermodepps_backup
Tyler Goodlet 2021-07-22 11:39:47 -04:00
parent 174b9ce0cf
commit ca2729d2c0
1 changed files with 11 additions and 27 deletions

View File

@ -33,7 +33,7 @@ from ..data._source import Symbol
from ..log import get_logger from ..log import get_logger
from ._editors import LineEditor, ArrowEditor from ._editors import LineEditor, ArrowEditor
from ._lines import LevelLine from ._lines import LevelLine
from ._position import PositionInfo from ._position import PositionTracker
from ._window import MultiStatus, main_window from ._window import MultiStatus, main_window
@ -259,8 +259,7 @@ class OrderMode:
chart = cursor.active_plot chart = cursor.active_plot
y = cursor._datum_xy[1] y = cursor._datum_xy[1]
symbol = self.chart._lc._symbol symbol = self.chart.linked.symbol
action = self._action action = self._action
# TODO: update the line once an ack event comes back # TODO: update the line once an ack event comes back
@ -423,7 +422,7 @@ async def run_order_mode(
log.info("Opening order mode") log.info("Opening order mode")
pp = PositionInfo(chart) pp = PositionTracker(chart)
mode = OrderMode( mode = OrderMode(
chart, chart,
@ -432,6 +431,8 @@ async def run_order_mode(
arrows, arrows,
status_bar, status_bar,
) )
# so that view handlers can access it
mode.pp = pp mode.pp = pp
view.mode = mode view.mode = mode
@ -451,19 +452,10 @@ async def run_order_mode(
# update any exising position # update any exising position
for sym, msg in positions.items(): for sym, msg in positions.items():
our_sym = mode.chart._lc._symbol.key our_sym = mode.chart.linked._symbol.key
if sym.lower() in our_sym: if sym.lower() in our_sym:
pp.update( pp.update(msg)
avg_price=msg['avg_price'],
size=msg['size'],
)
# mode._position.update(msg)
# size = msg['size']
# price = msg['avg_price']
# pp_label.fields['entry_size'] = size
# pp_label.render()
def get_index(time: float): def get_index(time: float):
@ -501,20 +493,10 @@ async def run_order_mode(
): ):
# show line label once order is live # show line label once order is live
sym = mode.chart._lc._symbol sym = mode.chart.linked.symbol
if msg['symbol'].lower() in sym.key: if msg['symbol'].lower() in sym.key:
pp.update( pp.update(msg)
avg_price=msg['avg_price'],
size=msg['size'],
)
# mode._position.update(msg)
# size = msg['size']
# price = msg['avg_price']
# pp.update(size, price)
# pp_label.fields['entry_size'] = size
# pp_label.render()
# short circuit to next msg to avoid # short circuit to next msg to avoid
# uncessary msg content lookups # uncessary msg content lookups
@ -594,3 +576,5 @@ async def run_order_mode(
# TODO: put the actual exchange timestamp # TODO: put the actual exchange timestamp
arrow_index=get_index(details['broker_time']), arrow_index=get_index(details['broker_time']),
) )
pp.info.fills.append(msg)