freqtrade_origin/freqtrade/optimize/edge_cli.py

56 lines
1.8 KiB
Python
Raw Permalink Normal View History

2018-11-14 11:37:15 +00:00
# pragma pylint: disable=missing-docstring, W0212, too-many-arguments
"""
This module contains the edge backtesting interface
2018-11-14 11:37:15 +00:00
"""
2024-05-12 15:20:36 +00:00
2018-11-14 11:37:15 +00:00
import logging
2019-06-15 10:20:32 +00:00
from freqtrade import constants
from freqtrade.configuration import TimeRange, validate_config_consistency
2022-09-18 11:20:36 +00:00
from freqtrade.constants import Config
from freqtrade.data.dataprovider import DataProvider
from freqtrade.edge import Edge
from freqtrade.optimize.optimize_reports import generate_edge_table
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
2018-11-14 11:37:15 +00:00
2020-09-28 17:39:41 +00:00
2018-11-14 11:37:15 +00:00
logger = logging.getLogger(__name__)
2019-09-12 01:39:52 +00:00
class EdgeCli:
2018-11-14 11:37:15 +00:00
"""
EdgeCli class, this class contains all the logic to run edge backtesting
2018-11-14 11:37:15 +00:00
To run a edge backtest:
edge = EdgeCli(config)
edge.start()
2018-11-14 11:37:15 +00:00
"""
2022-09-18 11:20:36 +00:00
def __init__(self, config: Config) -> None:
2018-11-14 11:37:15 +00:00
self.config = config
# Ensure using dry-run
2024-05-12 15:20:36 +00:00
self.config["dry_run"] = True
self.config["stake_amount"] = constants.UNLIMITED_STAKE_AMOUNT
2023-05-13 06:27:27 +00:00
self.exchange = ExchangeResolver.load_exchange(self.config)
self.strategy = StrategyResolver.load_strategy(self.config)
self.strategy.dp = DataProvider(config, self.exchange)
2018-11-14 11:37:15 +00:00
validate_config_consistency(self.config)
2018-11-14 11:37:15 +00:00
self.edge = Edge(config, self.exchange, self.strategy)
2019-09-20 18:22:51 +00:00
# Set refresh_pairs to false for edge-cli (it must be true for edge)
2019-09-20 18:02:07 +00:00
self.edge._refresh_pairs = False
2018-11-14 11:37:15 +00:00
2024-05-12 15:20:36 +00:00
self.edge._timerange = TimeRange.parse_timerange(
None if self.config.get("timerange") is None else str(self.config.get("timerange"))
)
self.strategy.ft_bot_start()
2018-11-14 16:14:37 +00:00
2018-11-14 11:37:15 +00:00
def start(self) -> None:
2024-05-12 15:20:36 +00:00
result = self.edge.calculate(self.config["exchange"]["pair_whitelist"])
if result:
2024-05-12 15:20:36 +00:00
print("") # blank line for readability
2024-07-09 05:08:10 +00:00
generate_edge_table(self.edge._cached_pairs)