Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Created November 15, 2019 19:12
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 PatrickAlphaC/8a18a81b9197a60ac5949b75d803e831 to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/8a18a81b9197a60ac5949b75d803e831 to your computer and use it in GitHub Desktop.
Data vendor comparison
# 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