Created
November 15, 2019 19:12
-
-
Save PatrickAlphaC/8a18a81b9197a60ac5949b75d803e831 to your computer and use it in GitHub Desktop.
Data vendor comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You'll need 3 environment variables API keys to run this | |
# ALPHAVANTAGE_API_KEY | |
# INTRINIO_PROD_KEY | |
# IEX_TOKEN | |
# Sometimes the vendor will error out the API call and you'll have to call it again.... | |
from __future__ import print_function | |
import pandas as pd | |
import threading | |
import os | |
import time | |
# Alpha Vantge | |
from alpha_vantage.timeseries import TimeSeries | |
# IEX | |
from iexfinance.stocks import Stock | |
from iexfinance.stocks import get_historical_data | |
# Intrinio | |
import intrinio_sdk | |
from intrinio_sdk.rest import ApiException | |
# Alpha Vantage | |
ts = TimeSeries() | |
data_av, meta_data = ts.get_quote_endpoint('AAPL') | |
data_av_hist, meta_data_av_hist = ts.get_daily('AAPL') | |
av_list = [] | |
av_list.extend(("Alpha Vantage", '{0:.6}'.format(data_av['05. price']), '{0:.6}'.format(data_av_hist['2019-11-13']['1. open']))) | |
# IEX | |
iex_list = [] | |
data_iex = Stock('AAPL', output_format = 'json') | |
iex_list.extend(("IEX Cloud", '{0:.6}'.format(data_iex.get_quote()['latestPrice']), '{0:.6}'.format(get_historical_data("AAPL", start='20191113')['2019-11-13']['open']))) | |
# Intrinio | |
intrinio_sdk.ApiClient().configuration.api_key['api_key'] = os.getenv('INTRINIO_PROD_KEY') | |
security_api = intrinio_sdk.SecurityApi() | |
intro_list = [] | |
try: | |
data_intro = security_api.get_security_realtime_price("AAPL") | |
data_intro_hist = security_api.get_security_stock_prices("AAPL", start_date='2019-11-13', end_date='2019-11-13').stock_prices[0] | |
except ApiException as e: | |
print("Exception when calling SecurityApi->get_security_realtime_price: %s\n" % e) | |
intro_list.extend(("Intrinio", '{0:.6}'.format(data_intro.last_price), '{0:.6}'.format(data_intro_hist.open))) | |
data_combined = [av_list, iex_list, intro_list] | |
df = pd.DataFrame(data_combined, columns = ['Vendor', 'Current Price', 'Nov. 13th Open']) | |
print(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment