# Get\_crypto\_bars method not returning correct number of bars

**URL:** <https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366>\
**Category:** Alpaca Market Data\
**Created:** [May 4, 2022, 7:39pm UTC](https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366 "2022-05-04T19:39:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slickky](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/slickky/32/4177_2.png) [@Slickky](https://forum.alpaca.markets/u/Slickky)\
**Post date:** [May 4, 2022, 7:39pm UTC](https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366/1 "2022-05-04T19:39:30Z")

</div>

I want to get the past day of minute bars.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Dan\_Whitnable\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dan_whitnable_alpaca/32/1658_2.png) [@Dan\_Whitnable\_Alpaca](https://forum.alpaca.markets/u/Dan_Whitnable_Alpaca)\
**Post date:** [May 6, 2022, 3:28pm UTC](https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366/2 "2022-05-06T15:28:55Z")

</div>

@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.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/alp/original/2X/d/d7972b95e5dae7482e2321567cdbd6815907fc21.jpeg)

---

<div class="post-metadata">

**Author:** ![rossjeremyd](https://avatars.discourse-cdn.com/v4/letter/r/c67d28/32.png) [@rossjeremyd](https://forum.alpaca.markets/u/rossjeremyd)\
**Post date:** [December 28, 2023, 8:32pm UTC](https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366/3 "2023-12-28T20:32:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rossjeremyd](https://avatars.discourse-cdn.com/v4/letter/r/c67d28/32.png) [@rossjeremyd](https://forum.alpaca.markets/u/rossjeremyd)\
**Post date:** [December 29, 2023, 2:14pm UTC](https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366/4 "2023-12-29T14:14:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SAF\_SAF](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/saf_saf/32/6889_2.png) [@SAF\_SAF](https://forum.alpaca.markets/u/SAF_SAF)\
**Post date:** [July 22, 2025, 6:31am UTC](https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366/5 "2025-07-22T06:31:31Z")

</div>

# 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](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.

---

<div class="post-metadata">

**Author:** ![Dan\_Whitnable\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dan_whitnable_alpaca/32/1658_2.png) [@Dan\_Whitnable\_Alpaca](https://forum.alpaca.markets/u/Dan_Whitnable_Alpaca)\
**Post date:** [August 7, 2025, 9:02pm UTC](https://forum.alpaca.markets/t/get-crypto-bars-method-not-returning-correct-number-of-bars/9366/6 "2025-08-07T21:02:03Z")

</div>

@SAF_SAF [@SAF\_SAF](https://forum.alpaca.markets/u/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.
