Port order mode to new order line api

basic_orders
Tyler Goodlet 2021-02-11 23:42:57 -05:00
parent d91f07c947
commit b794855ad3
1 changed files with 68 additions and 37 deletions

View File

@ -223,9 +223,12 @@ class LineEditor:
def stage_line( def stage_line(
self, self,
color: str = 'alert_yellow', color: str = 'alert_yellow',
hl_on_hover: bool = False, hl_on_hover: bool = False,
dotted: bool = False, dotted: bool = False,
# fields settings
size: Optional[int] = None, size: Optional[int] = None,
) -> LevelLine: ) -> LevelLine:
"""Stage a line at the current chart's cursor position """Stage a line at the current chart's cursor position
@ -238,20 +241,31 @@ class LineEditor:
cursor = chart._cursor cursor = chart._cursor
y = chart._cursor._datum_xy[1] y = chart._cursor._datum_xy[1]
symbol = chart._lc.symbol
line = self._stage_line line = self._stage_line
if not line: if not line:
# add a "staged" cursor-tracking line to view # add a "staged" cursor-tracking line to view
# and cash it in a a var # and cash it in a a var
line = order_line( line = order_line(
chart, chart,
level=y,
digits=chart._lc.symbol.digits(),
color=color,
level=y,
level_digits=symbol.digits(),
size=size,
size_digits=symbol.lot_digits(),
# just for the stage line to avoid
# flickering while moving the cursor
# around where it might trigger highlight
# then non-highlight depending on sensitivity
always_show_labels=True,
# kwargs
color=color,
# 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,
size=size,
) )
# line.label._use_extra_fields = size is not None # line.label._use_extra_fields = size is not None
@ -260,13 +274,13 @@ class LineEditor:
else: else:
# apply input settings to existing staging line # apply input settings to existing staging line
label = line.label # label = line.label
# disable order size and other extras in label # disable order size and other extras in label
label._use_extra_fields = size is not None # label._use_extra_fields = size is not None
label.size = size # label.size = size
label.color = color # label.color = color
# Use the existing staged line instead but copy # Use the existing staged line instead but copy
# overe it's current style "properties". # overe it's current style "properties".
@ -276,20 +290,18 @@ class LineEditor:
line.color = color line.color = color
line.setMouseHover(hl_on_hover) line.setMouseHover(hl_on_hover)
line.show() line.show()
line.show_labels()
# XXX: must have this to trigger updated # XXX: must have this to trigger updated
# label contents rendering # label contents rendering
line.setPos(y) line.set_level(level=y)
line.set_level()
# show order info label
line.label.update()
line.label.show()
self._active_staged_line = line self._active_staged_line = line
# hide crosshair y-line # hide crosshair y-line and label
cursor.graphics[chart]['hl'].hide() cg = cursor.graphics[chart]
cg['hl'].hide()
cg['yl'].hide()
# add line to cursor trackers # add line to cursor trackers
cursor._trackers.add(line) cursor._trackers.add(line)
@ -310,16 +322,20 @@ class LineEditor:
cursor._trackers.remove(line) cursor._trackers.remove(line)
self._active_staged_line = None self._active_staged_line = None
self._stage_line.hide() sl = self._stage_line
self._stage_line.label.hide() if sl:
sl.hide()
sl.hide_labels()
# show the crosshair y line # show the crosshair y line and label
hl = cursor.graphics[chart]['hl'] cg = cursor.graphics[chart]
hl.show() cg['hl'].show()
cg['yl'].show()
def create_line( def create_order_line(
self, self,
uuid: str uuid: str,
size: float,
) -> LevelLine: ) -> LevelLine:
line = self._active_staged_line line = self._active_staged_line
@ -328,17 +344,24 @@ class LineEditor:
chart = self.chart._cursor.active_plot chart = self.chart._cursor.active_plot
y = chart._cursor._datum_xy[1] y = chart._cursor._datum_xy[1]
sym = chart._lc.symbol
line = order_line( line = order_line(
chart, chart,
# label fields default values
level=y, level=y,
level_digits=sym.digits(),
size=size,
size_digits=sym.lot_digits(),
# LevelLine kwargs
color=line.color, color=line.color,
digits=chart._lc.symbol.digits(),
dotted=line._dotted, dotted=line._dotted,
size=line.label.size,
) )
# for now, until submission reponse arrives # for now, until submission reponse arrives
line.label.hide() line.hide_labels()
# register for later lookup/deletion # register for later lookup/deletion
self._order_lines[uuid] = line self._order_lines[uuid] = line
@ -358,9 +381,9 @@ class LineEditor:
return return
else: else:
line.oid = uuid line.oid = uuid
line.set_level() # line.set_level(line.level)
line.label.update() line.show_labels()
line.label.show() # line.label.show()
# TODO: other flashy things to indicate the order is active # TODO: other flashy things to indicate the order is active
@ -465,7 +488,7 @@ class OrderMode:
} }
_action: str = 'alert' _action: str = 'alert'
_exec_mode: str = 'dark' _exec_mode: str = 'dark'
_size: int = 100 _size: float = 100.0
key_map: Dict[str, Callable] = field(default_factory=dict) key_map: Dict[str, Callable] = field(default_factory=dict)
@ -485,7 +508,7 @@ class OrderMode:
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, size=size or self._size,
) )
def on_submit(self, uuid: str) -> dict: def on_submit(self, uuid: str) -> dict:
@ -559,7 +582,10 @@ class OrderMode:
f'Received cancel for unsubmitted order {pformat(msg)}' f'Received cancel for unsubmitted order {pformat(msg)}'
) )
def submit_exec(self) -> None: def submit_exec(
self,
size: Optional[float] = None,
) -> LevelLine:
"""Send execution order to EMS. """Send execution order to EMS.
""" """
@ -569,8 +595,13 @@ class OrderMode:
# order is live in the emsd). # order is live in the emsd).
uid = str(uuid.uuid4()) uid = str(uuid.uuid4())
size = size or self._size
# make line graphic # make line graphic
line, y = self.lines.create_line(uid) line, y = self.lines.create_order_line(
uid,
size=size,
)
line.oid = uid line.oid = uid
# send order cmd to ems # send order cmd to ems
@ -578,6 +609,7 @@ class OrderMode:
uuid=uid, uuid=uid,
symbol=self.chart._lc._symbol, symbol=self.chart._lc._symbol,
price=y, price=y,
size=size,
action=self._action, action=self._action,
exec_mode=self._exec_mode, exec_mode=self._exec_mode,
) )
@ -902,7 +934,6 @@ class ChartView(ViewBox):
mode.book.cancel(uuid=line.oid) mode.book.cancel(uuid=line.oid)
self._key_buffer.append(text) self._key_buffer.append(text)
order_size = self.mode._size
# View modes # View modes
if key == QtCore.Qt.Key_R: if key == QtCore.Qt.Key_R:
@ -911,13 +942,13 @@ class ChartView(ViewBox):
# Order modes: stage orders at the current cursor level # Order modes: stage orders at the current cursor level
elif key == QtCore.Qt.Key_D: # for "damp eet" elif key == QtCore.Qt.Key_D: # for "damp eet"
self.mode.set_exec('sell', size=order_size) self.mode.set_exec('sell')
elif key == QtCore.Qt.Key_F: # for "fillz eet" elif key == QtCore.Qt.Key_F: # for "fillz eet"
self.mode.set_exec('buy', size=order_size) self.mode.set_exec('buy')
elif key == QtCore.Qt.Key_A: elif key == QtCore.Qt.Key_A:
self.mode.set_exec('alert', size=None) self.mode.set_exec('alert')
# delete orders under cursor # delete orders under cursor
elif key == QtCore.Qt.Key_Delete: elif key == QtCore.Qt.Key_Delete: