Skip to content

Instantly share code, notes, and snippets.

@vedranmarkulj
Last active February 22, 2018 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vedranmarkulj/172fbf9df1d280a16a9a0e50a7f252bd to your computer and use it in GitHub Desktop.
Save vedranmarkulj/172fbf9df1d280a16a9a0e50a7f252bd to your computer and use it in GitHub Desktop.
get_historical_data.py
import requests
import pandas as pd
class AlphaVantage:
def __init__(self, symbol_code, interval="60min", outputsize="compact"):
self.base_url = "https://www.alphavantage.co"
self.default_endpoint = "/query"
self.api_key = "<enter your API Key here>"
self.symbol_code = symbol_code
self.interval = interval
self.outputsize = outputsize
def intraday(self):
parameters = {
"function": "TIME_SERIES_INTRADAY",
"symbol": self.symbol_code,
"interval": self.interval,
"outputsize": self.outputsize,
"datatype": "json",
"apikey": self.api_key
}
response_intraday = requests.get("{0}{1}".format(self.base_url, self.default_endpoint), params=parameters, stream=True).json()
return response_intraday
def daily(self):
parameters = {
"function": "TIME_SERIES_DAILY",
"symbol": self.symbol_code,
"outputsize": self.outputsize,
"datatype": "json",
"apikey": self.api_key
}
response_daily = requests.get("{0}{1}".format(self.base_url, self.default_endpoint), params=parameters, stream=True).json()
return response_daily
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment