Pass action to line editor

basic_orders
Tyler Goodlet 2021-03-13 19:31:03 -05:00
parent c75dacb239
commit 776395791a
2 changed files with 23 additions and 8 deletions

View File

@ -217,6 +217,7 @@ class LineEditor:
def stage_line( def stage_line(
self, self,
action: str,
color: str = 'alert_yellow', color: str = 'alert_yellow',
hl_on_hover: bool = False, hl_on_hover: bool = False,
@ -263,7 +264,11 @@ class LineEditor:
# don't highlight the "staging" line # don't highlight the "staging" line
hl_on_hover=hl_on_hover, hl_on_hover=hl_on_hover,
dotted=dotted, dotted=dotted,
exec_type='dark' if dotted else 'live',
action=action,
show_markers=True,
) )
self._active_staged_line = line self._active_staged_line = line
# hide crosshair y-line and label # hide crosshair y-line and label
@ -299,6 +304,7 @@ class LineEditor:
level: float, level: float,
chart: 'ChartPlotWidget', # noqa chart: 'ChartPlotWidget', # noqa
size: float, size: float,
action: str,
) -> LevelLine: ) -> LevelLine:
line = self._active_staged_line line = self._active_staged_line
@ -320,6 +326,8 @@ class LineEditor:
# LevelLine kwargs # LevelLine kwargs
color=line.color, color=line.color,
dotted=line._dotted, dotted=line._dotted,
action=action,
) )
# for now, until submission reponse arrives # for now, until submission reponse arrives

View File

@ -39,7 +39,6 @@ from ..log import get_logger
log = get_logger(__name__) log = get_logger(__name__)
class Position(BaseModel): class Position(BaseModel):
symbol: Symbol symbol: Symbol
size: float size: float
@ -84,16 +83,19 @@ class OrderMode:
if msg['symbol'].lower() not in sym.key: if msg['symbol'].lower() not in sym.key:
return return
size = msg['size']
self._position.update(msg) self._position.update(msg)
if self._position_line: if self._position_line:
self._position_line.delete() self._position_line.delete()
line = self._position_line = position_line( if size != 0.0:
self.chart, line = self._position_line = position_line(
level=msg['avg_price'], self.chart,
size=msg['size'], level=msg['avg_price'],
) size=size,
line.show() )
line.show()
def uuid(self) -> str: def uuid(self) -> str:
return str(uuid.uuid4()) return str(uuid.uuid4())
@ -108,10 +110,12 @@ class OrderMode:
""" """
self._action = action self._action = action
self.lines.stage_line( self.lines.stage_line(
color=self._colors[action], color=self._colors[action],
# hl_on_hover=True if self._exec_mode == 'live' else False, # hl_on_hover=True if self._exec_mode == 'live' else False,
dotted=True if self._exec_mode == 'dark' else False, dotted=True if self._exec_mode == 'dark' else False,
size=size or self._size, size=size or self._size,
action=action,
) )
def on_submit(self, uuid: str) -> dict: def on_submit(self, uuid: str) -> dict:
@ -206,6 +210,8 @@ class OrderMode:
symbol = self.chart._lc._symbol symbol = self.chart._lc._symbol
action = self._action
# send order cmd to ems # send order cmd to ems
self.book.send( self.book.send(
uuid=uid, uuid=uid,
@ -213,7 +219,7 @@ class OrderMode:
brokers=symbol.brokers, brokers=symbol.brokers,
price=y, price=y,
size=size, size=size,
action=self._action, action=action,
exec_mode=self._exec_mode, exec_mode=self._exec_mode,
) )
@ -224,6 +230,7 @@ class OrderMode:
level=y, level=y,
chart=chart, chart=chart,
size=size, size=size,
action=action,
) )
line.oid = uid line.oid = uid