freqtrade_origin/freqtrade/optimize/edge_cli.py

51 lines
1.6 KiB
Python
Raw 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
"""
import logging
from typing import Any, Dict
2019-06-15 10:20:32 +00:00
from freqtrade import constants
2020-09-28 17:39:41 +00:00
from freqtrade.configuration import TimeRange, remove_credentials, validate_config_consistency
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
"""
def __init__(self, config: Dict[str, Any]) -> None:
self.config = config
# Reset keys for edge
remove_credentials(self.config)
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)
self.strategy = StrategyResolver.load_strategy(self.config)
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
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')))
2018-11-14 11:37:15 +00:00
def start(self) -> None:
result = self.edge.calculate()
if result:
2019-05-22 11:34:35 +00:00
print('') # blank line for readability
print(generate_edge_table(self.edge._cached_pairs))