From d09ebb83e434ee168e9e0327d76148429a92f5d2 Mon Sep 17 00:00:00 2001 From: marcvanduyn Date: Thu, 4 Jul 2024 11:53:00 +0200 Subject: [PATCH] Add zero rows check --- .../market_service/ccxt_market_service.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py b/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py index 0a9412c..73c0a87 100644 --- a/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +++ b/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py @@ -356,6 +356,20 @@ def get_closed_orders( def get_ohlcv( self, symbol, time_frame, from_timestamp, market, to_timestamp=None ) -> pl.DataFrame: + """ + Function to retrieve ohlcv data for a symbol, time frame and market + + Args: + symbol: The symbol to retrieve ohlcv data for + time_frame: The time frame to retrieve ohlcv data for + from_timestamp: The start date to retrieve ohlcv data from + market: The market to retrieve ohlcv data from + to_timestamp: The end date to retrieve ohlcv data to + + Returns: + DataFrame: The ohlcv data for the symbol, time frame and market + in polars DataFrame format + """ if self.config is not None and "DATETIME_FORMAT" in self.config: datetime_format = self.config["DATETIME_FORMAT"] @@ -413,8 +427,8 @@ def get_ohlcv( # Combine the Series into a DataFrame with given column names df = pl.DataFrame(data) - # Check if width is 0 - if len(df) == 0: + # Check if DataFrame is empty (either rows or columns) + if df.shape[0] == 0 or df.shape[1] == 0: return df # Assign column names after DataFrame creation