# How to retrieve recent/current stock data?

**URL:** <https://forum.alpaca.markets/t/how-to-retrieve-recent-current-stock-data/13341>\
**Category:** Getting Started with Alpaca\
**Created:** [December 25, 2023, 3:06pm UTC](https://forum.alpaca.markets/t/how-to-retrieve-recent-current-stock-data/13341 "2023-12-25T15:06:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bunkiyiester](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/bunkiyiester/32/5735_2.png) [@Bunkiyiester](https://forum.alpaca.markets/u/Bunkiyiester)\
**Post date:** [December 25, 2023, 3:06pm UTC](https://forum.alpaca.markets/t/how-to-retrieve-recent-current-stock-data/13341/1 "2023-12-25T15:06:13Z")

</div>

This is in python

I am trying to calculate the stocks RSI

I have tried:

current\_datetime = datetime.now()  
print(current\_datetime)

#Get the last 7 days of historical data  
start\_datetime = current\_datetime - timedelta(days=7)

data = api.get\_bars(“NVDA”, tradeapi.rest.TimeFrame.Minute, start\_datetime, current\_datetime, limit=100000, adjustment=‘raw’).df

yet I get the error:

400 Client Error: Bad Request for url: [https://data.alpaca.markets/v2/stocks/NVDA/bars?timeframe=1Min&adjustment=raw&start=2023-12-18+19%3A01%3A36.991984&end=2023-12-25+19%3A01%3A36.991984&limit=10000](https://data.alpaca.markets/v2/stocks/NVDA/bars?timeframe=1Min&adjustment=raw&start=2023-12-18+19%3A01%3A36.991984&end=2023-12-25+19%3A01%3A36.991984&limit=10000)

---

<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:** [December 28, 2023, 3:42pm UTC](https://forum.alpaca.markets/t/how-to-retrieve-recent-current-stock-data/13341/2 "2023-12-28T15:42:04Z")

</div>

@Bunkiyiester The main issue is that the APIs expect a timezone. The current\_datetime is timezone naive. In general, always ensure datetime objects are timezone aware and ideally (for consistancy) ensure the timezone is set to market time. In this instance however UTC is ok.

So change your code to this and it will work

```auto

from datetime import datetime, timedelta, timezone

current_datetime = datetime.now(tz=timezone.utc)
start_datetime = current_datetime - timedelta(days=7)

data = api.get_bars(“NVDA”, 
                    tradeapi.rest.TimeFrame.Minute, 
                    start_datetime, 
                    current_datetime, 
                    limit=100000, 
                    adjustment=‘raw’).df

```

---

<div class="post-metadata">

**Author:** ![Bunkiyiester](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/bunkiyiester/32/5735_2.png) [@Bunkiyiester](https://forum.alpaca.markets/u/Bunkiyiester)\
**Post date:** [January 2, 2024, 4:34pm UTC](https://forum.alpaca.markets/t/how-to-retrieve-recent-current-stock-data/13341/3 "2024-01-02T16:34:44Z")

</div>

ah I see that makes sense, thanks, but is there any way to specify the interval for data?
