From c617a069050e0a868bc7154acf28bf15fd315710 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 18 Jun 2022 15:53:12 -0400 Subject: [PATCH] Port everything to `Position.be_price` --- piker/clearing/_allocate.py | 12 ++++++------ piker/clearing/_paper_engine.py | 2 +- piker/ui/_position.py | 10 +++++----- piker/ui/order_mode.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/piker/clearing/_allocate.py b/piker/clearing/_allocate.py index 7ee2b0be..336a9b25 100644 --- a/piker/clearing/_allocate.py +++ b/piker/clearing/_allocate.py @@ -130,7 +130,7 @@ class Allocator(BaseModel): l_sub_pp = self.units_limit - abs_live_size elif size_unit == 'currency': - live_cost_basis = abs_live_size * live_pp.avg_price + live_cost_basis = abs_live_size * live_pp.be_price slot_size = currency_per_slot / price l_sub_pp = (self.currency_limit - live_cost_basis) / price @@ -162,7 +162,7 @@ class Allocator(BaseModel): if size_unit == 'currency': # compute the "projected" limit's worth of units at the # current pp (weighted) price: - slot_size = currency_per_slot / live_pp.avg_price + slot_size = currency_per_slot / live_pp.be_price else: slot_size = u_per_slot @@ -204,7 +204,7 @@ class Allocator(BaseModel): Position( symbol=sym, size=order_size, - avg_price=price, + be_price=price, bsuid=sym, ) ) @@ -233,8 +233,8 @@ class Allocator(BaseModel): abs_pp_size = abs(pp.size) if self.size_unit == 'currency': - # live_currency_size = size or (abs_pp_size * pp.avg_price) - live_currency_size = abs_pp_size * pp.avg_price + # live_currency_size = size or (abs_pp_size * pp.be_price) + live_currency_size = abs_pp_size * pp.be_price prop = live_currency_size / self.currency_limit else: @@ -304,7 +304,7 @@ def mk_allocator( # if the current position is already greater then the limit # settings, increase the limit to the current position if alloc.size_unit == 'currency': - startup_size = startup_pp.size * startup_pp.avg_price + startup_size = startup_pp.size * startup_pp.be_price if startup_size > alloc.currency_limit: alloc.currency_limit = round(startup_size, ndigits=2) diff --git a/piker/clearing/_paper_engine.py b/piker/clearing/_paper_engine.py index 9e70dce2..bd78e1b4 100644 --- a/piker/clearing/_paper_engine.py +++ b/piker/clearing/_paper_engine.py @@ -263,7 +263,7 @@ class PaperBoi: pp = Position( Symbol(key=symbol), size=pp_msg.size, - avg_price=pp_msg.avg_price, + be_price=pp_msg.avg_price, uid=symbol.front_fqsn(), ) pp_msg.size, pp_msg.avg_price = pp.lifo_update(size, price) diff --git a/piker/ui/_position.py b/piker/ui/_position.py index 844869b0..6a1ab01e 100644 --- a/piker/ui/_position.py +++ b/piker/ui/_position.py @@ -106,8 +106,8 @@ async def update_pnl_from_feed( # compute and display pnl status order_mode.pane.pnl_label.format( pnl=copysign(1, size) * pnl( - # live.avg_price, - order_mode.current_pp.live_pp.avg_price, + # live.be_price, + order_mode.current_pp.live_pp.be_price, tick['price'], ), ) @@ -357,7 +357,7 @@ class SettingsPane: # last historical close price last = feed.shm.array[-1][['close']][0] pnl_value = copysign(1, size) * pnl( - tracker.live_pp.avg_price, + tracker.live_pp.be_price, last, ) @@ -557,7 +557,7 @@ class PositionTracker: pp = position or self.live_pp self.update_line( - pp.avg_price, + pp.be_price, pp.size, self.chart.linked.symbol.lot_size_digits, ) @@ -571,7 +571,7 @@ class PositionTracker: self.hide() else: - self._level_marker.level = pp.avg_price + self._level_marker.level = pp.be_price # these updates are critical to avoid lag on view/scene changes self._level_marker.update() # trigger paint diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index 03132b8e..f5a85d64 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -606,7 +606,7 @@ async def open_order_mode( startup_pp = Position( symbol=symbol, size=0, - avg_price=0, + be_price=0, # XXX: BLEH, do we care about this on the client side? bsuid=symbol,