Skip to content

Commit 5287ef9

Browse files
committed
Provide examples of how to use Alpha Vantage API
1 parent 5093fcd commit 5287ef9

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

av_examples.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os, dotenv;
2+
3+
import numpy as np;
4+
import pandas as pd;
5+
6+
from alpha_vantage.timeseries import TimeSeries;
7+
from alpha_vantage.foreignexchange import ForeignExchange;
8+
from alpha_vantage.techindicators import TechIndicators;
9+
from alpha_vantage.sectorperformance import SectorPerformances;
10+
11+
12+
#
13+
# Load Alpha Vantage API Keys from .env file
14+
#
15+
16+
dotenv.load_dotenv();
17+
18+
alpha_vantage_api_key = os.getenv('alpha_vantage_api_key');
19+
20+
21+
22+
#
23+
# Instantiate base objects for:
24+
# • time series
25+
# • foreign exchange
26+
# • technical indicators
27+
# • sector performance
28+
#
29+
30+
ts = TimeSeries(key=alpha_vantage_api_key, output_format='pandas');
31+
fx = ForeignExchange(key=alpha_vantage_api_key, output_format='pandas');
32+
ti = TechIndicators(key=alpha_vantage_api_key, output_format='pandas');
33+
34+
35+
# fx = ForeignExchange(key=alpha_vantage_api_key, output_format='pandas');
36+
# ti = TechIndicators(key=alpha_vantage_api_key, ouput_format='pandas');
37+
# sp = SectorPerformances(key=alpha_vantage_api_key, ouput_format='pandas');
38+
39+
40+
#
41+
# Daily closing stock prices for Capital One
42+
#
43+
44+
cof, meta_cof = ts.get_daily(symbol='COF', outputsize='full');
45+
46+
47+
#
48+
# Intraday stock prices for Proctor & Gamble
49+
#
50+
51+
pg, meta_pg = ts.get_intraday(symbol='PG', interval='1min', outputsize='full');
52+
53+
54+
#
55+
# Foreign exchange rate for Euros -> US Dollars
56+
#
57+
# Alpha Vantage API calls return a 2 element list.
58+
# The second element is normally meta data, but this forex call returns an empty string.
59+
#
60+
61+
fx_euro_usd, tmp_none = fx.get_currency_exchange_rate(from_currency='EUR', to_currency='USD');
62+
63+
64+
#
65+
# Technical Analysis Indicator - Simple Fifty-Day Moving Average for Linde plc
66+
#
67+
68+
sma_lin, sma_lin_meta = ti.get_sma(symbol='MCD', interval='monthly', time_period=50, series_type='close');

0 commit comments

Comments
 (0)