removed prints for strategy could not be loaded

Changed logic to contain much less if conditions

currently still missing:
Webhook terminology, Telegram notification settings, Strategy/Config settings
This commit is contained in:
hippocritical 2023-01-05 22:56:06 +01:00
parent ed55296d20
commit 4435c4fd0d
3 changed files with 18 additions and 13 deletions

View File

@ -1,4 +1,5 @@
import logging
import time
from typing import Any, Dict
from freqtrade.configuration import setup_utils_configuration
@ -33,4 +34,7 @@ def start_strategy_update(args: Dict[str, Any]) -> None:
for filtered_strategy_obj in filtered_strategy_objs:
instance_strategy_updater = StrategyUpdater()
start = time.perf_counter()
instance_strategy_updater.start(config, filtered_strategy_obj)
elapsed = time.perf_counter() - start
print(f"Conversion of {filtered_strategy_obj['name']} took {elapsed:.1f} seconds.")

View File

@ -52,7 +52,6 @@ class StrategyUpdater:
"""
source_file = strategy_obj['location']
print(f"started conversion of {source_file}")
strategies_backup_folder = Path.joinpath(config['user_data_dir'], "strategies_orig_updater")
target_file = Path.joinpath(strategies_backup_folder, strategy_obj['location_rel'])
@ -73,7 +72,6 @@ class StrategyUpdater:
# write the modified code to the destination folder
with open(source_file, 'w') as f:
f.write(new_code)
print(f"conversion of file {source_file} successful.")
# define the function to update the code
def update_code(self, code):
@ -81,7 +79,7 @@ class StrategyUpdater:
tree = ast.parse(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 updated_code
@ -96,6 +94,7 @@ class StrategyUpdater:
ast.increment_lineno(tree, n=1)
# generate the new code from the updated AST
# without indent {} parameters would just be written straight one after the other.
return astor.to_source(tree)
@ -131,8 +130,9 @@ class NameUpdater(ast.NodeTransformer):
return node
def visit_Expr(self, node):
node.value.left.id = self.check_dict(StrategyUpdater.name_mapping, node.value.left.id)
self.visit(node.value)
if hasattr(node.value, "left") and hasattr(node.value.left, "id"):
node.value.left.id = self.check_dict(StrategyUpdater.name_mapping, node.value.left.id)
self.visit(node.value)
return node
# Renames an element if contained inside a dictionary.

View File

@ -4,7 +4,8 @@ from freqtrade.strategy.strategyupdater import StrategyUpdater
def test_strategy_updater(default_conf, caplog) -> None:
modified_code1 = StrategyUpdater.update_code(StrategyUpdater, """
instance_strategy_updater = StrategyUpdater()
modified_code1 = instance_strategy_updater.update_code("""
class testClass(IStrategy):
def populate_buy_trend():
pass
@ -17,27 +18,27 @@ class testClass(IStrategy):
def custom_sell():
pass
""")
modified_code2 = StrategyUpdater.update_code(StrategyUpdater, """
modified_code2 = instance_strategy_updater.update_code("""
ticker_interval = '15m'
buy_some_parameter = IntParameter(space='buy')
sell_some_parameter = IntParameter(space='sell')
""")
modified_code3 = StrategyUpdater.update_code(StrategyUpdater, """
modified_code3 = instance_strategy_updater.update_code("""
use_sell_signal = True
sell_profit_only = True
sell_profit_offset = True
ignore_roi_if_buy_signal = True
forcebuy_enable = True
""")
modified_code4 = StrategyUpdater.update_code(StrategyUpdater, """
modified_code4 = instance_strategy_updater.update_code("""
dataframe.loc[reduce(lambda x, y: x & y, conditions), ["buy", "buy_tag"]] = (1, "buy_signal_1")
dataframe.loc[reduce(lambda x, y: x & y, conditions), 'sell'] = 1
""")
modified_code5 = StrategyUpdater.update_code(StrategyUpdater, """
modified_code5 = instance_strategy_updater.update_code("""
def confirm_trade_exit(sell_reason: str):
pass
""")
modified_code6 = StrategyUpdater.update_code(StrategyUpdater, """
modified_code6 = instance_strategy_updater.update_code("""
order_time_in_force = {
'buy': 'gtc',
'sell': 'ioc'
@ -54,12 +55,12 @@ unfilledtimeout = {
}
""")
modified_code7 = StrategyUpdater.update_code(StrategyUpdater, """
modified_code7 = instance_strategy_updater.update_code("""
def confirm_trade_exit(sell_reason):
if (sell_reason == 'stop_loss'):
pass
""")
modified_code8 = StrategyUpdater.update_code(StrategyUpdater, """
modified_code8 = instance_strategy_updater.update_code("""
sell_reason == 'sell_signal'
sell_reason == 'force_sell'
sell_reason == 'emergency_sell'