The MarketStack is a SaaS platform that provides real-time, intraday, historical stock market data via an API. The MarketStack is a product by apilayer team.
How to use MarketStack API
To use MarketStack API, you need to create an account on MarketStack. You can simply navigate to the sign up page and create a new free account.
Once you have created your account, MarketStack will generate an API key for you. Make sure that you don’t share it with unauthorized users.
Let’s call a simple API to observe how it works.
Here is a sample API to check various exchanges and their details around the world.
Once you hit the request, you should get the following response instantly.
"pagination": {
"limit": 100,
"offset": 0,
"count": 71,
"total": 71
},
"data": [
{
"name": "NASDAQ Stock Exchange",
"acronym": "NASDAQ",
"mic": "XNAS",
"country": "USA",
"country_code": "US",
"city": "New York",
"website": "www.nasdaq.com",
"timezone": {
"timezone": "America/New_York",
"abbr": "EST",
"abbr_dst": "EDT"
},
"currency": {
"code": "USD",
"symbol": "$",
"name": "US Dollar"
}
},
{
"name": "New York Stock Exchange",
"acronym": "NYSE",
"mic": "XNYS",
"country": "USA",
"country_code": "US",
"city": "New York",
"website": "www.nyse.com",
"timezone": {
"timezone": "America/New_York",
"abbr": "EST",
"abbr_dst": "EDT"
},
"currency": {
"code": "USD",
"symbol": "$",
"name": "US Dollar"
}
},
...
more data
...
]
}
Awesome. It works.
At present, MarketStack provides the following set of data.
- End-of-Day Data: Get daily stock market data.
- Intraday Data: Get intraday and real-time market data.
- Tickers: Get information about stock ticker symbols.
- Exchanges: Get information about all supported exchanges.
- Currencies: Get information about all supported currencies.
- Timezones: Get information about all supported timezones.
You can check out the documentation of MarketStack for more details.
Integrating with Node.js
Here is a sample code to Integrate MarketStack apis with Node.js.
First, install axios.
Replace the access key with your access key in the code shown below.
const params = {
access_key: 'YOUR_ACCESS_KEY'
}
axios.get('http://api.marketstack.com/v1/tickers/aapl/eod', {params})
.then(response => {
const apiResponse = response.data;
console.log(apiResponse);
}).catch(error => {
console.log(error);
});
Save the file and run the code using the following command.
You should the following output in the terminal.
MarketStack is really easy to use and provides a fast, JSON-based response. I highly recommend you give this SaaS platform a try.