Skip to content

Commit d8ec46c

Browse files
committed
Add window size check to ccxt data source
1 parent 662e92b commit d8ec46c

File tree

2 files changed

+30
-14
lines changed
  • investing_algorithm_framework/infrastructure/models/market_data_sources

2 files changed

+30
-14
lines changed

investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ def get_data(self, **kwargs):
438438
if self.config is not None:
439439
market_service.config = self.config
440440

441+
if "window_size" in kwargs:
442+
self.window_size = kwargs["window_size"]
443+
441444
if "start_date" in kwargs:
442445
start_date = kwargs["start_date"]
443446

@@ -451,6 +454,14 @@ def get_data(self, **kwargs):
451454
)
452455

453456
if "end_date" not in kwargs:
457+
458+
if self.window_size is None:
459+
raise OperationalException(
460+
"Either end_date or window_size "
461+
"should be passed as a "
462+
"parameter for CCXTOHLCVMarketDataSource"
463+
)
464+
454465
end_date = self.create_end_date(
455466
start_date, self.timeframe, self.window_size
456467
)

investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def get_data(self, **kwargs):
8888
end_date = kwargs.get("end_date")
8989
backtest_index_date = kwargs.get("backtest_index_date")
9090

91+
if "window_size" in kwargs:
92+
self.window_size = kwargs["window_size"]
93+
9194
if start_date is None \
9295
and end_date is None \
9396
and backtest_index_date is None:
@@ -97,11 +100,27 @@ def get_data(self, **kwargs):
97100

98101
if backtest_index_date is not None:
99102
end_date = backtest_index_date
103+
104+
if self.window_size is None:
105+
raise OperationalException(
106+
"Either end_date or window_size "
107+
"should be passed as a "
108+
"parameter for CCXTOHLCVMarketDataSource"
109+
)
110+
100111
start_date = self.create_start_date(
101112
end_date, self.timeframe, self.window_size
102113
)
103114
else:
104115
if start_date is None:
116+
117+
if self.window_size is None:
118+
raise OperationalException(
119+
"Either end_date or window_size "
120+
"should be passed as a "
121+
"parameter for CCXTOHLCVMarketDataSource"
122+
)
123+
105124
start_date = self.create_start_date(
106125
end_date, self.timeframe, self.window_size
107126
)
@@ -111,20 +130,6 @@ def get_data(self, **kwargs):
111130
start_date, self.timeframe, self.window_size
112131
)
113132

114-
# # Check if start or end date are out of range with
115-
# # the dates of the datasource.
116-
# if self._start_date_data_source > start_date:
117-
# raise OperationalException(
118-
# f"Given start date {start_date} is before the start date "
119-
# f"of the data source {self._start_date_data_source}"
120-
# )
121-
#
122-
# if self._end_date_data_source < end_date:
123-
# raise OperationalException(
124-
# f"End date {end_date} is after the end date "
125-
# f"of the data source {self._end_date_data_source}"
126-
# )
127-
128133
df = polars.read_csv(
129134
self.csv_file_path, columns=self._columns, separator=","
130135
)

0 commit comments

Comments
 (0)