I am learning to use Alpaca. I am trying to get the trading volume per day of AAPL. Apple has a daily trading volume of around 50 million. However, when I use StockBarsRequest, I am consistently seeing the trading volume hover between the 1000s and 10000s. Why is this data incorrect?
Here is my code.
stock_bar_req = StockBarsRequest(symbol_or_symbols=['AAPL'], timeframe=TimeFrame.Minute, limit = 100000,
start=datetime(2015, 7, 1), end = datetime(2022, 7, 1), feed="iex")
bars = client.get_stock_bars(stock_bar_req)
for i in bars['AAPL'][:-1]:
Because you have to pay to get SIP real time data, I would suggest using a different data provider unless you want to pay them 100 USD a month for their data.
Your comment makes no sense. I am not asking about real time data. I am asking why the historical data is not anywhere near the correct historical daily volume.
It makes sense: It is the same in trading view: unless you don’t have the best data bought you only get historic data from IEX in Alpaca, which is a thinly traded. This accounts for historic and real time data.
Ok I see, it’s not really related to whether the data is historical or not but each exchange has different volume.
@Lama If you change the feed from
sip you will see the full consolidated market volumes (and not just the IEX exchange volumes). Ensure you set the adjustment to either
split depending upon what you are trying to do.
Switch “iex” to “sip” gives me trade volume per day in the 200,000’s. Why is it not in the millions if it’s the consolidated market volume?
@Lama The daily volume for AAPL is in the millions when specifying
sip as the feed. Here is a sample query
from alpaca.data.timeframe import TimeFrameUnit
from alpaca.data import StockHistoricalDataClient, TimeFrame, TimeFrameUnit
from alpaca.data.requests import StockBarsRequest
data_client = StockHistoricalDataClient(ALPACA_API_KEY_ID, ALPACA_API_SECRET_KEY,)
symbols = 'AAPL'
start_time = pd.to_datetime("2023-07-05T00:00:00").tz_localize('America/New_York')
end_time = pd.to_datetime("2023-07-06T16:00:00").tz_localize('America/New_York')
request = StockBarsRequest(symbol_or_symbols=symbols,
bars = data_client.get_stock_bars(request).df
And here is the result
Not sure what you were seeing?