Why does the API values shows different data for 02/12/2025

It is not only for the mentioned date of 02/12/2025, but the data for any day is inconsistent irrespective of the stock. For example for TSLA,

This is what I get the closing prices from Trading View -

time close Basis Upper Lower RSI RSI-based MA
2025-02-12T09:30:00-05:00 599.62 604.92425 607.4192435 602.4292565 15.83301584 53.06023108
2025-02-12T09:35:00-05:00 600.11 604.69325 607.9550597 601.4314403 21.1353964 49.9986713
2025-02-12T09:40:00-05:00 600.58 604.48225 608.202842 600.761658 25.95395825 47.12198718
2025-02-12T09:45:00-05:00 601.17 604.28525 608.260543 600.309957 31.60343759 45.0263625
2025-02-12T09:50:00-05:00 601.51 604.07875 608.1782279 599.9792721 34.69558853 42.97320457
2025-02-12T09:55:00-05:00 601.35 603.87175 608.0818822 599.6616178 33.91846799 41.14766173
2025-02-12T10:00:00-05:00 599.89 603.59075 608.0677426 599.1137574 27.79960982 39.31343751
2025-02-12T10:05:00-05:00 600.32 603.33675 607.9487217 598.7247783 31.70720299 37.52982451
2025-02-12T10:10:00-05:00 599.8 603.04925 607.7886258 598.3098742 29.61950728 35.59709039
2025-02-12T10:15:00-05:00 601.25 602.844 607.5213215 598.1666785 41.2381203 35.12039236

And below is what I get from Alpaca API for Historical bars -

{“bars”:
{“TSLA”:[
{“c”:321.95,“h”:323,“l”:320.33,“n”:3583,“o”:320.54,“t”:“2025-02-12T09:30:00Z”,“v”:117417,“vw”:321.741581},
{“c”:322.91,“h”:324.02,“l”:322.1,“n”:3007,“o”:322.1,“t”:“2025-02-12T09:35:00Z”,“v”:99529,“vw”:323.267087},
{“c”:323.54,“h”:324,“l”:322.96,“n”:1833,“o”:322.99,“t”:“2025-02-12T09:40:00Z”,“v”:55361,“vw”:323.646905},
{“c”:323.33,“h”:323.72,“l”:323,“n”:1522,“o”:323.5,“t”:“2025-02-12T09:45:00Z”,“v”:49154,“vw”:323.347665},
{“c”:322.89,“h”:323.61,“l”:322.8,“n”:1388,“o”:323.33,“t”:“2025-02-12T09:50:00Z”,“v”:31382,“vw”:323.220809},
{“c”:322.13,“h”:322.8,“l”:321.65,“n”:1964,“o”:322.7,“t”:“2025-02-12T09:55:00Z”,“v”:39595,“vw”:322.117709},
{“c”:321.38,“h”:322.45,“l”:321.38,“n”:1692,“o”:322.01,“t”:“2025-02-12T10:00:00Z”,“v”:42706,“vw”:321.807952},
{“c”:320.71,“h”:321.4,“l”:320.71,“n”:2292,“o”:321.39,“t”:“2025-02-12T10:05:00Z”,“v”:60426,“vw”:321.100408},
{“c”:321.75,“h”:321.83,“l”:320.72,“n”:1571,“o”:320.72,“t”:“2025-02-12T10:10:00Z”,“v”:45843,“vw”:321.187086},
{“c”:321.43,“h”:321.91,“l”:321.15,“n”:1338,“o”:321.88,“t”:“2025-02-12T10:15:00Z”,“v”:27968,“vw”:321.488923},

This is my URL that I use -

interval_period = ‘5min’
start_date = ‘2025-02-12’
end_date = ‘2025-02-12’
symbol = “TSLA”
base_url = ‘https://data.alpaca.markets/v2/stocks/bars

url = f’{base_url}?symbols={symbol}&timeframe={interval_period}&start={start_date}T09%3A30%3A00Z&end={end_date}T16%3A00%3A00Z&limit=1000&adjustment=split&feed=sip&sort=asc’

Why does the closing price values do not match?

@das.somik You noted that the Alpaca close prices don’t seem to match TradingView. The issue here is timezones. Note the Alpaca times are UTC (ie 2025-02-12T09:30:00Z) while the TradingView times are America/New_York EST which is ‘market time’ (ie 2025-02-12T09:30:00-05:00).

One should always use timezone aware datetimes and specify the timezone when using the Alpaca APIs otherwise they default to UTC. Data is always returned in UTC. I like using pandas when working with datetimes because of the robust handling of timezones. I also always work in ‘market time’ for consistency. Additionally, it’s generally not a good idea to hardcode times if using UTC since daylight saving time changes the market time offset between -04:00 and -05:00 depending upon the time of year. Simply let the pandas methods do all the offset and formatting for you.

So, maybe change your code to this and incorporate timezone handling

import pandas as pd

interval_period = ‘5min’

# enter the timezone naive times, localize those to market time
start_date = pd.to_datetime('2025-02-12 09:30’).tz_localize('America/New_York')
end_date = pd.to_datetime('2025-02-12 16:00’).tz_localize('America/New_York')

symbol = “TSLA”
base_url = ‘https://data.alpaca.markets/v2/stocks/bars’

# create the url. use the .isoformat() method to properly format the datetimes
url = f’{base_url}?symbols={symbol}&timeframe={interval_period}&start={start_date.isoformat()}&end={end_date.isoformat()}&limit=1000&adjustment=split&feed=sip&sort=asc’

You should then see the close prices match.

Thank you so much, that looks like a silly miss.