[Bug]: Historical bar data is not consistent with API
- 主要语言
- Python
- 星标
- 1.5k
- 派生
- 397
- 平均合并
- 1 天 16 小时
- 30 天内合并 PR
- 6
描述
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Current Behavior
I tried to get hourly bar data from SDK but data is not hourly.
```
params = StockBarsRequest(
symbol_or_symbols="AAPL",
start=datetime(year=2026, month=4, day=6),
timeframe=TimeFrame(amount=1, unit=TimeFrame.Hour),
)
```
### Expected Behavior
I expect to obtain the same result as from this code
```
import requests
url = "https://data.alpaca.markets/v2/stocks/bars?limit=1000&adjustment=raw&feed=sip&sort=asc"
headers = {
"accept": "application/json",
"APCA-API-KEY-ID": os.environ["ALPACA_API_KEY"],
"APCA-API-SECRET-KEY": os.environ["ALPACA_SECRET"]
}
params = {
"symbols": "AAPL",
"timeframe": "1Hour",
"start": "2026-04-06"
}
response = requests.get(url, headers=headers, params=params)
bars = {i: pd.DataFrame(j) for i, j in response.json()["bars"].items()}
print(bars["AAPL"])
```
### SDK Version I encountered this issue in
alpaca-py=='0.43.2'
### Steps To Reproduce
```markdown
OS: macOS Sonoma Version 14.6.1
1. Set environment variables: ALPACA_API_KEY and ALPACA_SECRET
2. Run
from alpaca.data.requests import StockBarsRequest, TimeFrame
from alpaca.data import StockHistoricalDataClient
from datetime import datetime
import pandas as pd
import os
hist_client = StockHistoricalDataClient(
api_key=os.environ["ALPACA_API_KEY"],
secret_key=os.environ["ALPACA_SECRET"]
)
params = StockBarsRequest(
symbol_or_symbols="AAPL",
start=datetime(year=2026, month=4, day=6),
timeframe=TimeFrame(amount=1, unit=TimeFrame.Hour),
)
bars = hist_client.get_stock_bars(request_params = params )
_bars = []
for symbol, values in bars.data.items():
_bars += [dict(i) | {"symbol": symbol} for i in values]
df_bars = pd.DataFrame.from_records(_bars).set_index("timestamp")
print(df_bars)
```
### Filled out the Steps to Reproduce section?
- [x] I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.
### Anything else?
_No response_
贡献指南
评估
这个 Issue 还没有评估数据。