2018-11-14 11:37:15 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, W0212, too-many-arguments
|
|
|
|
|
|
|
|
"""
|
2018-12-12 19:03:41 +00:00
|
|
|
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-11-05 11:39:19 +00:00
|
|
|
|
2019-06-15 10:20:32 +00:00
|
|
|
from freqtrade import constants
|
2021-09-13 18:00:22 +00:00
|
|
|
from freqtrade.configuration import TimeRange, validate_config_consistency
|
2022-09-18 11:20:36 +00:00
|
|
|
from freqtrade.constants import Config
|
2021-09-07 12:40:53 +00:00
|
|
|
from freqtrade.data.dataprovider import DataProvider
|
2018-11-14 15:49:16 +00:00
|
|
|
from freqtrade.edge import Edge
|
2020-01-09 05:52:34 +00:00
|
|
|
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
|
|
|
"""
|
2018-12-12 19:03:41 +00:00
|
|
|
EdgeCli class, this class contains all the logic to run edge backtesting
|
2018-11-14 11:37:15 +00:00
|
|
|
|
2018-12-12 19:03:41 +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
|
|
|
|
|
2021-09-13 18:00:22 +00:00
|
|
|
# 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)
|
2019-12-23 09:23:48 +00:00
|
|
|
self.strategy = StrategyResolver.load_strategy(self.config)
|
2022-01-15 15:31:16 +00:00
|
|
|
self.strategy.dp = DataProvider(config, self.exchange)
|
2018-11-14 11:37:15 +00:00
|
|
|
|
2019-11-23 14:49:46 +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"))
|
|
|
|
)
|
2022-05-25 18:01:21 +00:00
|
|
|
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"])
|
2019-05-22 11:21:36 +00:00
|
|
|
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)
|