How to do multi-symbol market data request

Hi,

On the API document, it said “Aside from the actual data contents, Alpaca Data API, which uses IEX, provides more flexible query capability such as multi-symbol and precise time range parameters.”. Anyone has examples how to request multi-stocks market data in one API request?

BTW, is the Polygon streaming free for Alpaca customers?

Thanks.

I’m not sure what language you’re coding with, but here is an example using python and pandas.

You can just send multiple symbols as a list.

EXAMPLE:

import alpaca_trade_api as tradeapi
api = tradeapi.REST()

symbols = [‘FB’,‘AMZN’,‘AAPL’,‘NFLX’,‘GOOG’]

stock_df = api.get_barset(symbols, ‘5Min’, limit=20).df

Thank you very much. I am using VB/VBA. Do you know where I can find details about the API like GET/POST/REST input & output formats instead of using defined libraries? Such that I can implement the program in VB/VBA.

Since its using rest you can just comma delimit the Symbols in your request like so:

GET /v1/bars/minute?symbol=ATUS,AMZN,CMCSA

Thank you. That’s very helpful. Do you know how many stocks can be queried in one request?

I tried https://data.alpaca.markets/v1/?symbol=MSFT not work. It returns end point not found error. Is it something incorret?

Did a research, seems the API does not have real time stock data. The market data API only provides aggregated data like bars. Is it correct that except WebSocket streaming, there is not API to provide real time stock data?

2 Likes

Hey @ZZook2
I tried the following

headers = {}
headers['APCA-API-KEY-ID'] = os.environ.get('APCA_API_KEY_ID')
headers['APCA-API-SECRET-KEY'] = os.environ.get('APCA_API_SECRET_KEY')
headers['User-Agent'] = 'APCA-TRADE-SDK-PY/' + __version__

market_data_base_url = "https://data.alpaca.markets"
test_string = "/v1/bars/minute?symbol=ATUS,AMZN,CMCSA"
full_url_v1 = market_data_base_url + test_string
res = requests.get(full_url_v1, headers=headers)
pprint(res.json())

But got the following error:
➜ Alpaca_Trader git:(master) ✗ python3 test_get_barset.py
{‘code’: 42210000, ‘message’: ‘at least one symbol is required’}
Could you please advise on if my test_string is correct? Thank you!

It looks like it’s not seeing the symbol param you are passing let me review on my end

1 Like