Loading repository data…
Loading repository data…
alexanu / repository
An Opinionated AlphaVantage API Wrapper in Python 3.7. FREE API Key: https://www.alphavantage.co/support/
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
An Opinionated AlphaVantage API Wrapper in Python 3.7
Access to the AlphaVantage requires a free API key, that can be found at http://www.alphavantage.co/support/#api-key.
This API was designed to simplify the process of aquiring free financial data for retail traders and investors from the financial markets. While it does require Pandas, Pandas' methods help simplify saving data requests into a variety of file formats such as: csv (default), json, pkl, html, and txt. If the openpyxl module is also installed, it can be saved as an Excel file: xlsx.
pip install pandas
pip install alphaVantage-api
pip install alphaVantage-api openpyxl
git clone https://github.com/twopirllc/AlphaVantageAPI.git
pip install -e alphaVantage-api
api_key: str = None
premium: bool = False
output_size: str = 'compact'
datatype: str = 'json'
export: bool = False
export_path: str = '~/av_data'
output: str = 'csv'
clean: bool = False
proxy: dict = {}
from alphaVantageAPI.alphavantage import AlphaVantage
# Initialize the AlphaVantage Class with default values
AV = AlphaVantage(
api_key=None,
premium=False,
output_size='compact',
datatype='json',
export=False,
export_path='~/av_data',
output='csv',
clean=False,
proxy={}
)
# Your FREE API calls are throttled by 15.01 seconds.
AV = AlphaVantage(premium=False)
# No API call throttling.
AV = AlphaVantage(premium=True)
# Cleans and save requests to the default export_path in 'csv' format
AV = AlphaVantage(export=True, output='csv', clean=True)
print(AV)
# Help: lists all the functions and indicators AlphaVantage API supports
AV.help()
# Print 'function' aliases
AV.help('aliases')
# Help with a specific API function
AV.help('TIME_SERIES_DAILY')
# Help with an indicator
AV.help('BBANDS')
found_symbol = AV.search('AA')
# Global Quote
quote_df = AV.global_quote('MSFT')
# Sectors
sectors_df = AV.sectors()
# FX / Currency
usd_cad_rate_df = AV.fxrate(from_currency='USD', to_currency='CAD') # Rate
usd_cad_I5_df = AV.fx(from_currency='USD', to_currency='CAD', function='FXI', interval=5) # Intraday as int
usd_cad_I60_df = AV.fx(from_currency='USD', to_currency='CAD', function='FXI', interval='60min') # Intraday as str
usd_cad_D_df = AV.fx(from_currency='USD', to_currency='CAD', function='FXD') # Daily
usd_cad_W_df = AV.fx(from_currency='USD', to_currency='CAD', function='FXW') # Weekly
usd_cad_M_df = AV.fx(from_currency='USD', to_currency='CAD', function='FXM') # Monthly
## Digital/Crypto
btc_usd_I5_df = AV.digital(symbol='BTC', market='USD', function='CI', interval=5) # Intraday as int
btc_usd_I60_df = AV.digital(symbol='BTC', market='USD', function='CI', interval='60min') # Intraday as str
btc_usd_D_df = AV.digital(symbol='BTC', market='USD', function='CD') # Daily
btc_usd_W_df = AV.digital(symbol='BTC', market='USD', function='CW') # Weekly
btc_usd_M_df = AV.digital(symbol='BTC', market='USD', function='CM') # Monthly
## Generic Equity/ETF calls
msft_I5_df = AV.intraday(symbol='MSFT', interval=5) # Intraday as int
msft_I60_df = AV.intraday(symbol='MSFT', interval='60min') # Intraday as str
msft_D_df = AV.data(symbol='MSFT', function='D') # Daily
msft_DA_df = AV.data(symbol='MSFT', function='DA') # Daily Adjusted
msft_W_df = AV.data(symbol='MSFT', function='W') # Weekly
msft_WA_df = AV.data(symbol='MSFT', function='WA') # Weekly Adjusted
msft_M_df = AV.data(symbol='MSFT', function='M') # Monthly
msft_MA_df = AV.data(symbol='MSFT', function='MA') # Monthly Adjusted
# List of symbols Daily
symbols = ['AAPL', 'MSFT', 'XLK']
tech_list = AV.data('D', symbols) # returns list of DataFrames
## Indicators
# SMA(close, 20)
msft_SMA_20_df = AV.data(symbol='MSFT', function='SMA', series_type='close', time_period=20)
# STOCH(close)
msft_STOCH_df = AV.data('STOCH', symbols[1], interval='daily', series_type='close')
# Returns all successfull calls to the API
history_list = AV.call_history()
# Pretty display of Call History
history_df = pd.DataFrame(history_list)[['symbol', 'function', 'interval', 'time_period']]
print(history_df)
For simplicity and protection of your AV API key, the extension uses the environment variable AV_API_KEY upon import of the module.
import pandas as pd
import alphaVantageAPI
Since 'av' is an extension of a Pandas DataFrame, we need a DataFrame to work from. Simply create an empty DataFrame, it's contents will be replaced anyhow.
e = pd.DataFrame()
# Help: lists all the functions and indicators AlphaVantage API supports
e.av.help()
# Print 'function' aliases
e.av.help('aliases')
# Help with a specific API function
e.av.help('TIME_SERIES_DAILY')
# Help with an indicator
e.av.help('BBANDS')
found_symbol = e.av.search('AA')
# Global Quote
quote_df = e.av.global_quote('MSFT')
# Sectors
sectors_df = e.av.sectors()
# FX / Currency
usd_cad_rate_df = e.av.fx('USD', to_currency='EUR')
usd_cad_I5_df = e.av.fx_intraday('USD', to_currency='EUR', interval=5) # Intraday as int
usd_cad_I60_df = e.av.fx_intraday('USD', to_currency='EUR', interval='60min') # Intraday as str
usd_cad_D_df = e.av.fx_daily('USD', to_currency='EUR') # Daily
usd_cad_W_df = e.av.fx_weekly('USD', to_currency='EUR') # Weekly
usd_cad_M_df = e.av.fx_monthly('USD', to_currency='EUR') # Monthly
## Digital/Crypto
btc_usd_I5_df = e.av.digital_intraday('BTC', market='USD', interval=5) # Intraday as int
btc_usd_I60_df = e.av.digital_intraday('BTC', market='USD', interval='60min') # Intraday as str
btc_usd_D_df = e.av.digital_daily('BTC', market='USD') # Daily
btc_usd_W_df = e.av.digital_weekly('BTC', market='USD') # Weekly
btc_usd_M_df = e.av.digital_monthly('BTC', market='USD') # Monthly
## Equities/ ETFs
msft_I5_df = e.av.intraday('MSFT', interval=5) # Intraday as int
msft_I60_df = e.av.intraday('MSFT', interval='60min') # Intraday as str
msft_D_df = e.av.daily('MSFT') # Daily
msft_DA_df = e.av.daily_adjusted('MSFT') # Daily Adjusted
msft_W_df = e.av.weekly('MSFT') # Weekly
msft_WA_df = e.av.weekly_adjusted('MSFT') # Weekly Adjusted
msft_M_df = e.av.monthly('MSFT') # Monthly
msft_MA_df = e.av.monthly_adjusted('MSFT') # Monthly Adjusted
Contributions are welcome and I am open to new ideas or implementations.
If this module does not suit your style or workflow, consider some of the following AlphaVantage API Python Wrapper implementations by:
Romel Torres: https://github.com/RomelTorres/alpha_vantage
portfoliome: https://github.com/portfoliome/alphavantage