Skip to content

Commit 0617064

Browse files
committed
Add time_frame check to ohlcv market data source
1 parent 403a3c0 commit 0617064

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py

+9
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,15 @@ def get_data(
472472
if end_date is None:
473473
end_date = datetime.now(tz=timezone.utc)
474474

475+
if self.window_size is None:
476+
raise OperationalException(
477+
"Window_size should be defined before the " +
478+
"get_data method can be called. Make sure to set " +
479+
"the window_size attribute on your " +
480+
"CCXTOHLCVMarketDataSource or provide a start_date " +
481+
"and end_date to the get_data method."
482+
)
483+
475484
start_date = self.create_start_date(
476485
end_date=end_date,
477486
time_frame=self.time_frame,

tests/infrastructure/market_data_sources/test_ccxt_ohlcv_market_data_source.py

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from investing_algorithm_framework.infrastructure import \
66
CCXTOHLCVMarketDataSource
7+
from investing_algorithm_framework.domain import OperationalException
78

89

910
class Test(TestCase):
@@ -79,6 +80,21 @@ def test_get_data_with_only_window_size(self, mock):
7980
self.assertIsNotNone(data)
8081
self.assertEqual(data_source.window_size, 200)
8182

83+
def test_get_data_with_no_params_and_window_size(self):
84+
"""
85+
This should raise an exception because the window size needs to be
86+
defined if no start date or end date is provided.
87+
"""
88+
data_source = CCXTOHLCVMarketDataSource(
89+
identifier="BTC/EUR",
90+
time_frame="15m",
91+
market="BITVAVO",
92+
symbol="BTC/EUR",
93+
)
94+
95+
with self.assertRaises(OperationalException) as context:
96+
data_source.get_data()
97+
8298
@mock.patch('investing_algorithm_framework.infrastructure.services.market_service.ccxt_market_service.CCXTMarketService.get_ohlcv')
8399
def test_get_data_with_only_start_date(self, mock):
84100
data_source = CCXTOHLCVMarketDataSource(

0 commit comments

Comments
 (0)