Fix kraken account-alias config mismatch
Rename `Client._name` -> `Client._key_descr` so the attr actually describes what it holds (the `key_descr` field from `brokers.toml`). In `open_trade_dialog()` look up the account-alias via `conf['accounts']` and raise a `ConfigurationError` with a config-file example when no matching entry exists. Deats, - `api.py`: rename `name` param/attr to `key_descr`, add docstring to `get_client()`, pull `conf['key_descr']` into a named local. - `broker.py`: replace `acc_name` with `fqan` (fully-qualified account name), add accounts dict validation with actionable error msg. - `brokers.toml`: add `src_fiat`, `accounts.spot` entry, and comments explaining the required field relationships. (this commit-msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codefix_kraken_account_alias_mismatch_reporting
parent
4cfe0a9dac
commit
ebc5bbd42b
|
|
@ -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 ------
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue