Jordan Uses MarketStack
Tags: apilayer, axios, javascript, marketstack
Published: 2020-07-21 11:46:57

---
title: Jordan Uses MarketStack
published: true
date: 2020-07-13 20:50:00 UTC
tags: apilayer,Axios,Javascript,marketstack
canonical_url: https://javascriptwebscrapingguy.com/jordan-uses-marketstack/?utm_source=rss&utm_medium=rss&utm_campaign=jordan-uses-marketstack
---

[Demo code here](https://github.com/aarmora/jordan-uses-marketstack)

_This is a sponsored blog post by marketstack. All reviews and opinions expressed here are, however, based on my personal experience_.

This is my fifth post about APIs created by [apilayer](https://apilayer.com/). The other four were for [scrapestack](https://javascriptwebscrapingguy.com/jordan-scrapes-with-scrapestack/) (for proxying any and all web requests), [serpstack](https://javascriptwebscrapingguy.com/serpstack-easy-search-engine-results/) (for getting search engine results in a quick and easy JSON format), [positionstack](https://javascriptwebscrapingguy.com/jordan-uses-positionstack/) (geocode location), and [aviationstack](https://javascriptwebscrapingguy.com/jordan-uses-aviationstack/) (tracking real time flight data). I’m still really impressed with their APIs, with full featured documentation on their marketstack product [here](https://marketstack.com/documentation).

## Stocks!

![funny gif stock going up](https://media.giphy.com/media/1AjFk7MzJBT2UPYKLB/giphy.gif)

Marketstack is a great way to avoid the above gif. You don’t have to sit there watching the stock change. Now you can watch it change with the flick of your keyboard! In this post I’m going to go through some of the items that are supposed on all plans of marketstack but data intervals as short as one minute are available! Marketstack supports both [realtime](https://marketstack.com/documentation#realtime_updates) and [intraday](https://marketstack.com/documentation#intraday_data).

![marketstack intraday](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/07/image-6.png)

The first call I looked at was the [basic end of day request](https://marketstack.com/documentation#eod_data). The only required items are your api key (get it [here](https://marketstack.com/)) and the stock symbol. In my examples I used both Apple (APPL) and Lenovo (LNVGY). My function call looks like this:

```
async function basicEod(symbol: string) {
	const baseUrl = `http://api.marketstack.com/v1/eod?access_key=${process.env.marketStackApiKey}`;

	// Call for apple stock eod of day
	const axiosResponse = await axios.get(`${baseUrl}&symbols=${symbol}`);

	const appleData = axiosResponse.data;

	console.log('Apple data from basic EOD call', appleData.data.length, appleData.data[0], appleData.pagination);

	return axiosResponse.data;

}
```

And then the response looks like this:

![marketstack basic eod response](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/07/image-7.png)

I’m logging out both the first value (which is yesterday’s data) and the pagination object. You can offset or change your limit by just passing in limit or offset query parameters. Crazy easy!

I am also able to just update my url with `latest` and it’ll only return the most recent day.

```
`http://api.marketstack.com/v1/eod/latest?access_key=${process.env.marketStackApiKey}`
```

I’m not sure what the limit is on the history. You can see in the screenshot above that there are a total of 253 days of history for Apple. The response from Lenovo looks like this:

![market stack eod lenovo response](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/07/image-8.png)

Here it shows there is only a total of 20 results. This is something I’d have to use more to figure the differences.

## Tickers and Exchanges

![fun gif stock market](https://media.giphy.com/media/AgHBbekqDik0g/giphy.gif)

Marketstack also includes an API to be able to access ticker data. This allows you to look up information about one or multiple stock ticker symbols. The code:

```
async function tickers(symbol: string) {
	const url = `http://api.marketstack.com/v1/tickers/${symbol}?access_key=${process.env.marketStackApiKey}`;

	// Call for apple stock ticker
	const axiosResponse = await axios.get(url);

	const tickerData = axiosResponse.data;

	console.log(`${symbol} data from ticker`, tickerData);

}
```

And the response:

![lenovo ticker data from marketstack](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/07/image-9.png)

On to this ticker you can add pieces on to the url for extra data like end of day or intraday day. It would look something like this:

```
// EOD
`http://api.marketstack.com/v1/tickers/${symbol}/eod?access_key=${process.env.marketStackApiKey}`

// Intraday
`http://api.marketstack.com/v1/tickers/${symbol}/intraday?access_key=${process.env.marketStackApiKey}`
```

Exchanges is the final part of marketstack that I’m going to cover today. It returns any of the 72+ stock exchanges supported by marketstack. Like all of the other calls, this one is extremely simple:

```

async function exchanges() {
	const url = `http://api.marketstack.com/v1/exchanges?access_key=${process.env.marketStackApiKey}`;

	// Call for apple stock ticker
	const axiosResponse = await axios.get(url);

	const exchangesData = axiosResponse.data;

	console.log(`Data from exchanges`, exchangesData.data.length, exchangesData.data[0], 'Pagination', exchangesData.pagination);

}
```

And part of the response looks like this:

![](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/07/image-10.png)

I think the symbol and ticker data is maybe the more valuable one but I don’t know all of the possible uses. The awesome thing is that it’s super easy to access and use.

If you have any interested in being able to programmatically access stock market data, marketstack is what you need.

[Check it out!](https://marketstack.com)

The post [Jordan Uses MarketStack](https://javascriptwebscrapingguy.com/jordan-uses-marketstack/) appeared first on [JavaScript Web Scraping Guy](https://javascriptwebscrapingguy.com).