Get_crypto_bars method not returning correct number of bars

I want to get the past day of minute bars.

return self.api.get_crypto_bars(
    symbol = self.symbol,
    timeframe = alpaca_trade_api.TimeFrame.Minute,
    start = (datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(minutes = 86400)).isoformat()
)

This code returns an alpaca_trade_api.entity_v2.BarsV2 list that has a length of 148369, which is about 1.717 days, instead of 1 day.

Currently running Python 3.10.1 and API version v2.

And yes, I have the market data subscription.

@Slickky The format of the get_crypto_bar result is a bit different from the format of the equity get_bars. Specifically, the crypto bars are by exchange whereas the equity bars are consolidated across all exchanges. In other words, there can be multiple minute bars (one for each exchange where trades occurred) in crypto but there will only ever be one minute bar for equities. That is why you are getting more bars than you may have expected.

See below for how the crypto data is formatted. Notice two bars for one minute with different exchanges.

I am not able to get this to work. Did something change recently?

I got this to work with this:

from alpaca.data.historical import CryptoHistoricalDataClient
from alpaca.data.requests import CryptoBarsRequest
from alpaca.data.timeframe import TimeFrame

No keys required for crypto data

client = CryptoHistoricalDataClient()

Creating request object

request_params = CryptoBarsRequest(
symbol_or_symbols=[“BTC/USD”],
timeframe=TimeFrame.Minute,
start=“2023-12-01T00:00:00Z”,
end=“2023-12-28T00:00:00Z”
)

Retrieve daily bars for Bitcoin in a DataFrame and printing it

btc_bars = client.get_crypto_bars(request_params)

Convert to dataframe

btc_bars.df

get_crypto_bars not returning exchange.

Instantiate REST API Connection

api = REST(key_id=KEY_ID,secret_key=SECRET_KEY,base_url=“https://paper-api.alpaca.markets”)

Fetch 1Minute historical bars of Bitcoin

bars = api.get_crypto_bars(“BTC/USD”, TimeFrame.Minute).df

print(bars)

bars = bars[bars.exchange == ‘CBSE’]

print(bars)

                             close         high          low  trade_count  \

timestamp
2025-07-22 00:03:00+00:00 117395.3765 117395.3765 117395.3765 0
2025-07-22 00:07:00+00:00 117347.5250 117347.5250 117347.5250 0
2025-07-22 00:15:00+00:00 117397.5910 117397.5910 117397.5910 0
2025-07-22 00:16:00+00:00 117542.6200 117542.6200 117460.4100 0
2025-07-22 00:18:00+00:00 117523.1895 117634.1400 117523.1895 1
… … … … …
2025-07-22 06:17:00+00:00 117507.2190 117558.6500 117475.4250 1
2025-07-22 06:18:00+00:00 117561.3000 117561.3000 117561.3000 0
2025-07-22 06:19:00+00:00 117640.4215 117640.4215 117640.4215 0
2025-07-22 06:21:00+00:00 117666.1355 117666.1355 117666.1355 0
2025-07-22 06:23:00+00:00 117756.6850 117756.6850 117756.6850 0

                              open    volume         vwap   symbol  

timestamp
2025-07-22 00:03:00+00:00 117395.3765 0.000000 117395.3765 BTC/USD
2025-07-22 00:07:00+00:00 117347.5250 0.000000 117347.5250 BTC/USD
2025-07-22 00:15:00+00:00 117397.5910 0.000000 117397.5910 BTC/USD
2025-07-22 00:16:00+00:00 117460.4100 0.000000 117501.5150 BTC/USD
2025-07-22 00:18:00+00:00 117634.1400 0.000009 117634.1400 BTC/USD
… … … … …
2025-07-22 06:17:00+00:00 117475.4250 0.013702 117558.6500 BTC/USD
2025-07-22 06:18:00+00:00 117561.3000 0.000000 117561.3000 BTC/USD
2025-07-22 06:19:00+00:00 117640.4215 0.000000 117640.4215 BTC/USD
2025-07-22 06:21:00+00:00 117666.1355 0.000000 117666.1355 BTC/USD
2025-07-22 06:23:00+00:00 117756.6850 0.000000 117756.6850 BTC/USD

[223 rows x 8 columns]

AttributeError: ‘DataFrame’ object has no attribute ‘exchange’

When I print bars, there is no exchange column.

@SAF_SAF @SAF_SAF All Alpaca crypto data is just from trades executed on Alpaca (ie the ‘Alpaca exchange’). That is why there is no exchange listed.