Expose multi-chart-lines support through to order mode api
parent
a4935b8fa8
commit
8e07fda88f
|
@ -85,7 +85,7 @@ class Dialog(Struct):
|
||||||
uuid: str
|
uuid: str
|
||||||
order: Order
|
order: Order
|
||||||
symbol: Symbol
|
symbol: Symbol
|
||||||
line: LevelLine
|
lines: list[LevelLine]
|
||||||
last_status_close: Callable = lambda: None
|
last_status_close: Callable = lambda: None
|
||||||
msgs: dict[str, dict] = {}
|
msgs: dict[str, dict] = {}
|
||||||
fills: dict[str, Any] = {}
|
fills: dict[str, Any] = {}
|
||||||
|
@ -175,14 +175,16 @@ class OrderMode:
|
||||||
def line_from_order(
|
def line_from_order(
|
||||||
self,
|
self,
|
||||||
order: Order,
|
order: Order,
|
||||||
|
chart: Optional[ChartPlotWidget] = None,
|
||||||
**line_kwargs,
|
**line_kwargs,
|
||||||
|
|
||||||
) -> LevelLine:
|
) -> LevelLine:
|
||||||
|
|
||||||
level = order.price
|
level = order.price
|
||||||
|
|
||||||
line = order_line(
|
line = order_line(
|
||||||
|
|
||||||
self.chart,
|
chart or self.chart,
|
||||||
# TODO: convert these values into human-readable form
|
# TODO: convert these values into human-readable form
|
||||||
# (i.e. with k, m, M, B) type embedded suffixes
|
# (i.e. with k, m, M, B) type embedded suffixes
|
||||||
level=level,
|
level=level,
|
||||||
|
@ -224,6 +226,24 @@ class OrderMode:
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
def lines_from_order(
|
||||||
|
self,
|
||||||
|
order: Order,
|
||||||
|
**line_kwargs,
|
||||||
|
|
||||||
|
) -> list[LevelLine]:
|
||||||
|
|
||||||
|
lines: list[LevelLine] = []
|
||||||
|
for chart in [self.chart, self.hist_chart]:
|
||||||
|
line = self.line_from_order(
|
||||||
|
order=order,
|
||||||
|
chart=chart,
|
||||||
|
**line_kwargs,
|
||||||
|
)
|
||||||
|
lines.append(line)
|
||||||
|
|
||||||
|
return lines
|
||||||
|
|
||||||
def stage_order(
|
def stage_order(
|
||||||
self,
|
self,
|
||||||
|
|
||||||
|
@ -236,6 +256,7 @@ class OrderMode:
|
||||||
'''
|
'''
|
||||||
# not initialized yet
|
# not initialized yet
|
||||||
chart = self.chart
|
chart = self.chart
|
||||||
|
|
||||||
cursor = chart.linked.cursor
|
cursor = chart.linked.cursor
|
||||||
if not (chart and cursor and cursor.active_plot):
|
if not (chart and cursor and cursor.active_plot):
|
||||||
return
|
return
|
||||||
|
@ -298,13 +319,12 @@ class OrderMode:
|
||||||
|
|
||||||
order.symbol = order.symbol.front_fqsn()
|
order.symbol = order.symbol.front_fqsn()
|
||||||
|
|
||||||
line = self.line_from_order(
|
# line = self.line_from_order(
|
||||||
|
lines = self.lines_from_order(
|
||||||
order,
|
order,
|
||||||
|
|
||||||
show_markers=True,
|
show_markers=True,
|
||||||
only_show_markers_on_hover=True,
|
only_show_markers_on_hover=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# register the "submitted" line under the cursor
|
# register the "submitted" line under the cursor
|
||||||
# to be displayed when above order ack arrives
|
# to be displayed when above order ack arrives
|
||||||
# (means the marker graphic doesn't show on screen until the
|
# (means the marker graphic doesn't show on screen until the
|
||||||
|
@ -315,8 +335,8 @@ class OrderMode:
|
||||||
# maybe place a grey line in "submission" mode
|
# maybe place a grey line in "submission" mode
|
||||||
# which will be updated to it's appropriate action
|
# which will be updated to it's appropriate action
|
||||||
# color once the submission ack arrives.
|
# color once the submission ack arrives.
|
||||||
self.lines.submit_line(
|
self.lines.submit_lines(
|
||||||
line=line,
|
lines=lines,
|
||||||
uuid=order.oid,
|
uuid=order.oid,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -324,24 +344,25 @@ class OrderMode:
|
||||||
uuid=order.oid,
|
uuid=order.oid,
|
||||||
order=order,
|
order=order,
|
||||||
symbol=order.symbol,
|
symbol=order.symbol,
|
||||||
line=line,
|
lines=lines,
|
||||||
last_status_close=self.multistatus.open_status(
|
last_status_close=self.multistatus.open_status(
|
||||||
f'submitting {order.exec_mode}-{order.action}',
|
f'submitting {order.exec_mode}-{order.action}',
|
||||||
final_msg=f'submitted {order.exec_mode}-{order.action}',
|
final_msg=f'submitted {order.exec_mode}-{order.action}',
|
||||||
clear_on_next=True,
|
clear_on_next=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: create a new ``OrderLine`` with this optional var defined
|
|
||||||
line.dialog = dialog
|
|
||||||
|
|
||||||
# enter submission which will be popped once a response
|
# enter submission which will be popped once a response
|
||||||
# from the EMS is received to move the order to a different# status
|
# from the EMS is received to move the order to a different# status
|
||||||
self.dialogs[order.oid] = dialog
|
self.dialogs[order.oid] = dialog
|
||||||
|
|
||||||
# hook up mouse drag handlers
|
for line in lines:
|
||||||
line._on_drag_start = self.order_line_modify_start
|
|
||||||
line._on_drag_end = self.order_line_modify_complete
|
# TODO: create a new ``OrderLine`` with this optional var defined
|
||||||
|
line.dialog = dialog
|
||||||
|
|
||||||
|
# hook up mouse drag handlers
|
||||||
|
line._on_drag_start = self.order_line_modify_start
|
||||||
|
line._on_drag_end = self.order_line_modify_complete
|
||||||
|
|
||||||
# send order cmd to ems
|
# send order cmd to ems
|
||||||
if send_msg:
|
if send_msg:
|
||||||
|
@ -396,11 +417,11 @@ class OrderMode:
|
||||||
Commit the order line and registered order uuid, store ack time stamp.
|
Commit the order line and registered order uuid, store ack time stamp.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
line = self.lines.commit_line(uuid)
|
lines = self.lines.commit_line(uuid)
|
||||||
|
|
||||||
# a submission is the start of a new order dialog
|
# a submission is the start of a new order dialog
|
||||||
dialog = self.dialogs[uuid]
|
dialog = self.dialogs[uuid]
|
||||||
dialog.line = line
|
dialog.lines = lines
|
||||||
dialog.last_status_close()
|
dialog.last_status_close()
|
||||||
|
|
||||||
return dialog
|
return dialog
|
||||||
|
@ -428,17 +449,18 @@ class OrderMode:
|
||||||
|
|
||||||
'''
|
'''
|
||||||
dialog = self.dialogs[uuid]
|
dialog = self.dialogs[uuid]
|
||||||
line = dialog.line
|
lines = dialog.lines
|
||||||
if line:
|
if lines:
|
||||||
self.arrows.add(
|
for line in lines:
|
||||||
uuid,
|
self.arrows.add(
|
||||||
arrow_index,
|
uuid,
|
||||||
price,
|
arrow_index,
|
||||||
pointing=pointing,
|
price,
|
||||||
color=line.color
|
pointing=pointing,
|
||||||
)
|
color=line.color
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
log.warn("No line for order {uuid}!?")
|
log.warn("No line(s) for order {uuid}!?")
|
||||||
|
|
||||||
async def on_exec(
|
async def on_exec(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Reference in New Issue