From 6555ccfbba46c62d6c9dd72ee984161da52a29c7 Mon Sep 17 00:00:00 2001 From: Nelson Torres Date: Fri, 15 Nov 2024 15:24:08 -0300 Subject: [PATCH] config refactor only one get_config method for api class and cryptofeed feed handler --- piker/brokers/deribit/api.py | 40 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/piker/brokers/deribit/api.py b/piker/brokers/deribit/api.py index 05b025f1..3b19ff59 100644 --- a/piker/brokers/deribit/api.py +++ b/piker/brokers/deribit/api.py @@ -186,34 +186,22 @@ def get_config() -> dict[str, Any]: ) section: dict = {} section = conf.get('deribit') - - section['log'] = {} - section['log']['filename'] = 'feedhandler.log' - section['log']['level'] = 'DEBUG' - section['log']['disabled'] = True - if section is None: log.warning(f'No config section found for deribit in {path}') 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 -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: @@ -225,10 +213,10 @@ class Client: ) -> None: 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_secret = config.get('api_secret') + self._key_id = config.get('key_id') + self._key_secret = config.get('key_secret') self.json_rpc = json_rpc @@ -567,7 +555,7 @@ async def get_client( @acm async def open_feed_handler(): - fh = FeedHandler(config=get_fh_config()) + fh = FeedHandler(config=get_config()) yield fh await to_asyncio.run_task(fh.stop_async)