Skip to content

Commit

Permalink
Add zero rows check
Browse files Browse the repository at this point in the history
  • Loading branch information
MDUYN committed Jul 4, 2024
1 parent a07e4e4 commit d09ebb8
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d09ebb8

Please sign in to comment.