refactor config handling
This commit is contained in:
		| @@ -256,20 +256,26 @@ config = { | ||||
| } | ||||
|  | ||||
|  | ||||
| def set_config(c) -> None: | ||||
| def set_config(conf: dict) -> None: | ||||
|     global config | ||||
|  | ||||
|     if 'logging' in c: | ||||
|         config['env']['logging'] = c['logging'] | ||||
|     # optimization mode only | ||||
|     if jh.is_optimizing(): | ||||
|         # ratio | ||||
|         config['env']['optimization']['ratio'] = conf['ratio'] | ||||
|         # exchange info (only one because the optimize mode supports only one trading route at the moment) | ||||
|         config['env']['optimization']['exchange'] = conf['exchange'] | ||||
|         # warm_up_candles | ||||
|         config['env']['optimization']['warmup_candles_num'] = int(conf['warm_up_candles']) | ||||
|  | ||||
|     if 'warm_up_candles' in c: | ||||
|         config['env']['data']['warmup_candles_num'] = int(c['warm_up_candles']) | ||||
|  | ||||
|     if 'optimization' in c: | ||||
|         config['env']['optimization'] = c['optimization'] | ||||
|  | ||||
|     if 'exchanges' in c: | ||||
|         for key, e in c['exchanges'].items(): | ||||
|     # backtest and live | ||||
|     if jh.is_backtesting() or jh.is_live(): | ||||
|         # warm_up_candles | ||||
|         config['env']['data']['warmup_candles_num'] = int(conf['warm_up_candles']) | ||||
|         # logs | ||||
|         config['env']['logging'] = conf['logging'] | ||||
|         # exchanges | ||||
|         for key, e in conf['exchanges'].items(): | ||||
|             config['env']['exchanges'][e['name']] = { | ||||
|                 'fee': float(e['fee']), | ||||
|                 'type': 'futures', | ||||
| @@ -285,8 +291,9 @@ def set_config(c) -> None: | ||||
|                 ], | ||||
|             } | ||||
|  | ||||
|     if 'notifications' in c: | ||||
|         config['env']['notifications'] = c['notifications'] | ||||
|     # live mode only | ||||
|     if jh.is_live(): | ||||
|         config['env']['notifications'] = conf['notifications'] | ||||
|  | ||||
|     # TODO: must become a config value later when we go after multi account support? | ||||
|     config['env']['identifier'] = 'main' | ||||
|   | ||||
| @@ -117,7 +117,7 @@ class Optimizer(ABC): | ||||
|                             w = Process( | ||||
|                                 target=get_and_add_fitness_to_the_bucket, | ||||
|                                 args=( | ||||
|                                     dna_bucket, router.formatted_routes, router.formatted_extra_routes, | ||||
|                                     dna_bucket, jh.get_config('env.optimization'), router.formatted_routes, router.formatted_extra_routes, | ||||
|                                     self.strategy_hp, dna, self.training_candles, self.testing_candles, | ||||
|                                     self.optimal_total | ||||
|                                 ) | ||||
|   | ||||
| @@ -6,23 +6,23 @@ import traceback | ||||
| import os | ||||
|  | ||||
|  | ||||
| def _formatted_inputs_for_isolated_backtest(): | ||||
|     # TODO: make config dynamically | ||||
| def _formatted_inputs_for_isolated_backtest(user_config, routes): | ||||
|     formatted_config = { | ||||
|         'starting_balance': 5_000, | ||||
|         'fee': 0.001, | ||||
|         'futures_leverage': 3, | ||||
|         'futures_leverage_mode': 'cross', | ||||
|         'exchange': 'Binance', | ||||
|         'settlement_currency': 'USDT', | ||||
|         'warm_up_candles': 100 | ||||
|         'starting_balance': user_config['exchange']['balance'], | ||||
|         'fee': user_config['exchange']['fee'], | ||||
|         'futures_leverage': user_config['exchange']['futures_leverage'], | ||||
|         'futures_leverage_mode': user_config['exchange']['futures_leverage_mode'], | ||||
|         'exchange': routes[0]['exchange'], | ||||
|         'settlement_currency': jh.quote_asset(routes[0]['symbol']), | ||||
|         'warm_up_candles': user_config['warmup_candles_num'] | ||||
|     } | ||||
|  | ||||
|     return formatted_config | ||||
|  | ||||
|  | ||||
| def get_fitness( | ||||
|         routes: list, extra_routes: list, strategy_hp, dna: str, training_candles, testing_candles, optimal_total | ||||
|         optimization_config: dict, routes: list, extra_routes: list, strategy_hp, dna: str, training_candles, | ||||
|         testing_candles, optimal_total | ||||
| ) -> tuple: | ||||
|     """ | ||||
|     Notice that this function is likely to be executed inside workers, hence its inputs must | ||||
| @@ -32,7 +32,7 @@ def get_fitness( | ||||
|  | ||||
|     # run backtest simulation | ||||
|     training_data_metrics = isolated_backtest( | ||||
|         _formatted_inputs_for_isolated_backtest(), | ||||
|         _formatted_inputs_for_isolated_backtest(optimization_config, routes), | ||||
|         routes, | ||||
|         extra_routes, | ||||
|         training_candles, | ||||
| @@ -108,7 +108,8 @@ def get_fitness( | ||||
|  | ||||
|  | ||||
| def get_and_add_fitness_to_the_bucket( | ||||
|         dna_bucket, routes: list, extra_routes: list, strategy_hp, dna, training_candles, testing_candles, optimal_total | ||||
|         dna_bucket, optimization_config, routes: list, extra_routes: list, strategy_hp, dna, training_candles, | ||||
|         testing_candles, optimal_total | ||||
| ) -> None: | ||||
|     """ | ||||
|     Calculates the fitness ands adds the result into the dna_bucket (which is the object passed among workers) | ||||
| @@ -117,7 +118,8 @@ def get_and_add_fitness_to_the_bucket( | ||||
|         # check if the DNA is already in the list | ||||
|         if all(dna_tuple[0] != dna for dna_tuple in dna_bucket): | ||||
|             fitness_score, fitness_log_training, fitness_log_testing = get_fitness( | ||||
|                 routes, extra_routes, strategy_hp, dna, training_candles, testing_candles, optimal_total | ||||
|                 optimization_config, routes, extra_routes, strategy_hp, dna, training_candles, testing_candles, | ||||
|                 optimal_total | ||||
|             ) | ||||
|             dna_bucket.append((dna, fitness_score, fitness_log_training, fitness_log_testing)) | ||||
|         else: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Saleh Mir
					Saleh Mir