Tweaks on Client init to make api credentials optional
parent
5f60923ac1
commit
5872095b09
|
@ -119,27 +119,30 @@ def get_config() -> dict[str, Any]:
|
||||||
|
|
||||||
section = conf.get('deribit')
|
section = conf.get('deribit')
|
||||||
|
|
||||||
if section is None:
|
|
||||||
log.warning(f'No config section found for deribit in {path}')
|
|
||||||
return {}
|
|
||||||
|
|
||||||
conf['log'] = {}
|
conf['log'] = {}
|
||||||
conf['log']['disabled'] = True
|
conf['log']['disabled'] = True
|
||||||
|
|
||||||
|
if section is None:
|
||||||
|
log.warning(f'No config section found for deribit in {path}')
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
|
||||||
def __init__(self, n: Nursery, ws: NoBsWs) -> None:
|
def __init__(self, n: Nursery, ws: NoBsWs) -> None:
|
||||||
self._sesh = asks.Session(connections=4)
|
|
||||||
self._sesh.base_location = _url
|
|
||||||
self._pairs: dict[str, Any] = {}
|
self._pairs: dict[str, Any] = {}
|
||||||
|
|
||||||
config = get_config()['deribit']
|
config = get_config().get('deribit', {})
|
||||||
|
|
||||||
|
if ('key_id' in config) and ('key_secret' in config):
|
||||||
self._key_id = config['key_id']
|
self._key_id = config['key_id']
|
||||||
self._key_secret = config['key_secret']
|
self._key_secret = config['key_secret']
|
||||||
|
|
||||||
|
else:
|
||||||
|
self._key_id = None
|
||||||
|
self._key_secret = None
|
||||||
|
|
||||||
self._ws = ws
|
self._ws = ws
|
||||||
self._n = n
|
self._n = n
|
||||||
|
|
||||||
|
@ -160,6 +163,8 @@ class Client:
|
||||||
|
|
||||||
async def start_rpc(self):
|
async def start_rpc(self):
|
||||||
self._n.start_soon(self._recv_task)
|
self._n.start_soon(self._recv_task)
|
||||||
|
|
||||||
|
if self._key_id is not None:
|
||||||
await self._n.start(self._auth_loop)
|
await self._n.start(self._auth_loop)
|
||||||
|
|
||||||
async def _recv_task(self):
|
async def _recv_task(self):
|
||||||
|
@ -238,18 +243,6 @@ class Client:
|
||||||
else:
|
else:
|
||||||
await trio.sleep(renew_time / 2)
|
await trio.sleep(renew_time / 2)
|
||||||
|
|
||||||
async def _api(
|
|
||||||
self,
|
|
||||||
method: str,
|
|
||||||
params: dict,
|
|
||||||
) -> dict[str, Any]:
|
|
||||||
resp = await self._sesh.get(
|
|
||||||
path=f'/api/v2/public/{method}',
|
|
||||||
params=params,
|
|
||||||
timeout=float('inf')
|
|
||||||
)
|
|
||||||
return resproc(resp, log)
|
|
||||||
|
|
||||||
async def symbol_info(
|
async def symbol_info(
|
||||||
self,
|
self,
|
||||||
instrument: Optional[str] = None,
|
instrument: Optional[str] = None,
|
||||||
|
|
|
@ -30,3 +30,4 @@ async def trades_dialogue(
|
||||||
get_console_log(loglevel or tractor.current_actor().loglevel)
|
get_console_log(loglevel or tractor.current_actor().loglevel)
|
||||||
|
|
||||||
async with get_client() as client:
|
async with get_client() as client:
|
||||||
|
...
|
||||||
|
|
Loading…
Reference in New Issue