Merge remote-tracking branch 'origin/strategy_utils' into strategy_utils

This commit is contained in:
hippocritical 2023-01-02 20:46:05 +01:00
commit 697fad0ac4
3 changed files with 16 additions and 13 deletions

View File

@ -111,7 +111,8 @@ ARGS_ANALYZE_ENTRIES_EXITS = ["exportfilename", "analysis_groups", "enter_reason
NO_CONF_REQURIED = ["convert-data", "convert-trade-data", "download-data", "list-timeframes", NO_CONF_REQURIED = ["convert-data", "convert-trade-data", "download-data", "list-timeframes",
"list-markets", "list-pairs", "list-strategies", "list-freqaimodels", "list-markets", "list-pairs", "list-strategies", "list-freqaimodels",
"list-data", "hyperopt-list", "hyperopt-show", "backtest-filter", "list-data", "hyperopt-list", "hyperopt-show", "backtest-filter",
"plot-dataframe", "plot-profit", "show-trades", "trades-to-ohlcv"] "plot-dataframe", "plot-profit", "show-trades", "trades-to-ohlcv",
"strategy-updater"]
NO_CONF_ALLOWED = ["create-userdir", "list-exchanges", "new-strategy"] NO_CONF_ALLOWED = ["create-userdir", "list-exchanges", "new-strategy"]

View File

@ -39,4 +39,4 @@ def start_strategy_update(args: Dict[str, Any]) -> None:
for filtered_strategy_obj in filtered_strategy_objs: for filtered_strategy_obj in filtered_strategy_objs:
# Initialize backtesting object # Initialize backtesting object
instance_strategy_updater = StrategyUpdater() instance_strategy_updater = StrategyUpdater()
StrategyUpdater.start(instance_strategy_updater, config, filtered_strategy_obj) self.start(config, filtered_strategy_obj)

View File

@ -81,7 +81,7 @@ class StrategyUpdater:
tree = ast.parse(code) tree = ast.parse(code)
# use the AST to update the code # use the AST to update the code
updated_code = self.modify_ast(self, tree) updated_code = self.modify_ast(tree)
# return the modified code without executing it # return the modified code without executing it
return updated_code return updated_code
@ -186,9 +186,11 @@ class NameUpdater(ast.NodeTransformer):
def visit_Attribute(self, node): def visit_Attribute(self, node):
# if the attribute name is 'nr_of_successful_buys', # if the attribute name is 'nr_of_successful_buys',
# update it to 'nr_of_successful_entries' # update it to 'nr_of_successful_entries'
if isinstance(node.value, ast.Name) and \ if (
node.value.id == 'trades' and \ isinstance(node.value, ast.Name)
node.attr == 'nr_of_successful_buys': and node.value.id == 'trades'
and node.attr == 'nr_of_successful_buys'
):
node.attr = 'nr_of_successful_entries' node.attr = 'nr_of_successful_entries'
return self.generic_visit(node) return self.generic_visit(node)
@ -210,9 +212,11 @@ class NameUpdater(ast.NodeTransformer):
# otherwise, update its value to 3 # otherwise, update its value to 3
else: else:
for child in node.body: for child in node.body:
if isinstance(child, ast.Assign) and \ if (
isinstance(child.targets[0], ast.Name) and \ isinstance(child, ast.Assign)
child.targets[0].id == 'INTERFACE_VERSION': and isinstance(child.targets[0], ast.Name)
and child.targets[0].id == 'INTERFACE_VERSION'
):
child.value = ast.parse('3').body[0].value child.value = ast.parse('3').body[0].value
return self.generic_visit(node) return self.generic_visit(node)
@ -255,8 +259,6 @@ class NameUpdater(ast.NodeTransformer):
def visit_Constant(self, node): def visit_Constant(self, node):
# do not update the names in import statements # do not update the names in import statements
if node.value in \ if node.value in StrategyUpdater.otif_ot_unfilledtimeout:
StrategyUpdater.otif_ot_unfilledtimeout: node.value = StrategyUpdater.otif_ot_unfilledtimeout[node.value]
node.value = \
StrategyUpdater.otif_ot_unfilledtimeout[node.value]
return node return node