Is there an existing issue for this?
Current Behavior
The BarSet class returned by StockHistoricalDataClient.get_stock_bars() has a broken contains implementation. Using symbol in bars always returns False even when the symbol's data exists in bars.data.
Actual Behavior
- 'SPY' in bars → False
- 'SPY' in bars.data → True
- bars['SPY'] → Works correctly (returns list of bars)
Environment
- alpaca-py version: 0.33.1, reconfirmed in 0.43.2
- Python version: 3.11
Suggested Fix
Add a contains method to BarSet that delegates to self.data:
def contains(self, key):
return key in self.data
Expected Behavior
When I call get_stock_bars() and check if a symbol exists using 'SPY' in bars, it should return True if bar data for that symbol was returned by the API.
SDK Version I encountered this issue in
Bug found in 0.33.1
Reconfirmed that bug exists in 0.43.2
Steps To Reproduce
Reproduction Steps
from alpaca.data import StockHistoricalDataClient
from alpaca.data.requests import StockBarsRequest
from alpaca.data.timeframe import TimeFrame
from datetime import datetime
import pytz
ET = pytz.timezone('America/New_York')
client = StockHistoricalDataClient('<API_KEY>', '<API_SECRET>')
now = datetime.now(ET)
market_open = now.replace(hour=9, minute=30, second=0, microsecond=0)
req = StockBarsRequest(
symbol_or_symbols='SPY',
timeframe=TimeFrame.Minute,
start=market_open
)
bars = client.get_stock_bars(req)
# BUG: These produce inconsistent results
print(f"'SPY' in bars: {'SPY' in bars}") # False (WRONG!)
print(f"'SPY' in bars.data: {'SPY' in bars.data}") # True (correct)
print(f"len(bars['SPY']): {len(bars['SPY'])}") # Works, returns 80+ bars
Expected Behavior
'SPY' in bars should return True when bars['SPY'] contains data.
Filled out the Steps to Reproduce section?
Anything else?
No response
Is there an existing issue for this?
Current Behavior
The BarSet class returned by StockHistoricalDataClient.get_stock_bars() has a broken contains implementation. Using symbol in bars always returns False even when the symbol's data exists in bars.data.
Actual Behavior
Environment
Suggested Fix
Add a contains method to BarSet that delegates to self.data:
def contains(self, key):
return key in self.data
Expected Behavior
When I call get_stock_bars() and check if a symbol exists using 'SPY' in bars, it should return True if bar data for that symbol was returned by the API.
SDK Version I encountered this issue in
Bug found in 0.33.1
Reconfirmed that bug exists in 0.43.2
Steps To Reproduce
Reproduction Steps from alpaca.data import StockHistoricalDataClient from alpaca.data.requests import StockBarsRequest from alpaca.data.timeframe import TimeFrame from datetime import datetime import pytz ET = pytz.timezone('America/New_York') client = StockHistoricalDataClient('<API_KEY>', '<API_SECRET>') now = datetime.now(ET) market_open = now.replace(hour=9, minute=30, second=0, microsecond=0) req = StockBarsRequest( symbol_or_symbols='SPY', timeframe=TimeFrame.Minute, start=market_open ) bars = client.get_stock_bars(req) # BUG: These produce inconsistent results print(f"'SPY' in bars: {'SPY' in bars}") # False (WRONG!) print(f"'SPY' in bars.data: {'SPY' in bars.data}") # True (correct) print(f"len(bars['SPY']): {len(bars['SPY'])}") # Works, returns 80+ bars Expected Behavior 'SPY' in bars should return True when bars['SPY'] contains data.Filled out the Steps to Reproduce section?
Anything else?
No response