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