diff --git a/piker/accounting/__init__.py b/piker/accounting/__init__.py index d8d1fec9..28dd88b4 100644 --- a/piker/accounting/__init__.py +++ b/piker/accounting/__init__.py @@ -61,7 +61,7 @@ def get_likely_pair( dst: str, bs_mktid: str, -) -> str: +) -> str | None: ''' Attempt to get the likely trading pair matching a given destination asset `dst: str`. @@ -76,9 +76,9 @@ def get_likely_pair( # positions where the src fiat was used to # buy some other dst which was furhter used # to buy another dst..) - log.warning( - f'No src fiat {src} found in {bs_mktid}?' - ) + # log.warning( + # f'No src fiat {src} found in {bs_mktid}?' + # ) return likely_dst = bs_mktid[:src_name_start] diff --git a/piker/accounting/_ledger.py b/piker/accounting/_ledger.py index 8025ec3d..564ba9fe 100644 --- a/piker/accounting/_ledger.py +++ b/piker/accounting/_ledger.py @@ -34,7 +34,6 @@ from pendulum import ( datetime, parse, ) -import tomli import toml from .. import config @@ -227,30 +226,12 @@ def open_trade_ledger( name as defined in the user's ``brokers.toml`` config. ''' - ldir: Path = config._config_dir / 'ledgers' - if not ldir.is_dir(): - ldir.mkdir() - - fname = f'trades_{broker}_{account}.toml' - tradesfile: Path = ldir / fname - - if not tradesfile.is_file(): - log.info( - f'Creating new local trades ledger: {tradesfile}' - ) - tradesfile.touch() - - with tradesfile.open(mode='rb') as cf: - start = time.time() - ledger_dict = tomli.load(cf) - log.info(f'Ledger load took {time.time() - start}s') - cpy = ledger_dict.copy() - + ledger_dict, fpath = config.load_ledger(broker, account) + cpy = ledger_dict.copy() ledger = TransactionLedger( ledger_dict=cpy, - file_path=tradesfile, + file_path=fpath, ) - try: yield ledger finally: diff --git a/piker/accounting/_pos.py b/piker/accounting/_pos.py index 12c2e19f..60ba104c 100644 --- a/piker/accounting/_pos.py +++ b/piker/accounting/_pos.py @@ -187,7 +187,7 @@ class Position(Struct): inline_table = toml.TomlDecoder().get_empty_inline_table() # serialize datetime to parsable `str` - dtstr = inline_table['dt'] = str(data['dt']) + dtstr = inline_table['dt'] = data['dt'].isoformat('T') assert 'Datetime' not in dtstr # insert optional clear fields in column order @@ -670,8 +670,7 @@ class PpTable(Struct): pos: Position for bs_mktid, pos in active.items(): - - # keep the minimal amount of clears that make up this + # NOTE: we only store the minimal amount of clears that make up this # position since the last net-zero state. pos.minimize_clears() pos.ensure_state() @@ -679,7 +678,7 @@ class PpTable(Struct): # serialize to pre-toml form fqme, asdict = pos.to_pretoml() - # assert 'Datetime' not in asdict['dt'] + assert 'Datetime' not in asdict['clears'][0]['dt'] log.info(f'Updating active pp: {fqme}') # XXX: ugh, it's cuz we push the section under @@ -807,9 +806,7 @@ def open_pps( ''' conf: dict conf_path: Path - conf, conf_path = config.load( - f'pps.{brokername}.{acctid}', - ) + conf, conf_path = config.load_account(brokername, acctid) if brokername in conf: log.warning( diff --git a/piker/accounting/cli.py b/piker/accounting/cli.py index 7e68ce6f..5cdd4a58 100644 --- a/piker/accounting/cli.py +++ b/piker/accounting/cli.py @@ -79,7 +79,7 @@ def broker_init( # enabled.append('piker.data.feed') # non-blocking setup of brokerd service nursery - from ..brokers import _setup_persistent_brokerd + from ..brokers._daemon import _setup_persistent_brokerd return ( start_actor_kwargs, # to `ActorNursery.start_actor()` @@ -217,4 +217,4 @@ def sync( if __name__ == "__main__": - ledger() + ledger() # this is called from ``>> ledger ``