From e615473d221ac468fe6e0141ff5ab9c771935bd0 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Wed, 4 Feb 2026 16:36:16 -0700 Subject: [PATCH] Replace print statements with proper logging for consistent log file output --- alpaca_trader/api.py | 3 ++- alpaca_trader/filters.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/alpaca_trader/api.py b/alpaca_trader/api.py index cbee389..aa89606 100644 --- a/alpaca_trader/api.py +++ b/alpaca_trader/api.py @@ -95,5 +95,6 @@ class AlpacaClient: return float(status.filled_avg_price) return None except Exception as e: - print(f"Order placement error: {e}") + import logging + logging.error(f"Order placement error: {e}") return None diff --git a/alpaca_trader/filters.py b/alpaca_trader/filters.py index b6b93ca..e427182 100644 --- a/alpaca_trader/filters.py +++ b/alpaca_trader/filters.py @@ -1,9 +1,12 @@ import pandas as pd from datetime import datetime +import logging from .indicators import ema, sma, rsi, adx, atr, bollinger, macd from .api import AlpacaClient from .utils import EASTERN +logger = logging.getLogger(__name__) + def check_volume(bars: pd.DataFrame, multiplier: float): if len(bars) < 20 or "volume" not in bars.columns: return True @@ -84,15 +87,16 @@ def get_vix(client: AlpacaClient, symbol: str, use_vix_filter: bool): if len(vix) > 0: return vix["close"].iloc[-1] except Exception as e: - print(f"Warning: VIX data unavailable: {e}") + logger.warning(f"VIX data unavailable: {e}") try: spy = client.get_bars(symbol, "1Day", limit=20) if len(spy) >= 20: returns = spy["close"].pct_change() calculated_vix = returns.std() * (252 ** 0.5) * 100 - print(f"Using calculated volatility as VIX proxy: {calculated_vix:.1f}") + logger.info(f"Using calculated volatility as VIX proxy: {calculated_vix:.1f}") return calculated_vix except Exception as e: - print(f"Warning: Could not calculate volatility: {e}") - print("Warning: VIX data unavailable, skipping VIX filter for this iteration") + logger.warning(f"Could not calculate volatility: {e}") + logger.warning("VIX data unavailable, skipping VIX filter for this iteration") + return 0 return 0