Complain when kwargs are missing but required
parent
1b93a4c02a
commit
66441d15e8
|
@ -20,7 +20,7 @@ def run(main, loglevel='info'):
|
|||
except Exception as err:
|
||||
log.exception(err)
|
||||
finally:
|
||||
log.debug("Exiting pikerd")
|
||||
log.debug("Exiting piker")
|
||||
|
||||
|
||||
@click.command()
|
||||
|
@ -41,9 +41,9 @@ def cli():
|
|||
@click.option('--broker', default='questrade', help='Broker backend to use')
|
||||
@click.option('--loglevel', '-l', default='warning', help='Logging level')
|
||||
@click.argument('meth', nargs=1)
|
||||
@click.argument('kwargs', nargs=-1, required=True)
|
||||
@click.argument('kwargs', nargs=-1)
|
||||
def api(meth, kwargs, loglevel, broker):
|
||||
"""Client for testing broker API methods with pretty printing of output.
|
||||
"""client for testing broker API methods with pretty printing of output.
|
||||
"""
|
||||
log = get_console_log(loglevel)
|
||||
brokermod = import_module('.' + broker, 'piker.brokers')
|
||||
|
|
|
@ -16,7 +16,6 @@ def load() -> (configparser.ConfigParser, str):
|
|||
Create a ``broker.ini`` file if one dne.
|
||||
"""
|
||||
config = configparser.ConfigParser()
|
||||
# mode = 'r' if path.exists(_broker_conf_path) else 'a'
|
||||
read = config.read(_broker_conf_path)
|
||||
log.debug(f"Read config file {_broker_conf_path}")
|
||||
return config, _broker_conf_path
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""
|
||||
Questrade API backend.
|
||||
"""
|
||||
import inspect
|
||||
import json
|
||||
import time
|
||||
import datetime
|
||||
|
@ -47,7 +48,8 @@ def resproc(
|
|||
|
||||
|
||||
class Client:
|
||||
"""API client suitable for use as a long running broker daemon.
|
||||
"""API client suitable for use as a long running broker daemon or
|
||||
for single api requests.
|
||||
"""
|
||||
def __init__(self, config: 'configparser.ConfigParser'):
|
||||
self._sess = asks.Session()
|
||||
|
@ -243,13 +245,20 @@ async def serve_forever() -> None:
|
|||
|
||||
|
||||
async def api(methname, **kwargs) -> dict:
|
||||
"""Make (proxy) through an api call by name and return its result.
|
||||
"""
|
||||
async with get_client() as client:
|
||||
meth = getattr(client.api, methname, None)
|
||||
if meth is None:
|
||||
log.error(f"No api method `{methname}` could be found?")
|
||||
else:
|
||||
arg = kwargs.get('arg')
|
||||
if arg:
|
||||
return await meth(arg)
|
||||
else:
|
||||
return await meth(**kwargs)
|
||||
return
|
||||
elif not kwargs:
|
||||
# verify kwargs requirements are met
|
||||
sig = inspect.signature(meth)
|
||||
if sig.parameters:
|
||||
log.error(
|
||||
f"Argument(s) are required by the `{methname}` method: "
|
||||
f"{tuple(sig.parameters.keys())}")
|
||||
return
|
||||
|
||||
return await meth(**kwargs)
|
||||
|
|
Loading…
Reference in New Issue