Fix pp line label update logic

We weren't updating the LHS size labels on creation and we now use the
lot size digits to do so. Change `PositionTracker.update()` to
`.update_from_pp_msg()`.
fsp_feeds
Tyler Goodlet 2021-09-05 13:50:53 -04:00
parent 171832cfb8
commit 27f10293bd
1 changed files with 33 additions and 26 deletions

View File

@ -622,20 +622,22 @@ class PositionTracker:
self.pp_label.update() self.pp_label.update()
self.size_label.update() self.size_label.update()
def update( def update_from_pp_msg(
self, self,
msg: BrokerdPosition, msg: BrokerdPosition,
position: Optional[Position] = None, position: Optional[Position] = None,
) -> None: ) -> None:
'''Update graphics and data from average price and size. '''Update graphics and data from average price and size passed in our
EMS ``BrokerdPosition`` msg.
''' '''
# XXX: better place to do this? # XXX: better place to do this?
symbol = self.chart.linked.symbol symbol = self.chart.linked.symbol
lot_size_digits = symbol.lot_size_digits
avg_price, size = ( avg_price, size = (
round(msg['avg_price'], ndigits=symbol.tick_size_digits), round(msg['avg_price'], ndigits=symbol.tick_size_digits),
round(msg['size'], ndigits=symbol.lot_size_digits), round(msg['size'], ndigits=lot_size_digits),
) )
# live pp updates # live pp updates
@ -643,7 +645,11 @@ class PositionTracker:
pp.avg_price = avg_price pp.avg_price = avg_price
pp.size = size pp.size = size
self.update_line(avg_price, size) self.update_line(
avg_price,
size,
lot_size_digits,
)
# label updates # label updates
self.size_label.fields['slots_used'] = round( self.size_label.fields['slots_used'] = round(
@ -739,6 +745,7 @@ class PositionTracker:
self, self,
price: float, price: float,
size: float, size: float,
size_digits: int,
) -> None: ) -> None:
'''Update personal position level line. '''Update personal position level line.
@ -747,32 +754,32 @@ class PositionTracker:
# do line update # do line update
line = self.line line = self.line
if line is None and size: if size:
if line is None:
# create and show a pp line # create and show a pp line
line = self.line = position_line( line = self.line = position_line(
chart=self.chart, chart=self.chart,
level=price, level=price,
size=size, size=size,
color=self._color, color=self._color,
marker=self._level_marker, marker=self._level_marker,
) )
line.show()
elif line: else:
if size != 0.0:
line.set_level(price) line.set_level(price)
self._level_marker.level = price self._level_marker.level = price
self._level_marker.update() self._level_marker.update()
# update LHS sizing label
line.update_labels({
'size': size,
'fiat_size': round(price * size, ndigits=2)
})
line.show()
else: # update LHS sizing label
# remove pp line from view line.update_labels({
line.delete() 'size': size,
self.line = None 'size_digits': size_digits,
'fiat_size': round(price * size, ndigits=2)
})
line.show()
elif line: # remove pp line from view if it exists on a net-zero pp
line.delete()
self.line = None