From c0bc567f231303f5794a17a50c010f747b389bd1 Mon Sep 17 00:00:00 2001 From: Robert Grzesik Date: Fri, 29 Nov 2024 13:06:21 -0500 Subject: [PATCH] bug fix for float in historical data --- lumibot/data_sources/pandas_data.py | 9 ++++++++- lumibot/entities/data.py | 2 +- lumibot/strategies/strategy.py | 10 ++++++++++ setup.py | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lumibot/data_sources/pandas_data.py b/lumibot/data_sources/pandas_data.py index a8671e0f7..5c74af8fa 100644 --- a/lumibot/data_sources/pandas_data.py +++ b/lumibot/data_sources/pandas_data.py @@ -427,7 +427,14 @@ def get_start_datetime_and_ts_unit(self, length, timestep, start_dt=None, start_ return start_datetime, ts_unit def get_historical_prices( - self, asset, length, timestep="", timeshift=None, quote=None, exchange=None, include_after_hours=True + self, + asset: Asset, + length: int, + timestep: str = None, + timeshift: int = None, + quote: Asset = None, + exchange: str = None, + include_after_hours: bool = True, ): """Get bars for a given asset""" if isinstance(asset, str): diff --git a/lumibot/entities/data.py b/lumibot/entities/data.py index dbc15018e..b040e7e1b 100644 --- a/lumibot/entities/data.py +++ b/lumibot/entities/data.py @@ -596,7 +596,7 @@ def get_bars(self, dt, length=1, timestep=MIN_TIMESTEP, timeshift=0): # The original df_result may include more rows when timestep is day and self.timestep is minute. # In this case, we only want to return the last n rows. - df_result = df_result.tail(n=num_periods) + df_result = df_result.tail(n=int(num_periods)) return df_result diff --git a/lumibot/strategies/strategy.py b/lumibot/strategies/strategy.py index a25e43dd4..fbe972873 100644 --- a/lumibot/strategies/strategy.py +++ b/lumibot/strategies/strategy.py @@ -3097,6 +3097,16 @@ def get_historical_prices( >>> self.log_message(f"Last price of BTC in USD: {last_ohlc['close']}, and the open price was {last_ohlc['open']}") """ + # Get that length is type int and if not try to cast it + if not isinstance(length, int): + try: + length = int(length) + except Exception as e: + raise ValueError( + f"Invalid length parameter in get_historical_prices() method. Length must be an int but instead got {length}, " + f"which is a type {type(length)}." + ) + if quote is None: quote = self.quote_asset diff --git a/setup.py b/setup.py index e856c17c1..a923bac32 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="lumibot", - version="3.8.14", + version="3.8.15", author="Robert Grzesik", author_email="rob@lumiwealth.com", description="Backtesting and Trading Library, Made by Lumiwealth",