Learning to pull Simple market Data

Hi I am brand new to Alpaca and I’m having a really rough time pulling market data using python, I was wondering if someone could help me with an example. I’m still confused as to how API’s work completely so I’m lost as per usual. A super simple example that I could dissect would be awesome. (market data meaning historical data). THANK YOU!

First, welcome to Alpaca!

I strongly recommend first working in an interactive environment like Jupyter notebooks. The interaction gives a much better ‘feel’ for how the API’s work. Better yet, use Google Colab. It’s free, all you need is a browser, and you won’t have issues with getting all the modules to play together nicely like one often does in a local install. Even if one does get things ‘confused’ it’s a simple matter of opening a new notebook and you are back to a clean slate. There is a good tutorial for how to set that up here. If you have a browser, you can be up and running in 5 minutes.

If you just want to get to work, and you already know Python, follow the tutorial linked above. That installs some python code (ie the alpaca-trade-api package) which defines ‘wrappers’ for all the API calls. One doesn’t really need to understand the API calls -just use the methods and functions included in that package. There are examples of placing orders, getting account info, and fetching stock data.

To better understand how to format the actual APIs, I would recommend using a tool like Postman. It allows you to enter an API ‘endpoint’ along with its various parameters. It then formats the HTTP string which are the GET and POST API commands. The python wrappers do the same thing but Postman allows you to visually see the actual API strings. There is a good tutorial for how to set up Postman here.

1 Like

AWESOME! thank you so much!

hi Dylan, I just figured out how to do this yesterday, without downloading the python client, so if you’re still interested in that route, try Python requests (easy to google/learn HTTP library) along with this endpoint to get started:

https://data.alpaca.markets/v2/stocks/{symbol}/bars?start={start_date}&end={end_date}&timeframe=1Day

replace {example} with your dates, symbol

Note dates should look like YYYY-MM-DD and you can add time info later if needed. The docs state that 1Min and 1Hour are also available, but I can’t get 1Hour to work unfortunately.

cheers