2022-12-27 19:14:39 +00:00
|
|
|
import logging
|
2023-03-10 07:59:07 +00:00
|
|
|
import sys
|
2023-01-05 21:56:06 +00:00
|
|
|
import time
|
2023-03-05 15:19:26 +00:00
|
|
|
from pathlib import Path
|
2022-12-27 19:14:39 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
|
|
|
from freqtrade.configuration import setup_utils_configuration
|
|
|
|
from freqtrade.enums import RunMode
|
|
|
|
from freqtrade.resolvers import StrategyResolver
|
2023-02-17 20:01:09 +00:00
|
|
|
from freqtrade.strategy.strategyupdater import StrategyUpdater
|
2022-12-27 19:14:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def start_strategy_update(args: Dict[str, Any]) -> None:
|
|
|
|
"""
|
|
|
|
Start the strategy updating script
|
|
|
|
:param args: Cli args from Arguments()
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
2023-03-10 08:23:56 +00:00
|
|
|
if sys.version_info == (3, 8): # pragma: no cover
|
|
|
|
sys.exit("Freqtrade strategy updater requires Python version >= 3.9")
|
2022-12-27 19:14:39 +00:00
|
|
|
|
2023-03-10 08:23:56 +00:00
|
|
|
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
|
|
|
|
|
|
|
strategy_objs = StrategyResolver.search_all_objects(
|
2024-05-12 14:27:03 +00:00
|
|
|
config, enum_failed=False, recursive=config.get("recursive_strategy_search", False)
|
|
|
|
)
|
2023-03-10 08:23:56 +00:00
|
|
|
|
|
|
|
filtered_strategy_objs = []
|
2024-05-12 14:27:03 +00:00
|
|
|
if args["strategy_list"]:
|
2023-03-12 14:47:03 +00:00
|
|
|
filtered_strategy_objs = [
|
2024-05-12 14:27:03 +00:00
|
|
|
strategy_obj
|
|
|
|
for strategy_obj in strategy_objs
|
|
|
|
if strategy_obj["name"] in args["strategy_list"]
|
2023-03-12 14:47:03 +00:00
|
|
|
]
|
|
|
|
|
2023-03-10 08:23:56 +00:00
|
|
|
else:
|
2023-03-12 14:47:03 +00:00
|
|
|
# Use all available entries.
|
|
|
|
filtered_strategy_objs = strategy_objs
|
|
|
|
|
|
|
|
processed_locations = set()
|
|
|
|
for strategy_obj in filtered_strategy_objs:
|
2024-05-12 14:27:03 +00:00
|
|
|
if strategy_obj["location"] not in processed_locations:
|
|
|
|
processed_locations.add(strategy_obj["location"])
|
2023-03-12 14:47:03 +00:00
|
|
|
start_conversion(strategy_obj, config)
|
2023-02-17 20:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def start_conversion(strategy_obj, config):
|
2023-03-05 15:19:26 +00:00
|
|
|
print(f"Conversion of {Path(strategy_obj['location']).name} started.")
|
2023-02-17 20:01:09 +00:00
|
|
|
instance_strategy_updater = StrategyUpdater()
|
|
|
|
start = time.perf_counter()
|
|
|
|
instance_strategy_updater.start(config, strategy_obj)
|
|
|
|
elapsed = time.perf_counter() - start
|
2023-03-05 15:19:26 +00:00
|
|
|
print(f"Conversion of {Path(strategy_obj['location']).name} took {elapsed:.1f} seconds.")
|