Start drafting out alloctor settings per asset type

fsp_feeds
Tyler Goodlet 2021-08-18 08:42:56 -04:00
parent be956c4031
commit 17fbe6a6ab
1 changed files with 32 additions and 18 deletions

View File

@ -88,6 +88,7 @@ class OrderMode:
multistatus: MultiStatus multistatus: MultiStatus
pp: PositionTracker pp: PositionTracker
allocator: 'Allocator' # noqa allocator: 'Allocator' # noqa
active: bool = False
name: str = 'order' name: str = 'order'
dialogs: dict[str, OrderDialog] = field(default_factory=dict) dialogs: dict[str, OrderDialog] = field(default_factory=dict)
@ -140,6 +141,7 @@ class OrderMode:
order_info = self.allocator.get_order_info( order_info = self.allocator.get_order_info(
symbol=symbol, symbol=symbol,
price=y, price=y,
action=order.action,
) )
line.update_labels(order_info) line.update_labels(order_info)
order.price = y order.price = y
@ -501,9 +503,9 @@ async def run_order_mode(
log.info("Opening order mode") log.info("Opening order mode")
alloc = chart.linked.godwidget.pp_pane.model alloc = chart.linked.godwidget.pp_pane.model
pp = PositionTracker(chart) pp_tracker = PositionTracker(chart, alloc=alloc)
pp.hide() pp_tracker.hide()
alloc._position = pp alloc._position = pp_tracker
mode = OrderMode( mode = OrderMode(
chart, chart,
@ -511,33 +513,45 @@ async def run_order_mode(
lines, lines,
arrows, arrows,
multistatus, multistatus,
pp, pp_tracker,
allocator=alloc, allocator=alloc,
) )
# TODO: create a mode "manager" of sorts? # TODO: create a mode "manager" of sorts?
# -> probably just call it "UxModes" err sumthin? # -> probably just call it "UxModes" err sumthin?
# so that view handlers can access it # so that view handlers can access it
view.mode = mode view.order_mode = mode
asset_type = symbol.type_key asset_type = symbol.type_key
# default entry sizing
if asset_type == 'stock':
mode._size = 100.0
elif asset_type in ('future', 'option', 'futures_option'):
mode._size = 1.0
else: # to be safe
mode._size = 1.0
# update any exising position # update any exising position
for sym, msg in positions.items(): for sym, msg in positions.items():
our_sym = mode.chart.linked._symbol.key our_sym = mode.chart.linked._symbol.key
if sym.lower() in our_sym: if sym.lower() in our_sym:
pp.update(msg) pp_tracker.update(msg, position=pp_tracker.startup_pp)
pp_tracker.update(msg)
# default entry sizing
if asset_type in ('stock', 'crypto', 'forex'):
alloc.size_unit = '$ size'
pp_tracker.pane.fields['size_unit'].setCurrentText(alloc.size_unit)
elif asset_type in ('future', 'option', 'futures_option'):
alloc.size_unit = '# units'
pp_tracker.pane.fields['size_unit'].setCurrentText(alloc.size_unit)
slots = alloc.slots = pp_tracker.startup_pp.size
pp_tracker.pane.fields['slots'].setText(str(alloc.slots))
# make entry step 1.0
alloc.size = slots
pp_tracker.pane.fields['size'].setText(str(alloc.size))
# make fill bar and positioning snapshot
pp_tracker.init_status_ui()
# TODO: this should go onto some sort of # TODO: this should go onto some sort of
# data-view strimg thinger..right? # data-view strimg thinger..right?
@ -584,7 +598,7 @@ async def run_order_mode(
sym = mode.chart.linked.symbol sym = mode.chart.linked.symbol
if msg['symbol'].lower() in sym.key: if msg['symbol'].lower() in sym.key:
pp.update(msg) pp_tracker.update(msg)
# short circuit to next msg to avoid # short circuit to next msg to avoid
# uncessary msg content lookups # uncessary msg content lookups
@ -672,4 +686,4 @@ async def run_order_mode(
arrow_index=get_index(details['broker_time']), arrow_index=get_index(details['broker_time']),
) )
pp.info.fills.append(msg) pp_tracker.live_pp.fills.append(msg)