Financial Modeling Prep is a free API that can be used to access various financial metrics such as stock prices and cryptocurrency data. The API documentation outlines how to access data through programming languages like Python. In particular, for cryptocurrency data:
https://financialmodelingprep.com/developer/docs/#Historical-Cryptocurrencies-Price
One simply needs to generate a unique API key, and data can be accessed by calling a URL. The content of the URL is received and parsed as a JSON, and returned as an object in Python. For example, I can access all historical data of Bitcoin (price, volume, low, high, etc.):
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
import json
def get_jsonparsed_data(url):
response = urlopen(url)
data = response.read().decode("utf-8")
return json.loads(data)
url = ("https://financialmodelingprep.com/api/v3/historical-price-full/crypto/BTCUSD?apikey=myKey")
myData = get_jsonparsed_data(url)
By default, with this URL call the object contains all BTC data (1828 days worth, as of 1/18/21), with a time interval of 1 day. For example, using the Spyder variable explorer:
However, I want to improve my time resolution to 4 hours. The API documentation gives some insight on how to do this - just change url to the following:
url = ("https://financialmodelingprep.com/api/v3/historical-chart/4hour/BTCUSD?apikey=myKey")
The result is data for BTC sampled very 4 hours. However, there are only 200 data points, limiting the range of historical data:
After reviewing the documentation, it is unclear how to specify both the 4 hour interval as well as all historical data (so I'd get 6*1828 = 10968 data points). How can I get all data at the time interval of interest?