diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index f4959db3b..79bc769e6 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -482,7 +482,6 @@ class Exchange: def reload_markets(self) -> None: """Reload markets both sync and async if refresh interval has passed """ - asyncio.set_event_loop(self.loop) # Check whether markets have to be reloaded if (self._last_markets_refresh > 0) and ( self._last_markets_refresh + self.markets_refresh_interval diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index be9284c92..6735df02b 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -17,9 +17,9 @@ from sklearn.model_selection import train_test_split from sklearn.neighbors import NearestNeighbors from freqtrade.configuration import TimeRange +from freqtrade.data.dataprovider import DataProvider from freqtrade.data.history.history_utils import refresh_backtest_ohlcv_data from freqtrade.exceptions import OperationalException -from freqtrade.resolvers import ExchangeResolver from freqtrade.strategy.interface import IStrategy @@ -895,22 +895,20 @@ class FreqaiDataKitchen: self.model_filename = f"cb_{coin.lower()}_{int(trained_timerange.stopts)}" - def download_all_data_for_training(self, timerange: TimeRange) -> None: + def download_all_data_for_training(self, timerange: TimeRange, dp: DataProvider) -> None: """ Called only once upon start of bot to download the necessary data for populating indicators and training the model. - :params: - timerange: TimeRange = The full data timerange for populating the indicators - and training the model. + :param timerange: TimeRange = The full data timerange for populating the indicators + and training the model. + :param dp: DataProvider instance attached to the strategy """ - exchange = ExchangeResolver.load_exchange( - self.config["exchange"]["name"], self.config, validate=False, load_leverage_tiers=False - ) - new_pairs_days = int((timerange.stopts - timerange.startts) / SECONDS_IN_DAY) - + if not dp._exchange: + # Not realistic - this is only called in live mode. + raise OperationalException("Dataprovider did not have an exchange attached.") refresh_backtest_ohlcv_data( - exchange, + dp._exchange, pairs=self.all_pairs, timeframes=self.freqai_config["feature_parameters"].get("include_timeframes"), datadir=self.config["datadir"], @@ -922,8 +920,6 @@ class FreqaiDataKitchen: prepend=self.config.get("prepend_data", False), ) - exchange.close() - def set_all_pairs(self) -> None: self.all_pairs = copy.deepcopy( diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index 097ecf553..833fb50d6 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -273,7 +273,7 @@ class IFreqaiModel(ABC): "corr_pairlist, this may take a while if you do not have the " "data saved" ) - dk.download_all_data_for_training(data_load_timerange) + dk.download_all_data_for_training(data_load_timerange, strategy.dp) self.dd.load_all_pair_histories(data_load_timerange, dk) if not self.scanning: diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index ec69a41c1..a36f80280 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -16,6 +16,7 @@ def is_arm() -> bool: machine = platform.machine() return "arm" in machine or "aarch64" in machine + def test_train_model_in_series_LightGBM(mocker, freqai_conf): freqai_conf.update({"timerange": "20180110-20180130"})