From ae711682168e90eaf66f643acbdc0ad0f181f9ca Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 27 Jul 2022 12:08:13 -0400 Subject: [PATCH] Change name `be_price` -> `ppu` throughout codebase --- piker/brokers/ib/broker.py | 4 +-- piker/clearing/_allocate.py | 12 ++++----- piker/clearing/_paper_engine.py | 4 +-- piker/pp.py | 43 +++++++++++++++++---------------- piker/ui/_position.py | 10 ++++---- piker/ui/order_mode.py | 2 +- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/piker/brokers/ib/broker.py b/piker/brokers/ib/broker.py index bc712677..93128240 100644 --- a/piker/brokers/ib/broker.py +++ b/piker/brokers/ib/broker.py @@ -383,7 +383,7 @@ async def update_and_audit_msgs( symbol=ibppmsg.symbol, currency=ibppmsg.currency, size=p.size, - avg_price=p.be_price, + avg_price=p.ppu, ) msgs.append(msg) @@ -430,7 +430,7 @@ async def update_and_audit_msgs( symbol=p.symbol.front_fqsn(), # currency=ibppmsg.currency, size=p.size, - avg_price=p.be_price, + avg_price=p.ppu, ) if validate and p.size: raise ValueError( diff --git a/piker/clearing/_allocate.py b/piker/clearing/_allocate.py index 8e51ed16..62b8c115 100644 --- a/piker/clearing/_allocate.py +++ b/piker/clearing/_allocate.py @@ -126,7 +126,7 @@ class Allocator(Struct): l_sub_pp = self.units_limit - abs_live_size elif size_unit == 'currency': - live_cost_basis = abs_live_size * live_pp.be_price + live_cost_basis = abs_live_size * live_pp.ppu slot_size = currency_per_slot / price l_sub_pp = (self.currency_limit - live_cost_basis) / price @@ -158,7 +158,7 @@ class Allocator(Struct): 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.be_price + slot_size = currency_per_slot / live_pp.ppu else: slot_size = u_per_slot @@ -200,7 +200,7 @@ class Allocator(Struct): Position( symbol=sym, size=order_size, - be_price=price, + ppu=price, bsuid=sym, ) ) @@ -229,8 +229,8 @@ class Allocator(Struct): abs_pp_size = abs(pp.size) if self.size_unit == 'currency': - # live_currency_size = size or (abs_pp_size * pp.be_price) - live_currency_size = abs_pp_size * pp.be_price + # live_currency_size = size or (abs_pp_size * pp.ppu) + live_currency_size = abs_pp_size * pp.ppu prop = live_currency_size / self.currency_limit else: @@ -303,7 +303,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.be_price + startup_size = startup_pp.size * startup_pp.ppu 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 3bb93b80..7d2ceebd 100644 --- a/piker/clearing/_paper_engine.py +++ b/piker/clearing/_paper_engine.py @@ -259,7 +259,7 @@ class PaperBoi: Position( Symbol(key=symbol), size=size, - be_price=price, + ppu=price, bsuid=symbol, ) ) @@ -283,7 +283,7 @@ class PaperBoi: # inferred from the pair? currency='', size=pp.size, - avg_price=pp.be_price, + avg_price=pp.ppu, ) await self.ems_trades_stream.send(pp_msg) diff --git a/piker/pp.py b/piker/pp.py index 5c031ec7..456c2c4f 100644 --- a/piker/pp.py +++ b/piker/pp.py @@ -129,7 +129,7 @@ class Position(Struct): # "breakeven price" above or below which pnl moves above and below # zero for the entirety of the current "trade state". - be_price: float + ppu: float # unique backend symbol id bsuid: str @@ -167,8 +167,8 @@ class Position(Struct): fqsn = s.front_fqsn() size = d.pop('size') - be_price = d.pop('be_price') - d['size'], d['be_price'] = self.audit_sizing(size, be_price) + ppu = d.pop('ppu') + d['size'], d['ppu'] = self.audit_sizing(size, ppu) if self.expiry is None: d.pop('expiry', None) @@ -206,32 +206,32 @@ class Position(Struct): def audit_sizing( self, size: Optional[float] = None, - be_price: Optional[float] = None, + ppu: Optional[float] = None, ) -> tuple[float, float]: ''' - Audit either the `.size` and `.be_price` values or equvialent + Audit either the `.size` and `.ppu` values or equvialent passed in values against the clears table calculations and return the calc-ed values if they differ and log warnings to console. ''' size = size or self.size - be_price = be_price or self.be_price + ppu = ppu or self.ppu csize = self.calc_size() - cbe_price = self.calc_ppu() + cppu = self.calc_ppu() if size != csize: log.warning(f'size != calculated size: {size} != {csize}') size = csize - if be_price != cbe_price: + if ppu != cppu: log.warning( - f'be_price != calculated be_price: {be_price} != {cbe_price}' + f'ppu != calculated ppu: {ppu} != {cppu}' ) - be_price = cbe_price + ppu = cppu - return size, be_price + return size, ppu def update_from_msg( self, @@ -243,7 +243,7 @@ class Position(Struct): symbol = self.symbol lot_size_digits = symbol.lot_size_digits - be_price, size = ( + ppu, size = ( round( msg['avg_price'], ndigits=symbol.tick_size_digits @@ -254,7 +254,7 @@ class Position(Struct): ), ) - self.be_price = be_price + self.ppu = ppu self.size = size @property @@ -264,7 +264,7 @@ class Position(Struct): terms. ''' - return self.be_price * self.size + return self.ppu * self.size # TODO: idea: "real LIFO" dynamic positioning. # - when a trade takes place where the pnl for @@ -444,7 +444,7 @@ class Position(Struct): # in order to make the recurrence relation math work # inside ``.calc_size()``. self.size = clear['accum_size'] = self.calc_size() - self.be_price = clear['ppu'] = self.calc_ppu() + self.ppu = clear['ppu'] = self.calc_ppu() return clear @@ -479,7 +479,7 @@ class PpTable(Struct): info={}, ), size=0.0, - be_price=0.0, + ppu=0.0, bsuid=t.bsuid, expiry=t.expiry, ) @@ -501,7 +501,7 @@ class PpTable(Struct): # minimize clears tables and update sizing. for bsuid, pp in updated.items(): - pp.size, pp.be_price = pp.audit_sizing() + pp.size, pp.ppu = pp.audit_sizing() return updated @@ -534,7 +534,7 @@ class PpTable(Struct): # if bsuid == qqqbsuid: # breakpoint() - pp.size, pp.be_price = pp.audit_sizing() + pp.size, pp.ppu = pp.audit_sizing() if ( # "net-zero" is a "closed" position @@ -846,7 +846,8 @@ def open_pps( clears[tid] = clears_table size = entry['size'] - be_price = entry['be_price'] + # TODO: remove but, handle old field name for now + ppu = entry.get('ppu', entry.get('be_price', 0)) expiry = entry.get('expiry') if expiry: @@ -855,7 +856,7 @@ def open_pps( pp = pp_objs[bsuid] = Position( Symbol.from_fqsn(fqsn, info={}), size=size, - be_price=be_price, + ppu=ppu, expiry=expiry, bsuid=entry['bsuid'], @@ -868,7 +869,7 @@ def open_pps( ) # audit entries loaded from toml - pp.size, pp.be_price = pp.audit_sizing() + pp.size, pp.ppu = pp.audit_sizing() try: yield table diff --git a/piker/ui/_position.py b/piker/ui/_position.py index 6a1ab01e..e02187da 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.be_price, - order_mode.current_pp.live_pp.be_price, + # live.ppu, + order_mode.current_pp.live_pp.ppu, 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.be_price, + tracker.live_pp.ppu, last, ) @@ -557,7 +557,7 @@ class PositionTracker: pp = position or self.live_pp self.update_line( - pp.be_price, + pp.ppu, pp.size, self.chart.linked.symbol.lot_size_digits, ) @@ -571,7 +571,7 @@ class PositionTracker: self.hide() else: - self._level_marker.level = pp.be_price + self._level_marker.level = pp.ppu # 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 83a0ed48..ce08a64c 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -610,7 +610,7 @@ async def open_order_mode( startup_pp = Position( symbol=symbol, size=0, - be_price=0, + ppu=0, # XXX: BLEH, do we care about this on the client side? bsuid=symbol,