Skip to content

Add time_frame check to ohlcv market data source #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ def get_data(
if end_date is None:
end_date = datetime.now(tz=timezone.utc)

if self.window_size is None:
raise OperationalException(
"Window_size should be defined before the " +
"get_data method can be called. Make sure to set " +
"the window_size attribute on your " +
"CCXTOHLCVMarketDataSource or provide a start_date " +
"and end_date to the get_data method."
)

start_date = self.create_start_date(
end_date=end_date,
time_frame=self.time_frame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ def get_ohlcv(
col_names = ["Datetime", "Open", "High", "Low", "Close", "Volume"]

# Combine the Series into a DataFrame with given column names
df = pl.DataFrame(data, schema=col_names)

df = pl.DataFrame(data, schema=col_names, orient="row")
return df

def get_ohlcvs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from investing_algorithm_framework.infrastructure import \
CCXTOHLCVMarketDataSource
from investing_algorithm_framework.domain import OperationalException


class Test(TestCase):
Expand Down Expand Up @@ -79,6 +80,21 @@ def test_get_data_with_only_window_size(self, mock):
self.assertIsNotNone(data)
self.assertEqual(data_source.window_size, 200)

def test_get_data_with_no_params_and_window_size(self):
"""
This should raise an exception because the window size needs to be
defined if no start date or end date is provided.
"""
data_source = CCXTOHLCVMarketDataSource(
identifier="BTC/EUR",
time_frame="15m",
market="BITVAVO",
symbol="BTC/EUR",
)

with self.assertRaises(OperationalException) as context:
data_source.get_data()

@mock.patch('investing_algorithm_framework.infrastructure.services.market_service.ccxt_market_service.CCXTMarketService.get_ohlcv')
def test_get_data_with_only_start_date(self, mock):
data_source = CCXTOHLCVMarketDataSource(
Expand Down
Loading