Async enter/open the symcache in paper engine

Since we don't want to be doing a `trio.run()` from async code (being
already in the `tractor` runtime and all); for now just put a top level
block wrapping async enter until we figure out to embed it (likely)
inside `open_account()` and pass the ref to `open_trade_ledger()`.
account_tests
Tyler Goodlet 2023-07-10 17:52:23 -04:00
parent 108e8c7082
commit 06c581bfab
1 changed files with 123 additions and 117 deletions

View File

@ -49,9 +49,10 @@ from ..accounting import (
Transaction, Transaction,
TransactionLedger, TransactionLedger,
open_trade_ledger, open_trade_ledger,
open_pps, open_account,
) )
from ..data import iterticks from ..data import iterticks
from ..data._symcache import open_symcache
from ..accounting import unpack_fqme from ..accounting import unpack_fqme
from ._util import ( from ._util import (
log, # sub-sys logger log, # sub-sys logger
@ -541,10 +542,15 @@ async def open_trade_dialog(
# enable piker.clearing console log for *this* subactor # enable piker.clearing console log for *this* subactor
get_console_log(loglevel) get_console_log(loglevel)
async with open_symcache(get_brokermod(broker)) as symcache:
acnt: Account acnt: Account
ledger: TransactionLedger ledger: TransactionLedger
with ( with (
open_pps(
# TODO: probably do the symcache and ledger loading
# implicitly behind this? Deliver an account, and ledger
# pair or make the ledger an attr of the account?
open_account(
broker, broker,
'paper', 'paper',
write_on_exit=True, write_on_exit=True,
@ -553,6 +559,7 @@ async def open_trade_dialog(
open_trade_ledger( open_trade_ledger(
broker, broker,
'paper', 'paper',
symcache=symcache,
) as ledger ) as ledger
): ):
# NOTE: retreive market(pair) info from the backend broker # NOTE: retreive market(pair) info from the backend broker
@ -647,7 +654,6 @@ async def open_trade_dialog(
# sanity check all the mkt infos # sanity check all the mkt infos
for fqme, flume in feed.flumes.items(): for fqme, flume in feed.flumes.items():
mkt = mkt_by_fqme[fqme] mkt = mkt_by_fqme[fqme]
print(mkt - flume.mkt)
assert mkt == flume.mkt assert mkt == flume.mkt
async with ( async with (