Tweaks on Client init to make api credentials optional

size_in_shm_token
Guillermo Rodriguez 2022-08-22 10:39:30 -03:00
parent 92090b01b8
commit 212b3d620d
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
1 changed files with 15 additions and 22 deletions

View File

@ -119,26 +119,29 @@ 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', {})
self._key_id = config['key_id']
self._key_secret = config['key_secret'] if ('key_id' in config) and ('key_secret' in config):
self._key_id = config['key_id']
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,7 +163,9 @@ 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)
await self._n.start(self._auth_loop)
if self._key_id is not None:
await self._n.start(self._auth_loop)
async def _recv_task(self): async def _recv_task(self):
while True: while True:
@ -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,