Merge pull request #4869 from freqtrade/edge_informative

Have Edge support informative pairs
This commit is contained in:
Matthias 2021-05-05 20:10:40 +02:00 committed by GitHub
commit d8de871934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 4 deletions

View File

@ -1,6 +1,8 @@
# pragma pylint: disable=W0603 # pragma pylint: disable=W0603
""" Edge positioning package """ """ Edge positioning package """
import logging import logging
from collections import defaultdict
from copy import deepcopy
from typing import Any, Dict, List, NamedTuple from typing import Any, Dict, List, NamedTuple
import arrow import arrow
@ -12,8 +14,10 @@ from freqtrade.configuration import TimeRange
from freqtrade.constants import DATETIME_PRINT_FORMAT, UNLIMITED_STAKE_AMOUNT from freqtrade.constants import DATETIME_PRINT_FORMAT, UNLIMITED_STAKE_AMOUNT
from freqtrade.data.history import get_timerange, load_data, refresh_data from freqtrade.data.history import get_timerange, load_data, refresh_data
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.exchange.exchange import timeframe_to_seconds
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.strategy.interface import SellType from freqtrade.state import RunMode
from freqtrade.strategy.interface import IStrategy, SellType
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -45,7 +49,7 @@ class Edge:
self.config = config self.config = config
self.exchange = exchange self.exchange = exchange
self.strategy = strategy self.strategy: IStrategy = strategy
self.edge_config = self.config.get('edge', {}) self.edge_config = self.config.get('edge', {})
self._cached_pairs: Dict[str, Any] = {} # Keeps a list of pairs self._cached_pairs: Dict[str, Any] = {} # Keeps a list of pairs
@ -102,14 +106,33 @@ class Edge:
logger.info('Using local backtesting data (using whitelist in given config) ...') logger.info('Using local backtesting data (using whitelist in given config) ...')
if self._refresh_pairs: if self._refresh_pairs:
timerange_startup = deepcopy(self._timerange)
timerange_startup.subtract_start(timeframe_to_seconds(
self.strategy.timeframe) * self.strategy.startup_candle_count)
refresh_data( refresh_data(
datadir=self.config['datadir'], datadir=self.config['datadir'],
pairs=pairs, pairs=pairs,
exchange=self.exchange, exchange=self.exchange,
timeframe=self.strategy.timeframe, timeframe=self.strategy.timeframe,
timerange=self._timerange, timerange=timerange_startup,
data_format=self.config.get('dataformat_ohlcv', 'json'), data_format=self.config.get('dataformat_ohlcv', 'json'),
) )
# Download informative pairs too
res = defaultdict(list)
for p, t in self.strategy.informative_pairs():
res[t].append(p)
for timeframe, inf_pairs in res.items():
timerange_startup = deepcopy(self._timerange)
timerange_startup.subtract_start(timeframe_to_seconds(
timeframe) * self.strategy.startup_candle_count)
refresh_data(
datadir=self.config['datadir'],
pairs=inf_pairs,
exchange=self.exchange,
timeframe=timeframe,
timerange=timerange_startup,
data_format=self.config.get('dataformat_ohlcv', 'json'),
)
data = load_data( data = load_data(
datadir=self.config['datadir'], datadir=self.config['datadir'],
@ -125,8 +148,11 @@ class Edge:
self._cached_pairs = {} self._cached_pairs = {}
logger.critical("No data found. Edge is stopped ...") logger.critical("No data found. Edge is stopped ...")
return False return False
# Fake run-mode to Edge
prior_rm = self.config['runmode']
self.config['runmode'] = RunMode.EDGE
preprocessed = self.strategy.ohlcvdata_to_dataframe(data) preprocessed = self.strategy.ohlcvdata_to_dataframe(data)
self.config['runmode'] = prior_rm
# Print timeframe # Print timeframe
min_date, max_date = get_timerange(preprocessed) min_date, max_date = get_timerange(preprocessed)

View File

@ -21,6 +21,7 @@ from freqtrade.exchange import Exchange
from freqtrade.freqtradebot import FreqtradeBot from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.persistence import LocalTrade, Trade, init_db from freqtrade.persistence import LocalTrade, Trade, init_db
from freqtrade.resolvers import ExchangeResolver from freqtrade.resolvers import ExchangeResolver
from freqtrade.state import RunMode
from freqtrade.worker import Worker from freqtrade.worker import Worker
from tests.conftest_trades import (mock_trade_1, mock_trade_2, mock_trade_3, mock_trade_4, from tests.conftest_trades import (mock_trade_1, mock_trade_2, mock_trade_3, mock_trade_4,
mock_trade_5, mock_trade_6) mock_trade_5, mock_trade_6)
@ -1677,6 +1678,7 @@ def buy_order_fee():
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def edge_conf(default_conf): def edge_conf(default_conf):
conf = deepcopy(default_conf) conf = deepcopy(default_conf)
conf['runmode'] = RunMode.DRY_RUN
conf['max_open_trades'] = -1 conf['max_open_trades'] = -1
conf['tradable_balance_ratio'] = 0.5 conf['tradable_balance_ratio'] = 0.5
conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT

View File

@ -344,6 +344,8 @@ def test_edge_process_no_trades(mocker, edge_conf, caplog):
def test_edge_process_no_pairs(mocker, edge_conf, caplog): def test_edge_process_no_pairs(mocker, edge_conf, caplog):
edge_conf['exchange']['pair_whitelist'] = [] edge_conf['exchange']['pair_whitelist'] = []
mocker.patch('freqtrade.freqtradebot.validate_config_consistency')
freqtrade = get_patched_freqtradebot(mocker, edge_conf) freqtrade = get_patched_freqtradebot(mocker, edge_conf)
fee_mock = mocker.patch('freqtrade.exchange.Exchange.get_fee', return_value=0.001) fee_mock = mocker.patch('freqtrade.exchange.Exchange.get_fee', return_value=0.001)
mocker.patch('freqtrade.edge.edge_positioning.refresh_data') mocker.patch('freqtrade.edge.edge_positioning.refresh_data')