The marketstack is a lightweight, free, and easy-to-use REST API that aims to provide an interface to deliver worldwide stock market data. Using marketstack APIs, you can obtain real-time stock data for any ticker down to the minute, request intraday quotes, or search 30+ years of accurate historical market data. It is an easy-to-integrate API and covers the data from 70+ global stock exchanges.
In this blog post, we’ll explore the marketstack API and look at its different available options to access the stock market data. Another great API to pair with this API is an exchange rate API.
Table of Contents
How can I access end-of-day stock market data using marketstack API?
You can use the API’s eod
endpoint in order to obtain end-of-day data for one or multiple stock tickers. A single or multiple comma-separated ticker symbols are passed to the API using the symbols
parameter.
Python
1 2 3 4 5 6 7 8 9 10 11 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY' } api_result = requests.get('https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = AAPL', params) api_response = api_result.json() |
jQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$.ajax({ url: 'https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = AAPL', data: { access_key: 'YOUR_ACCESS_KEY' }, dataType: 'json', success: function(apiResponse) { if (Array.isArray(apiResponse['data'])) { // Your processing code here... } } }); |
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$queryString = http_build_query([ 'access_key' => 'YOUR_ACCESS_KEY' ]); $ch = curl_init(sprintf('%s?%s', 'https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = AAPL', $queryString)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $apiResult = json_decode($json, true); |
Can I get stock market data for intervals during the day?
In addition to daily end-of-day stock prices, the marketstack API also supports intraday data with data intervals as short as one minute. Intraday prices are available for all US stock tickers included in the IEX (Investors Exchange) stock exchange.
To obtain intraday data, you can use the API’s intraday
endpoint and specify your preferred stock ticker symbols.
Python
1 2 3 4 5 6 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY' } api_result = requests.get('https://api.marketstack.com/v1/intraday ? access_key = YOUR_ACCESS_KEY & symbols = AAPL', params) api_response = api_result.json() |
jQuery
1 2 3 4 5 6 7 8 9 10 11 12 |
$.ajax({ url: 'https://api.marketstack.com/v1/intraday ? access_key = YOUR_ACCESS_KEY & symbols = AAPL', data: { access_key: 'YOUR_ACCESS_KEY' }, dataType: 'json', success: function(apiResponse) { if (Array.isArray(apiResponse['data'])) { // Your processing code here... } } }); |
PHP
1 2 3 4 5 6 7 8 |
$queryString = http_build_query([ 'access_key' => 'YOUR_ACCESS_KEY' ]); $ch = curl_init(sprintf('%s?%s', 'https://api.marketstack.com/v1/intraday ? access_key = YOUR_ACCESS_KEY & symbols = AAPL', $queryString)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $apiResult = json_decode($json, true); |
What is an easy way to capture real-time stock market data updates?
For customers with an active subscription to the Professional Plan, the marketstack API’s intraday
endpoint is also capable of providing real-time market data, updated every minute, every 5 minutes, or every 10 minutes.
To obtain real-time data using this endpoint, simply append the API’s interval
parameter and set it to 1min
, 5min
or 10min
.
Python
1 2 3 4 5 6 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY' } api_result = requests.get('https://api.marketstack.com/v1/intraday ? access_key = YOUR_ACCESS_KEY & symbols = AAPL & interval = 1min', params) api_response = api_result.json() |
jQuery
1 2 3 4 5 6 7 8 9 10 11 12 |
$.ajax({ url: 'https://api.marketstack.com/v1/intraday ? access_key = YOUR_ACCESS_KEY & symbols = AAPL & interval = 1min', data: { access_key: 'YOUR_ACCESS_KEY' }, dataType: 'json', success: function(apiResponse) { if (Array.isArray(apiResponse['data'])) { // Your processing code here... } } }); |
PHP
1 2 3 4 5 6 7 8 |
$queryString = http_build_query([ 'access_key' => 'YOUR_ACCESS_KEY' ]); $ch = curl_init(sprintf('%s?%s', 'https://api.marketstack.com/v1/intraday ? access_key = YOUR_ACCESS_KEY & symbols = AAPL & interval = 1min', $queryString)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $apiResult = json_decode($json, true); |
How can I access historic stock market data using marketstack API?
Historical stock prices are available both from the end-of-day (eod
) and intraday (intraday
) API endpoints. To obtain historical data, simply use the date_from
and date_to
parameters as shown in the example request below.
Python
1 2 3 4 5 6 7 8 9 10 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY' } api_result = requests.get('https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = AAPL & date_from = 2021-07-08 & date_to = 2021-07-18', params) api_response = api_result.json() |
jQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$.ajax({ url: 'https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = AAPL & date_from = 2021-07-08 & date_to = 2021-07-18', data: { access_key: 'YOUR_ACCESS_KEY' }, dataType: 'json', success: function(apiResponse) { if (Array.isArray(apiResponse['data'])) { // Your processing code here... } } }); |
PHP
1 2 3 4 5 6 7 8 9 10 11 12 |
$queryString = http_build_query([ 'access_key' => 'YOUR_ACCESS_KEY' ]); $ch = curl_init(sprintf('%s?%s', 'https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = AAPL & date_from = 2021-07-08 & date_to = 2021-07-18', $queryString)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $apiResult = json_decode($json, true); |
How can I quickly access the stock market index data?
The API is also capable of delivering end-of-day for 750+ of the world’s major indices, including the S&P 500 Index, the Dow Jones Industrial Average Index as well as the NASDAQ Composite Index.
To list or access index data, simply pass INDX
as your stock exchange MIC identification, as seen in the examples below. The example API request below illustrates how to obtain end-of-day data for the DJI
market index.
Python
1 2 3 4 5 6 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY' } api_result = requests.get('https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = DJI.INDX', params) api_response = api_result.json() |
jQuery
1 2 3 4 5 6 7 8 9 10 11 12 |
$.ajax({ url: 'https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = DJI.INDX', data: { access_key: 'YOUR_ACCESS_KEY' }, dataType: 'json', success: function(apiResponse) { if (Array.isArray(apiResponse['data'])) { // Your processing code here... } } }); |
PHP
1 2 3 4 5 6 7 8 |
$queryString = http_build_query([ 'access_key' => 'YOUR_ACCESS_KEY' ]); $ch = curl_init(sprintf('%s?%s', 'https://api.marketstack.com/v1/eod ? access_key = YOUR_ACCESS_KEY & symbols = DJI.INDX', $queryString)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($ch); curl_close($ch); $apiResult = json_decode($json, true); |
As you can see, accessing stock market data with marketstack and using them in your applications is pretty simple and quick. Not only that, marketstack is reliable and easy on your budget to help you enable a diverse digital ecosystem that focuses on user experience. Moreover, the free plan of marketstack is an ideal choice for experimentation, trials, and proof of concepts.
Head over to marketstack and start exploring historic stock market data.