From d8ec46c6d4e8e608bcb56c53feab5683a8dd88f9 Mon Sep 17 00:00:00 2001 From: marcvanduyn Date: Tue, 2 Jul 2024 17:15:11 +0200 Subject: [PATCH] Add window size check to ccxt data source --- .../models/market_data_sources/ccxt.py | 11 +++++++ .../models/market_data_sources/csv.py | 33 +++++++++++-------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py b/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py index 8d004a83..fd781e48 100644 --- a/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +++ b/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py @@ -438,6 +438,9 @@ def get_data(self, **kwargs): if self.config is not None: market_service.config = self.config + if "window_size" in kwargs: + self.window_size = kwargs["window_size"] + if "start_date" in kwargs: start_date = kwargs["start_date"] @@ -451,6 +454,14 @@ def get_data(self, **kwargs): ) if "end_date" not in kwargs: + + if self.window_size is None: + raise OperationalException( + "Either end_date or window_size " + "should be passed as a " + "parameter for CCXTOHLCVMarketDataSource" + ) + end_date = self.create_end_date( start_date, self.timeframe, self.window_size ) diff --git a/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py b/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py index 0aaac06c..b8e0d11c 100644 --- a/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +++ b/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py @@ -88,6 +88,9 @@ def get_data(self, **kwargs): end_date = kwargs.get("end_date") backtest_index_date = kwargs.get("backtest_index_date") + if "window_size" in kwargs: + self.window_size = kwargs["window_size"] + if start_date is None \ and end_date is None \ and backtest_index_date is None: @@ -97,11 +100,27 @@ def get_data(self, **kwargs): if backtest_index_date is not None: end_date = backtest_index_date + + if self.window_size is None: + raise OperationalException( + "Either end_date or window_size " + "should be passed as a " + "parameter for CCXTOHLCVMarketDataSource" + ) + start_date = self.create_start_date( end_date, self.timeframe, self.window_size ) else: if start_date is None: + + if self.window_size is None: + raise OperationalException( + "Either end_date or window_size " + "should be passed as a " + "parameter for CCXTOHLCVMarketDataSource" + ) + start_date = self.create_start_date( end_date, self.timeframe, self.window_size ) @@ -111,20 +130,6 @@ def get_data(self, **kwargs): start_date, self.timeframe, self.window_size ) - # # Check if start or end date are out of range with - # # the dates of the datasource. - # if self._start_date_data_source > start_date: - # raise OperationalException( - # f"Given start date {start_date} is before the start date " - # f"of the data source {self._start_date_data_source}" - # ) - # - # if self._end_date_data_source < end_date: - # raise OperationalException( - # f"End date {end_date} is after the end date " - # f"of the data source {self._end_date_data_source}" - # ) - df = polars.read_csv( self.csv_file_path, columns=self._columns, separator="," )