Delayed Trade Data

Hi Alpaca Team,

I love your API however I’m having some issue with it. I’m seeing that some tickers are not real time. They are in fact delayed. Most likely i’m implementing the StockHistoricalDataClient or OptionHistoricalDataClient wrong.

I implemented two above clients like this:

from alpaca.data.historical import StockHistoricalDataClient
from alpaca.data.historical import OptionHistoricalDataClient

stock_client = StockHistoricalDataClient(api_key=config[‘alpaca’][‘key’], secret_key=config[‘alpaca’][‘secret’])

latest_snapshot_request = StockSnapshotRequest(symbol_or_symbols = tickers_for_snapshot,feed=DataFeed.SIP)
#Rest of the workflow

option_client = OptionHistoricalDataClient(api_key=config[‘alpaca’][‘key’], secret_key=config[‘alpaca’][‘secret’])
#Rest of the workflow

In my test box the configuration has API KEY/SECRET generated under the Paper Trading account and in my Live box I have it pointing to a config where API KEY/SECRET is generated under the live account.

I’m not using the sandbox: bool = False explicitly in either of the handlers above but it seems like it’s working seamlessly between test and live account. This is where I got the idea of the sandbox parameter

Question: Is the right approach or do I need to explicitly change sandbox = False or True based on the test vs live machine to get real time data?

The ticker in question is : VTI

Thanks

@lracerk What makes you feel you are getting "delayed trade data”? I run the following code and it returns the following results:

!pip install -q alpaca-py

from alpaca.data import StockHistoricalDataClient
from alpaca.data.requests import StockSnapshotRequest
from alpaca.data.enums import DataFeed

# keys for any of your paper or live accounts. They all will return identical data. 
# Replace with your own keys.
API_KEY = 'xxxxx'
SECRET_KEY = 'xxxxx'

data_client = StockHistoricalDataClient(api_key=API_KEY, secret_key=SECRET_KEY)

tickers_for_snapshot = 'VTI'

latest_snapshot_request = StockSnapshotRequest(symbol_or_symbols=tickers_for_snapshot, feed=DataFeed.SIP)
latest_snapshot = data_client.get_stock_snapshot(latest_snapshot_request)

These are the results, which at the time I ran this seemed exactly as expected for real time data.

{'VTI': {   'daily_bar': {   'close': 338.84,
                      'high': 339.6084,
                      'low': 337.85,
                      'open': 338.0,
                      'symbol': 'VTI',
                      'timestamp': datetime.datetime(2026, 1, 5, 5, 0, tzinfo=TzInfo(0)),
                      'trade_count': 157508.0,
                      'volume': 5439454.0,
                      'vwap': 338.884395},
     'latest_quote': {   'ask_exchange': 'P',
                         'ask_price': 338.81,
                         'ask_size': 40.0,
                         'bid_exchange': 'P',
                         'bid_price': 338.6,
                         'bid_size': 40.0,
                         'conditions': ['R'],
                         'symbol': 'VTI',
                         'tape': 'B',
                         'timestamp': datetime.datetime(2026, 1, 6, 0, 59, 0, 104850, tzinfo=TzInfo(0))},
     'latest_trade': {   'conditions': [' ', 'M'],
                         'exchange': 'P',
                         'id': 52983627658808,
                         'price': 338.84,
                         'size': 65323.0,
                         'symbol': 'VTI',
                         'tape': 'B',
                         'timestamp': datetime.datetime(2026, 1, 6, 1, 0, 0, 17735, tzinfo=TzInfo(0))},
     'minute_bar': {   'close': 338.77,
                       'high': 338.78,
                       'low': 338.77,
                       'open': 338.78,
                       'symbol': 'VTI',
                       'timestamp': datetime.datetime(2026, 1, 6, 0, 45, tzinfo=TzInfo(0)),
                       'trade_count': 7.0,
                       'volume': 313.0,
                       'vwap': 338.774898},
     'previous_daily_bar': {   'close': 336.31,
                               'high': 337.741,
                               'low': 334.6,
                               'open': 337.15,
                               'symbol': 'VTI',
                               'timestamp': datetime.datetime(2026, 1, 2, 5, 0, tzinfo=TzInfo(0)),
                               'trade_count': 163696.0,
                               'volume': 5177288.0,
                               'vwap': 336.110041},
     'symbol': 'VTI'}}

What method are you calling and what results are you getting? What makes you feel the data is delayed?

1 Like

Thanks Dan for getting back on this. I am definitely mistaken. I did a more granular look and it appears the mismatch I saw was was between different trade prints. We can close this as solved.

Thanks

import configparser
from alpaca.data import StockHistoricalDataClient
from alpaca.data.requests import StockSnapshotRequest
from alpaca.data.enums import DataFeed
import time
from datetime import datetime, timezone
from zoneinfo import ZoneInfo

config = configparser.ConfigParser()  # Load configs for the app
config.read("resources/config.ini")

# keys for any of your paper or live accounts. They all will return identical data. 
# Replace with your own keys.
API_KEY = config['alpaca']['key']
SECRET_KEY = config['alpaca']['secret']

data_client = StockHistoricalDataClient(api_key=API_KEY, secret_key=SECRET_KEY)

tickers_for_snapshot = 'VTI'
latest_snapshot_request = StockSnapshotRequest(symbol_or_symbols=tickers_for_snapshot, feed=DataFeed.SIP)
for i in range(0, 60):
    latest_snapshot = data_client.get_stock_snapshot(latest_snapshot_request)
    yesterday = latest_snapshot[tickers_for_snapshot].previous_daily_bar.close
    latest_trade = latest_snapshot[tickers_for_snapshot].latest_trade.price
    latest_trade_datetime = latest_snapshot[tickers_for_snapshot].latest_trade.timestamp #UTC
    latest_trade_datetime = latest_snapshot[tickers_for_snapshot].latest_trade.timestamp.astimezone(tz=ZoneInfo("America/New_York")) #NY
    # latest_trade_datetime = latest_trade_datetime.replace(tzinfo=None) #AGNOSTIC
    print(f"Trade DateTime:{latest_trade_datetime:'%Y-%m-%dT%I:%M:%S %p'} | Last Trade {latest_trade}, {latest_trade/yesterday-1 : .2%}")
    time.sleep(1)
1 Like