# Why Alpaca API does not provide "useRTH=True/False" to either get Regular Market hours data?

**URL:** <https://forum.alpaca.markets/t/why-alpaca-api-does-not-provide-userth-true-false-to-either-get-regular-market-hours-data/12268>\
**Category:** Alpaca Market Data\
**Created:** [April 25, 2023, 9:42pm UTC](https://forum.alpaca.markets/t/why-alpaca-api-does-not-provide-userth-true-false-to-either-get-regular-market-hours-data/12268 "2023-04-25T21:42:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![EGYXee](https://avatars.discourse-cdn.com/v4/letter/e/cc9497/32.png) [@EGYXee](https://forum.alpaca.markets/u/EGYXee)\
**Post date:** [April 25, 2023, 9:42pm UTC](https://forum.alpaca.markets/t/why-alpaca-api-does-not-provide-userth-true-false-to-either-get-regular-market-hours-data/12268/1 "2023-04-25T21:42:04Z")

</div>

I have been trying to work with Regular Trading Hours (RTH) market data using the Alpaca API but never succeeded in getting data similar to what I get from other brokers. Interactive Brokers API provides something like a “useRTH =False” parameter to either work with Regular Trading Hours or not!  
Why can’t Alpaca Markets API have a similar thing to make our lives easier?

---

<div class="post-metadata">

**Author:** ![nye](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/nye/32/2111_2.png) [@nye](https://forum.alpaca.markets/u/nye)\
**Post date:** [May 1, 2023, 4:36am UTC](https://forum.alpaca.markets/t/why-alpaca-api-does-not-provide-userth-true-false-to-either-get-regular-market-hours-data/12268/2 "2023-05-01T04:36:25Z")

</div>

You can easily filter the data returned for market hours. See the commented line below:

```auto
def get_bars(self, symbols:pd.Series, start_datetime:datetime, end_datetime:datetime, timeframe):
        stockbar_request = StockBarsRequest(symbol_or_symbols=symbols.tolist(), start=start_datetime, end=end_datetime, \
            timeframe=timeframe, adjustment=Adjustment.DIVIDEND, feed=DataFeed.SIP)
        try:
            df = self.historicaldata_client.get_stock_bars(stockbar_request).df
            #print(df)
            
            df = df.reset_index()
            #print(df)
            df.set_index('timestamp', inplace=True)
            df = df.tz_convert('America/New_York')

            ##################################
            # filter the data returned for market hours
            df= df.between_time("9:30", "16:00")
            ##################################

            #print(df)
        except BaseException as error:
            print('An exception occurred: {}'.format(error))
            
            df = pd.DataFrame()
        
        return df

```

---

<div class="post-metadata">

**Author:** ![EGYXee](https://avatars.discourse-cdn.com/v4/letter/e/cc9497/32.png) [@EGYXee](https://forum.alpaca.markets/u/EGYXee)\
**Post date:** [May 1, 2023, 8:45pm UTC](https://forum.alpaca.markets/t/why-alpaca-api-does-not-provide-userth-true-false-to-either-get-regular-market-hours-data/12268/3 "2023-05-01T20:45:06Z")

</div>

Thank you for the code,  
I will give it a try.  
Thank you

---

<div class="post-metadata">

**Author:** ![DmitriK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dmitrik/32/5490_2.png) [@DmitriK](https://forum.alpaca.markets/u/DmitriK)\
**Post date:** [March 18, 2024, 6:22pm UTC](https://forum.alpaca.markets/t/why-alpaca-api-does-not-provide-userth-true-false-to-either-get-regular-market-hours-data/12268/4 "2024-03-18T18:22:42Z")

</div>

Filtering on client side is not good. Fetching unneeded bars consumes bandwidth.  
Besides hours need to filter trading days too.

---

<div class="post-metadata">

**Author:** ![EGYXee](https://avatars.discourse-cdn.com/v4/letter/e/cc9497/32.png) [@EGYXee](https://forum.alpaca.markets/u/EGYXee)\
**Post date:** [March 18, 2024, 6:35pm UTC](https://forum.alpaca.markets/t/why-alpaca-api-does-not-provide-userth-true-false-to-either-get-regular-market-hours-data/12268/5 "2024-03-18T18:35:17Z")

</div>

Is there a way to filter data on server side?  
Can you provide code example to return filtered data?
