Where do I find historical intraday data for stocks ?

Bel Quanzo
4 min readJul 5, 2020

--

While it is relatively easy these days to find historical end-of-day data for markets analysis and strategy purposes, this is not the case for intraday historical data. I tried a lot of data providers among others but i was never satisfied, because often: the data is not complete, the timings intervals were fixed (5mn, 15mn, etc), not all markets (no forex or crypto) are available, only the US markets… I kept my pain in patience until recently I made a phenomenal discovery by a tweet.

Indeed, I came across an API called Quotient which loudly proclaims to whoever wants to hear it, that it can provide: historical intraday (1-min) data, historical end of day data, live market prices, options data, trading signal, financial data and much more on various assets (Stocks, ETFs, Funds, Indices, Forex, Cryptocurrencies, etc) on worldwide stock exchanges (us, canada, australia, uk and europe). And as if that were not enough, it also provides data on earnings, dividends, splits and many other information.

The most in this pleasant discovery is that the API is hosted on the rapidapi. We can therefore directly test the endpoints of this API through the graphical interface (as you can see below) to make our own opinion on Quotient API.

intraday historical data
intraday historical data

I admit that I quickly fell in love with this API. So I signed up for a full access plan and got my key to call the API from code (which I will show you right away) or from Excel to do my core business: analyzing, finding and optimizing strategies for the markets.

Below, I’m going to show you how, once subscribed to Quotient API and obtained your key, use it with Python to pull intraday data and plot it.

For illustration purpose, i will choose as input data:
symbol : QCOM
from: 2019–07–02 09:30
to: 2019–07–02 16:01
intervals(min) : 1, …, 5, 15, 30, … (you can set at 1-min level)

We will first import the necessary packages and set our preferred plotting style :

import requests
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
%matplotlib inline
plt.style.use('seaborn')

Then we will initialize our data as defined above and enter the API key (Remember to replace with your own API key for Quotient)

symbol = "QCOM"
start_date = "2019-07-02 09:30"
end_date = "2019-07-02 16:01"
api_key = "YOUR-API-KEY-GOES-HERE"

Once our input data initialized, then we will going to define a small function which we will call ‘get_intraday_data’ which will pull the data for us from Quotient API.

def get_intraday_data(symbol, start_date, end_date, interval):
url = "https://quotient.p.rapidapi.com/equity/intraday"
querystring = {
"symbol": symbol,
"from": start_date,
"to": end_date,
"interval": interval,
"adjust": "false"
}
headers = {
'x-rapidapi-host': "quotient.p.rapidapi.com",
'x-rapidapi-key': api_key
}


response = requests.request("GET", url, headers=headers, params=querystring)

df=pd.DataFrame(response.json())
df = df.set_index(pd.DatetimeIndex(df['Date']))
del df['Date']
df = df.sort_index()
df['Volume'] = df['Volume'].str.replace(',', '').astype(float)
df = df[['Open', 'High', 'Low', 'Close', 'Volume']].apply(pd.to_numeric)

return df

We will use this function which we will call for the three types of interval chosen previously (5, 15, 30 min) and save in three different dataframes df5, df15 and df30.

df5 = get_intraday_data(symbol, start_date, end_date, interval=5)
df15 = get_intraday_data(symbol, start_date, end_date, interval=15)
df30 = get_intraday_data(symbol, start_date, end_date, interval=30)

We can inspect the data obtained from the API, as follows:

df5.head()
intraday historical data
df5.tail()
intraday historical data

Now that we have the data, we just have to plot the closing price for these three different dataframes df5, df15 and df30.

fig, ax = plt.subplots(nrows=3, ncols=1, figsize=(12,8))
ax[0].plot(df5.index, df5['Close'], color='green', label='%s (5-min)' % (symbol))
ax[1].plot(df15.index, df15['Close'], color='red', label='%s (15-min)' % (symbol))
ax[2].plot(df30.index, df30['Close'], color='blue', label='%s (30-min)' % (symbol))
ax[0].xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))
ax[1].xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))
ax[2].xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))
ax[0].grid(True)
ax[1].grid(True)
ax[2].grid(True)
ax[0].set_ylabel('Price ($)')
ax[1].set_ylabel('Price ($)')
ax[2].set_ylabel('Price ($)')
ax[0].legend()
ax[1].legend()
ax[2].legend()
plt.tight_layout()
plt.show()
intraday historical data

Hopefully, this little post will help some who are looking for an API to get intraday historical data.

--

--

Bel Quanzo
Bel Quanzo

No responses yet