Skip to content

Commit

Permalink
Merge pull request #641 from Lumiwealth/float-in-historical-data-bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesir authored Dec 3, 2024
2 parents 6dc59cf + c0bc567 commit b295196
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lumibot/data_sources/pandas_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lumibot/entities/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions lumibot/strategies/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="lumibot",
version="3.8.14",
version="3.8.15",
author="Robert Grzesik",
author_email="[email protected]",
description="Backtesting and Trading Library, Made by Lumiwealth",
Expand Down

0 comments on commit b295196

Please sign in to comment.