removed prints for strategy could not be loaded

changed back to ast, astor is not really needed.
This commit is contained in:
hippocritical 2023-01-02 23:35:51 +01:00
parent 697fad0ac4
commit 71ec32ac9e
2 changed files with 9 additions and 17 deletions

View File

@ -26,17 +26,11 @@ def start_strategy_update(args: Dict[str, Any]) -> None:
filtered_strategy_objs = []
for args_strategy in args['strategy_list']:
found = False
for strategy_obj in strategy_objs:
if strategy_obj['name'] == args_strategy and strategy_obj not in filtered_strategy_objs:
filtered_strategy_objs.append(strategy_obj)
found = True
break
if not found:
print(f"strategy {strategy_obj['name']} could not be loaded or found and is skipped.")
for filtered_strategy_obj in filtered_strategy_objs:
# Initialize backtesting object
instance_strategy_updater = StrategyUpdater()
self.start(config, filtered_strategy_obj)
instance_strategy_updater.start(config, filtered_strategy_obj)

View File

@ -3,8 +3,6 @@ import os
import shutil
from pathlib import Path
import astor
class StrategyUpdater:
name_mapping = {
@ -59,7 +57,7 @@ class StrategyUpdater:
# read the file
with open(source_file, 'r') as f:
old_code = f.read()
if not os.path.exists(strategies_backup_folder):
if not strategies_backup_folder.is_dir():
os.makedirs(strategies_backup_folder)
# backup original
@ -96,7 +94,7 @@ class StrategyUpdater:
ast.increment_lineno(tree, n=1)
# generate the new code from the updated AST
return astor.to_source(tree)
return ast.dump(tree)
# Here we go through each respective node, slice, elt, key ... to replace outdated entries.
@ -187,9 +185,9 @@ class NameUpdater(ast.NodeTransformer):
# if the attribute name is 'nr_of_successful_buys',
# update it to 'nr_of_successful_entries'
if (
isinstance(node.value, ast.Name)
and node.value.id == 'trades'
and node.attr == 'nr_of_successful_buys'
isinstance(node.value, ast.Name)
and node.value.id == 'trades'
and node.attr == 'nr_of_successful_buys'
):
node.attr = 'nr_of_successful_entries'
return self.generic_visit(node)
@ -213,9 +211,9 @@ class NameUpdater(ast.NodeTransformer):
else:
for child in node.body:
if (
isinstance(child, ast.Assign)
and isinstance(child.targets[0], ast.Name)
and child.targets[0].id == 'INTERFACE_VERSION'
isinstance(child, ast.Assign)
and isinstance(child.targets[0], ast.Name)
and child.targets[0].id == 'INTERFACE_VERSION'
):
child.value = ast.parse('3').body[0].value
return self.generic_visit(node)