diff --git a/config/brokers.toml b/config/brokers.toml index 098a940c..a59ce36f 100644 --- a/config/brokers.toml +++ b/config/brokers.toml @@ -32,7 +32,14 @@ option.log.disabled = true [kraken] -key_descr = '' +# the reference fiat asset as can be set +# in an account's web-trading-UI prefs. +src_fiat = 'usd' + +# NOTE for account defs, the following +# lines must match as follows. +accounts.spot = 'spot' +key_descr = 'spot' api_key = '' secret = '' # ------ kraken ------ diff --git a/piker/brokers/kraken/api.py b/piker/brokers/kraken/api.py index 92297393..654f0718 100644 --- a/piker/brokers/kraken/api.py +++ b/piker/brokers/kraken/api.py @@ -147,17 +147,14 @@ class Client: config: dict[str, str], httpx_client: httpx.AsyncClient, - name: str = '', + key_descr: str = '', api_key: str = '', secret: str = '' ) -> None: - self._sesh: httpx.AsyncClient = httpx_client - - self._name = name + self._key_descr = key_descr self._api_key = api_key self._secret = secret - self.conf: dict[str, str] = config @property @@ -681,7 +678,13 @@ class Client: @acm async def get_client() -> Client: + ''' + Load and deliver a `.kraken.api.Client`. + When defined, inject any config delivered from the user's + `brokers.toml` config file. + + ''' conf: dict[str, Any] = get_config() async with httpx.AsyncClient( base_url=_url, @@ -692,13 +695,14 @@ async def get_client() -> Client: # connections=4 ) as trio_client: if conf: + api_key_descr: str = conf['key_descr'] client = Client( conf, httpx_client=trio_client, # TODO: don't break these up and just do internal # conf lookups instead.. - name=conf['key_descr'], + key_descr=api_key_descr, api_key=conf['api_key'], secret=conf['secret'] ) diff --git a/piker/brokers/kraken/broker.py b/piker/brokers/kraken/broker.py index 027b92b7..0717612b 100644 --- a/piker/brokers/kraken/broker.py +++ b/piker/brokers/kraken/broker.py @@ -133,7 +133,6 @@ class BrokerClient: async def handle_order_requests( - ws: NoBsWs, client: Client, ems_order_stream: tractor.MsgStream, @@ -475,8 +474,20 @@ async def open_trade_dialog( ) # auth required block - acctid = client._name - acc_name = 'kraken.' + acctid + conf: dict = client.conf + accounts: dict = conf.get('accounts') + acctid: str = client._key_descr + if not accounts.get(acctid): + raise ConfigurationError( + f'No API-key found for account-alias defined as {acctid!r} !\n' + f'\n' + f'Did set a `kraken.accounts.*` entry in your `brokers.toml`?\n' + f'It should look something like,\n' + f'\n' + f'[kraken]\n' + f'accounts.{acctid} = {acctid!r}\n' + ) + fqan: str = f'kraken.{acctid}' # task local msg dialog tracking apiflows = OrderDialogs() @@ -595,7 +606,10 @@ async def open_trade_dialog( acctid, ) # sync with EMS delivering pps and accounts - await ctx.started((ppmsgs, [acc_name])) + await ctx.started(( + ppmsgs, + [fqan], + )) # TODO: ideally this blocks the this task # as little as possible. we need to either do @@ -649,7 +663,7 @@ async def open_trade_dialog( acnt=acnt, ledger=ledger, acctid=acctid, - acc_name=acc_name, + acc_name=fqan, token=token, )