Fix duplicate return, add defensive null checks for bid/ask prices, and protect PnL calculation

This commit is contained in:
justin committed 2026-02-04 16:47:03 -07:00
1 parent e615473d22
commit 6c878c4e63
3 files changed
+7 -2

No files matched your search

+6
View File
@@ -61,6 +61,12 @@ class AlpacaClient:
return None return None
bid_price = getattr(quote, 'bid_price', None) bid_price = getattr(quote, 'bid_price', None)
ask_price = getattr(quote, 'ask_price', None) ask_price = getattr(quote, 'ask_price', None)
if bid_price is None or ask_price is None:
return None
if bid_price <= 0 or ask_price <= 0:
return None
if limit_price: if limit_price:
price_source = limit_price price_source = limit_price
else: else:
+1 -1
View File
@@ -1076,7 +1076,7 @@ def main():
status_msg = f"⏱️ {current_time} | {position_status} | {regime.upper()}" status_msg = f"⏱️ {current_time} | {position_status} | {regime.upper()}"
if position_active: if position_active:
if entry_price > 0: if entry_price > 0 and current_price > 0:
pnl_pct = ((current_price - entry_price) / entry_price) * 100 if position_type == 'long' else ((entry_price - current_price) / entry_price) * 100 pnl_pct = ((current_price - entry_price) / entry_price) * 100 if position_type == 'long' else ((entry_price - current_price) / entry_price) * 100
else: else:
pnl_pct = 0 pnl_pct = 0
-1
View File
@@ -99,4 +99,3 @@ def get_vix(client: AlpacaClient, symbol: str, use_vix_filter: bool):
logger.warning(f"Could not calculate volatility: {e}") logger.warning(f"Could not calculate volatility: {e}")
logger.warning("VIX data unavailable, skipping VIX filter for this iteration") logger.warning("VIX data unavailable, skipping VIX filter for this iteration")
return 0 return 0
return 0