You've successfully subscribed to Alpaca Learn | Developer-First API for Crypto and Stocks
Great! Next, complete checkout for full access to Alpaca Learn | Developer-First API for Crypto and Stocks
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.
Search
Broker API

Add market data to your trading app with Alpaca Market Data API

Alpaca Team
Alpaca Team

Following the release of Ribbit, we’ve discussed constructing an app’s onboarding, funding, and trading flows using the Broker API. Here, we’ll explore another foundational feature: market data. We’ll chat briefly about our Market Data API and then use Ribbit to demonstrate powering the UI from it.


Ribbit Recap

With any type of product, from ideation to implementation, there are countless steps and tasks that need to be completed to successfully launch. This can get even more complicated when building a financial related app as there are strict regulations and laws that you need to be compliant with. Our Broker API was designed to simplify this process as it offers everything you need to get your trading app launched right away! We even took it one step further and created Ribbit to help you speed up your app development and help you focus on getting your app out to users. Ribbit is an open source commission-free trading app built on the Alpaca Broker API to demonstrate just how easy it is to build a fully functional trading app using our products. Built as a reference implementation, you can check out the frontend code for iOS and Android and the backend code written in Go.

Alpaca Market Data API

We’ve made it easy for you to provide your customers with real-time and historical market data using Alpaca Market Data API. We offer two subscription plans, the Free Plan and the Unlimited Plan. The specifics of each will vary and are detailed in the subscription plans section of our documentation. Your Broker API key and secret will allow you to authenticate to the Market Data API’s REST endpoints and websocket.

How does Ribbit use it?

Ribbit uses the historical data endpoints to retrieve values for populating charts and price fields. While we refer to these operations as historical they can be used to retrieve near real-time data. Through the /latest and /snapshot routes, users of either subscription plan can obtain the most recent data we have from the exchanges covered by their plan type. The historical endpoints are sufficient for many applications and the websocket provides added flexibility to build features reliant on streams of real-time data, such as price alerts. While use of the websocket isn’t on display in Ribbit’s current form, keep it in mind as an implementation option when thinking about new features.

Let’s see it in action!

GET /v2/stocks/{symbol}/snapshot consolidates the latest trade, latest quote, as well as minute, daily, and previous daily bars into a single operation. GET /v2/stocks/snapshots extends this by accepting a comma-delimited list of symbols as a query parameter. Ribbit uses this endpoint to retrieve snapshot data for all of the symbols on the Favorite Stocks list. Snapshots’ {symbol}.latestTrade.p values are then used to populate the stock prices found on the dashboard and the My Profile screen.

Tapping the Search icon followed by searching and selecting a symbol will bring you to a stock detail view. Here, snapshots’ dailyBar’s o, h, l, and v values are used to populate the Statistics fields.

You’ll also find a line chart with selectable ranges from one day (1D) to five years (5Y). Each of the ranges ultimately call GET /v2/stocks/{symbol}/bars for data, varying the values passed in the timeframe and start query parameters. The o values of the bars in the response are used to render the chart with the appropriate x-axis indices for the chosen range.

What’s next?

Having now learned the basics of using our Market Data API in an app, you’re ready to give it a try! We have many more features in the Broker API and encourage you to learn about them and use them to create your own innovative and delightful experiences for your customers.  

As an API-first product company, we are committed to providing the best developer experience. If you have feedback or questions, don’t hesitate to get in touch at [email protected] or @AlpacaHQ on Twitter.


Commission-Free trading means that there are no commission charges for Alpaca self-directed individual cash brokerage accounts that trade U.S. listed securities through an API. Relevant SEC and FINRA fees may apply.

Please note that this code is for example use only and is not intended to be used for distribution. The code is provided as an open-source for the purpose of demonstration of the Broker API usage. It is not designed for production use and Alpaca does not offer official support of the code.

This article is for educational and informational purposes only. All screenshots are for illustrative purposes only. Alpaca does not recommend any specific securities or investment strategies. Brokerage services are provided by Alpaca Securities LLC ("Alpaca"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.

Interested in learning more about Broker API?

Don't miss out on any updates about our Broker API suite of solutions! Share your details with us and be the first to know about our latest content.

Broker API

Alpaca Team

API-first stock brokerage. *Securities are offered through Alpaca Securities LLC* http://alpaca.markets/#disclosures