alpacahq / alpacahq/alpaca-py

[Bug]: Historical bar data is not consistent with API

Open
#664 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.5k
Forks
398
Avg merge
1d 16h
Merged PRs (30d)
6

Description

### 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),
)
```

Image

### 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"])
```

Image

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.