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
|
|
|
"""
|
|
|
|
import logging
|
2019-11-05 11:39:19 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
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
|
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
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, config: Dict[str, Any]) -> None:
|
|
|
|
self.config = config
|
|
|
|
|
2021-09-13 18:00:22 +00:00
|
|
|
# Ensure using dry-run
|
|
|
|
self.config['dry_run'] = True
|
2019-06-15 10:20:32 +00:00
|
|
|
self.config['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
|
2019-12-30 13:28:34 +00:00
|
|
|
self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], 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
|
|
|
|
2019-12-19 18:55:21 +00:00
|
|
|
self.edge._timerange = TimeRange.parse_timerange(None if self.config.get(
|
2018-11-14 16:14:37 +00:00
|
|
|
'timerange') is None else str(self.config.get('timerange')))
|
2022-04-30 06:55:07 +00:00
|
|
|
self.strategy.bot_start()
|
2018-11-14 16:14:37 +00:00
|
|
|
|
2018-11-14 11:37:15 +00:00
|
|
|
def start(self) -> None:
|
2021-03-30 18:20:24 +00:00
|
|
|
result = self.edge.calculate(self.config['exchange']['pair_whitelist'])
|
2019-05-22 11:21:36 +00:00
|
|
|
if result:
|
2019-05-22 11:34:35 +00:00
|
|
|
print('') # blank line for readability
|
2020-01-09 05:52:34 +00:00
|
|
|
print(generate_edge_table(self.edge._cached_pairs))
|