Port `accounting._pos` to new `Symbol` simplifications

pre_overruns_ctxcancelled
Tyler Goodlet 2023-03-14 20:58:55 -04:00
parent b74c41cb77
commit ef915273ea
1 changed files with 13 additions and 18 deletions

View File

@ -45,6 +45,7 @@ from ._ledger import (
) )
from ._mktinfo import ( from ._mktinfo import (
Symbol, Symbol,
# MktPair,
unpack_fqsn, unpack_fqsn,
) )
from .. import config from .. import config
@ -62,7 +63,7 @@ class Position(Struct):
transaction history. transaction history.
''' '''
symbol: Symbol symbol: Symbol # | MktPair
# can be +ve or -ve for long/short # can be +ve or -ve for long/short
size: float size: float
@ -113,7 +114,7 @@ class Position(Struct):
# it via the trades ledger.. # it via the trades ledger..
# drop symbol obj in serialized form # drop symbol obj in serialized form
s = d.pop('symbol') s = d.pop('symbol')
fqsn = s.front_fqsn() fqsn = s.fqme
broker, key, suffix = unpack_fqsn(fqsn) broker, key, suffix = unpack_fqsn(fqsn)
sym_info = s.broker_info[broker] sym_info = s.broker_info[broker]
@ -157,7 +158,6 @@ class Position(Struct):
inline_table['tid'] = tid inline_table['tid'] = tid
toml_clears_list.append(inline_table) toml_clears_list.append(inline_table)
d['clears'] = toml_clears_list d['clears'] = toml_clears_list
return fqsn, d return fqsn, d
@ -218,19 +218,14 @@ class Position(Struct):
symbol = self.symbol symbol = self.symbol
lot_size_digits = symbol.lot_size_digits lot_size_digits = symbol.lot_size_digits
ppu, size = ( self.ppu = round(
round(
msg['avg_price'], msg['avg_price'],
ndigits=symbol.tick_size_digits ndigits=symbol.tick_size_digits,
), )
round( self.size = round(
msg['size'], msg['size'],
ndigits=lot_size_digits ndigits=lot_size_digits,
),
) )
self.ppu = ppu
self.size = size
@property @property
def dsize(self) -> float: def dsize(self) -> float:
@ -406,7 +401,7 @@ class Position(Struct):
size = round(size * self.split_ratio) size = round(size * self.split_ratio)
return float( return float(
self.symbol.quantize_size(size), self.symbol.quantize(size),
) )
def minimize_clears( def minimize_clears(
@ -466,8 +461,8 @@ class Position(Struct):
return clear return clear
def sugest_split(self) -> float: # def sugest_split(self) -> float:
... # ...
class PpTable(Struct): class PpTable(Struct):