How To Use the Stock Market API — With Examples!

Get real-time and historical market data from the stock market api. Learn quickly with easy to use examples that work right from your browser.

February 7, 2023
    Add a header to begin generating the table of contents

    Market Data’s Stock Market API offers both real-time and historical data for all stocks and ETFs traded on U.S. markets. Real-time prices are available using our stock quote endpoint. This endpoint will deliver a full top of book level 1 real-time stock quote. If historical data is what you’re after, you can get historical candlestick data (perfect for charting) using our stock candles endpoint. The candles endpoint is compatible with the TradingView Technical Analysis Charting Library.

    You can experiment on our all Stock Market APIs using the AAPL ticker without any need for registration or authentication. The API will respond to all queries as if you were authenticated. Feel free to try any of the examples below by clicking on them and seeing the output in your browser.

    Throughout this example, we’ll add the dateformat=timestamp parameter to each link so that you can click the examples and read the dates & times in human-readable format. However, the default date/time output of the API is unix format. Omit the dateformat=timestamp parameter and you can see the output in seconds after the Unix epoch.

    Getting Live Stock Data from the API

    Live stock market data is available via the quotes API. This API endpoint will fetch a real-time top of book level 1 stock quote for all U.S.-traded stocks and ETFs. By default, both bid, ask, mid, and last prices are displayed. You can control for latency by using the timestamp of the quote. Please note that only users on paid plans will receive real-time data from the API.

    Example: https://api.marketdata.app/v1/stocks/quotes/AAPL/

    Getting Historical Stock Data from the API

    If you need historical candlestick data, use this candles API endpoint. It will return OHLCV candles at whatever resolution you need, as small as 1 minute through monthly. This endpoint provides historical candles only up through the previous trading day.

    Read our in-depth tutorial How To Use The Historical Stock Data API for complete details on how to add from and to parameters, filter, sort and limit the data.

    Using The Stock Market API For Free

    If you are looking for free data to get started quickly and inexpensively, we recommend you take advantage of our trial offer. Sign-up for a 30 day free trial of either our Starter or Trader plans and get 10,000 or 50,000 daily API calls for free with no credit card needed.

    If you don’t have a large need for data, you can also use the Free Forever plan and get 100 daily API calls for life.

    Share This Tutorial

    Comments & Questions