config refactor

only one get_config method for api class and cryptofeed feed handler
deribit_fix
Nelson Torres 2024-11-15 15:24:08 -03:00
parent 75d1d007fb
commit 6555ccfbba
1 changed files with 14 additions and 26 deletions

View File

@ -186,34 +186,22 @@ def get_config() -> dict[str, Any]:
) )
section: dict = {} section: dict = {}
section = conf.get('deribit') section = conf.get('deribit')
section['log'] = {}
section['log']['filename'] = 'feedhandler.log'
section['log']['level'] = 'DEBUG'
section['log']['disabled'] = True
if section is None: if section is None:
log.warning(f'No config section found for deribit in {path}') log.warning(f'No config section found for deribit in {path}')
return {} return {}
conf_option = section.get('option', {})
section.clear # clear the dict to reuse it
section['deribit'] = {}
section['deribit']['key_id'] = conf_option.get('api_key')
section['deribit']['key_secret'] = conf_option.get('api_secret')
section['log'] = {}
section['log']['filename'] = 'feedhandler.log'
section['log']['level'] = 'DEBUG'
return section return section
def get_fh_config() -> dict[str, Any]:
conf_option = get_config().get('option', {})
conf_log = get_config().get('log', {})
return {
'log': {
'filename': conf_log.get('filename'),
'level': conf_log.get('level'),
'disabled': conf_log.get('disabled')
},
'deribit': {
'key_id': conf_option.get('api_key'),
'key_secret': conf_option.get('api_secret')
}
}
class Client: class Client:
@ -225,10 +213,10 @@ class Client:
) -> None: ) -> None:
self._pairs: ChainMap[str, Pair] = ChainMap() self._pairs: ChainMap[str, Pair] = ChainMap()
config = get_config().get('option', {}) config = get_config().get('deribit', {})
self._key_id = config.get('api_key') self._key_id = config.get('key_id')
self._key_secret = config.get('api_secret') self._key_secret = config.get('key_secret')
self.json_rpc = json_rpc self.json_rpc = json_rpc
@ -567,7 +555,7 @@ async def get_client(
@acm @acm
async def open_feed_handler(): async def open_feed_handler():
fh = FeedHandler(config=get_fh_config()) fh = FeedHandler(config=get_config())
yield fh yield fh
await to_asyncio.run_task(fh.stop_async) await to_asyncio.run_task(fh.stop_async)