Skip to content

Commit

Permalink
Merge branch 'dev' into backtest-logs-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Al4ise committed Oct 24, 2024
2 parents cedf4cf + 2fbbc9a commit 5b7349f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
20 changes: 12 additions & 8 deletions lumibot/strategies/_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ def __init__(
self._name = self.__class__.__name__

# Create an adapter with 'strategy_name' set to the instance's name
self.logger = CustomLoggerAdapter(logger, {'strategy_name': self._name})
logging.info(self.__class__.__name__)
if not hasattr(self, "logger") or self.logger is None:
self.logger = CustomLoggerAdapter(logger, {'strategy_name': self._name})

# Set the log level to INFO so that all logs INFO and above are displayed
self.logger.setLevel(logging.INFO)

Expand All @@ -221,9 +222,6 @@ def __init__(
self.hide_positions = HIDE_POSITIONS
self.hide_trades = HIDE_TRADES

if self._name is None:
self._name = self.__class__.__name__

# If the MARKET env variable is set, use it as the market
if MARKET:
# Log the market being used
Expand Down Expand Up @@ -998,6 +996,15 @@ def run_backtest(
>>> )
"""

if name is None:
name = self.__name__

self._name = name

# Create an adapter with 'strategy_name' set to the instance's name
if not hasattr(self, "logger") or self.logger is None:
self.logger = CustomLoggerAdapter(logger, {'strategy_name': self._name})

# Print start message
print(f"Starting backtest for {datasource_class.__name__}...")

Expand All @@ -1019,9 +1026,6 @@ def run_backtest(
"polygon_has_paid_subscription is deprecated and will be removed in future versions. "
"Please remove it from your code."
)

if name is None:
name = self.__name__

# check if datasource_class is a class or a dictionary
if isinstance(datasource_class, dict):
Expand Down
2 changes: 1 addition & 1 deletion lumibot/tools/polygon_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_price_data_from_polygon(
# multiple queries if we are requesting more than 30 days of data
delta = timedelta(days=MAX_POLYGON_DAYS)
while poly_start <= missing_dates[-1]:
if poly_end > poly_start + delta:
if poly_end > (poly_start + delta):
poly_end = poly_start + delta

result = polygon_client.get_aggs(
Expand Down
5 changes: 5 additions & 0 deletions lumibot/traders/trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ def _set_logger(self):

if self.debug:
logger.setLevel(logging.DEBUG)
elif self.is_backtest_broker:
logger.setLevel(logging.INFO)
for handler in logger.handlers:
if handler.__class__.__name__ == "StreamHandler":
handler.setLevel(logging.ERROR)
else:
logger.setLevel(logging.INFO)

Expand Down

0 comments on commit 5b7349f

Please sign in to comment.