Compare commits
2 Commits
f210a478c6
...
ebc5bbd42b
| Author | SHA1 | Date |
|---|---|---|
|
|
ebc5bbd42b | |
|
|
4cfe0a9dac |
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,65 @@ async def maybe_spawn_daemon(
|
|||
async with tractor.wait_for_actor(service_name) as portal:
|
||||
lock.release()
|
||||
yield portal
|
||||
await portal.cancel_actor()
|
||||
# --- ---- ---
|
||||
# XXX NOTE XXX
|
||||
# --- ---- ---
|
||||
# DO NOT PUT A `portal.cancel_actor()` here (as was prior)!
|
||||
#
|
||||
# Doing so will cause an "out-of-band" ctxc
|
||||
# (`tractor.ContextCancelled`) to be raised inside the
|
||||
# `ServiceMngr.open_context_in_task()`'s call to
|
||||
# `ctx.wait_for_result()` AND the internal self-ctxc
|
||||
# "graceful capture" WILL NOT CATCH IT!
|
||||
#
|
||||
# This can cause certain types of operations to raise
|
||||
# that ctxc BEFORE THEY `return`, resulting in
|
||||
# a "false-negative" ctxc being raised when really
|
||||
# nothing actually failed, other then our semantic
|
||||
# "failure" to suppress an expected, graceful,
|
||||
# self-cancel scenario..
|
||||
#
|
||||
# bUt wHy duZ It WorK lIKe dis..
|
||||
# ------------------------------
|
||||
# from the perspective of the `tractor.Context` this
|
||||
# cancel request was conducted "out of band" since
|
||||
# `Context.cancel()` was never called and thus the
|
||||
# `._cancel_called: bool` was never set. Despite the
|
||||
# remote `.canceller` being set to `pikerd` (i.e. the
|
||||
# same `Actor.uid` of the raising service-mngr task) the
|
||||
# service-task's ctx itself was never marked as having
|
||||
# requested cancellation and thus still raises the ctxc
|
||||
# bc it was unaware of any such request.
|
||||
#
|
||||
# How to make grokin these cases easier tho?
|
||||
# ------------------------------------------
|
||||
# Because `Portal.cancel_actor()` was called it requests
|
||||
# "full-`Actor`-runtime-cancellation" of it's peer
|
||||
# process which IS NOT THE SAME as a single inter-actor
|
||||
# RPC task cancelling its local context with a remote
|
||||
# peer `Task` in that same peer process.
|
||||
#
|
||||
# ?TODO? It might be better if we do one (or all) of the
|
||||
# following:
|
||||
#
|
||||
# -[ ] at least set a special message for the
|
||||
# `ContextCancelled` when raised locally by the
|
||||
# unaware ctx task such that we check for the
|
||||
# `.canceller` being *our `Actor`* and in the case
|
||||
# where `Context._cancel_called == False` we specially
|
||||
# note that this is likely an "out-of-band"
|
||||
# runtime-cancel request triggered by some call to
|
||||
# `Portal.cancel_actor()`, possibly even reporting the
|
||||
# exact LOC of that caller by tracking it inside our
|
||||
# portal-type?
|
||||
# -[ ] possibly add another field `ContextCancelled` like
|
||||
# maybe a,
|
||||
# `.request_type: Literal['os', 'proc', 'actor',
|
||||
# 'ctx']` type thing which would allow immediately
|
||||
# being able to tell what kind of cancellation caused
|
||||
# the unexpected ctxc?
|
||||
# -[ ] REMOVE THIS COMMENT, once we've settled on how to
|
||||
# better augment `tractor` to be more explicit on this!
|
||||
|
||||
except BaseException as _err:
|
||||
err = _err
|
||||
|
|
|
|||
Loading…
Reference in New Issue