Convert accounts table to `bidict` after config load
parent
050aa7594c
commit
725909a94c
|
@ -38,6 +38,7 @@ import time
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
|
||||||
|
from bidict import bidict
|
||||||
import trio
|
import trio
|
||||||
import tractor
|
import tractor
|
||||||
from tractor import to_asyncio
|
from tractor import to_asyncio
|
||||||
|
@ -261,12 +262,11 @@ class Client:
|
||||||
|
|
||||||
# NOTE: the ib.client here is "throttled" to 45 rps by default
|
# NOTE: the ib.client here is "throttled" to 45 rps by default
|
||||||
|
|
||||||
async def trades(
|
async def trades(self) -> dict[str, Any]:
|
||||||
self,
|
'''
|
||||||
# api_only: bool = False,
|
Return list of trades from current session in ``dict``.
|
||||||
|
|
||||||
) -> dict[str, Any]:
|
|
||||||
|
|
||||||
|
'''
|
||||||
# orders = await self.ib.reqCompletedOrdersAsync(
|
# orders = await self.ib.reqCompletedOrdersAsync(
|
||||||
# apiOnly=api_only
|
# apiOnly=api_only
|
||||||
# )
|
# )
|
||||||
|
@ -811,10 +811,23 @@ _scan_ignore: set[tuple[str, int]] = set()
|
||||||
|
|
||||||
def get_config() -> dict[str, Any]:
|
def get_config() -> dict[str, Any]:
|
||||||
|
|
||||||
conf, path = config.load()
|
conf, path = config.load('brokers')
|
||||||
|
|
||||||
section = conf.get('ib')
|
section = conf.get('ib')
|
||||||
|
|
||||||
|
accounts = section.get('accounts')
|
||||||
|
if not accounts:
|
||||||
|
raise ValueError(
|
||||||
|
'brokers.toml -> `ib.accounts` must be defined\n'
|
||||||
|
f'location: {path}'
|
||||||
|
)
|
||||||
|
|
||||||
|
names = list(accounts.keys())
|
||||||
|
accts = section['accounts'] = bidict(accounts)
|
||||||
|
log.info(
|
||||||
|
f'brokers.toml defines {len(accts)} accounts: '
|
||||||
|
f'{pformat(names)}'
|
||||||
|
)
|
||||||
|
|
||||||
if section is None:
|
if section is None:
|
||||||
log.warning(f'No config section found for ib in {path}')
|
log.warning(f'No config section found for ib in {path}')
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Reference in New Issue