11import requests
22from alpha_vantage .timeseries import TimeSeries
3- from alpha_vantage .cryptocurrencies import CryptoCurrencies
4- from alpha_vantage .foreignexchange import ForeignExchange
53from alpha_vantage .sectorperformance import SectorPerformances
64from alpha_vantage .techindicators import TechIndicators
75from alpaca_trade_api .common import get_alpha_vantage_credentials
@@ -13,8 +11,6 @@ def __init__(self, api_key):
1311 self ._api_key = get_alpha_vantage_credentials (api_key )
1412 self ._session = requests .Session ()
1513 self ._timeseries = TimeSeries (key = self ._api_key )
16- self ._cryptocurrencies = CryptoCurrencies (key = self ._api_key )
17- self ._foreignexchange = ForeignExchange (key = self ._api_key )
1814 self ._sectorperformance = SectorPerformances (key = self ._api_key )
1915 self ._techindicators = TechIndicators (key = self ._api_key )
2016
@@ -27,7 +23,7 @@ def _request(self, method, params=None):
2723 return resp .json ()
2824
2925 def get (self , params = None ):
30- ''' Customizable endpoint, where you can pass all
26+ ''' Customizable endpoint, where you can pass all
3127 keywords/paramters from the documentation:
3228 https://www.alphavantage.co/documentation/#
3329
@@ -36,13 +32,17 @@ def get(self, params=None):
3632 '''
3733 return self ._request ('GET' , params = params )
3834
39- def historic_quotes (self , symbol , adjusted = False , outputsize = 'full' , cadence = 'daily' , output_format = None ):
40- ''' Returns the one of the TIME_SERIES_* endpoints of the Alpha Vantage API.
35+ def historic_quotes (
36+ self , symbol , adjusted = False , outputsize = 'full' ,
37+ cadence = 'daily' , output_format = None
38+ ):
39+ ''' Returns one of the TIME_SERIES_* endpoints
40+ of the Alpha Vantage API.
4141
4242 Params:
4343 symbol: The ticker to return
4444 adjusted: Return the adjusted prices
45- cadence: Choose between ['daily', 'weekly', 'monthly'], to return the cadence
45+ cadence: Choose between ['daily', 'weekly', 'monthly']
4646 output_format: Choose between['json', 'csv', 'pandas']
4747
4848 Returns:
@@ -52,16 +52,27 @@ def historic_quotes(self, symbol, adjusted=False, outputsize='full', cadence='da
5252 self ._timeseries .output_format = output_format
5353 if cadence == 'daily' :
5454 data , _ = self ._timeseries .get_daily_adjusted (
55- symbol = symbol , outputsize = outputsize ) if adjusted else self ._timeseries .get_daily (symbol = symbol , outputsize = outputsize )
55+ symbol = symbol , outputsize = outputsize
56+ ) if adjusted else self ._timeseries .get_daily (
57+ symbol = symbol , outputsize = outputsize
58+ )
5659 if cadence == 'weekly' :
5760 data , _ = self ._timeseries .get_weekly_adjusted (
58- symbol = symbol ) if adjusted else self ._timeseries .get_weekly (symbol = symbol )
61+ symbol = symbol
62+ ) if adjusted else self ._timeseries .get_weekly (
63+ symbol = symbol
64+ )
5965 if cadence == 'monthly' :
6066 data , _ = self ._timeseries .get_monthly_adjusted (
61- symbol = symbol ) if adjusted else self ._timeseries .get_monthly (symbol = symbol )
67+ symbol = symbol
68+ ) if adjusted else self ._timeseries .get_monthly (
69+ symbol = symbol
70+ )
6271 return data
6372
64- def intraday_quotes (self , symbol , interval = '5min' , outputsize = 'full' , output_format = None ):
73+ def intraday_quotes (
74+ self , symbol , interval = '5min' , outputsize = 'full' , output_format = None
75+ ):
6576 ''' Returns the TIME_SERIES_INTRADAY endpoint of the Alpha Vantage API.
6677
6778 Params:
@@ -113,92 +124,11 @@ def search_endpoint(self, keywords, datatype='json'):
113124 'keywords' : keywords , 'datatype' : datatype }
114125 return self .get (params )
115126
116- def historic_fx_quotes (self , from_symbol , to_symbol , outputsize = 'full' , cadence = 'daily' , output_format = None ):
117- ''' Returns the one of the FX_* endpoints of the Alpha Vantage API.
118-
119- Params:
120- from_currency: The symbol to convert
121- to_currency: The symbol to convert to
122- cadence: Choose between ['daily', 'weekly', 'monthly'], to return the cadence
123- output_format: Choose between['json', 'csv', 'pandas']
124-
125- Returns:
126- pandas, csv, or json
127- '''
128- if output_format :
129- self ._foreignexchange .output_format = output_format
130- if cadence == 'daily' :
131- data , _ = self ._foreignexchange .get_currency_exchange_daily (
132- from_symbol = from_symbol , to_symbol = to_symbol , outputsize = outputsize )
133- if cadence == 'weekly' :
134- data , _ = self ._foreignexchange .get_currency_exchange_weekly (
135- from_symbol = from_symbol , to_symbol = to_symbol , outputsize = outputsize )
136- if cadence == 'monthly' :
137- data , _ = self ._foreignexchange .get_currency_exchange_monthly (
138- from_symbol = from_symbol , to_symbol = to_symbol , utputsize = outputsize )
139- return data
140-
141- def intraday_fx_quotes (self , from_symbol , to_symbol , interval = '5min' , outputsize = 'full' , output_format = None ):
142- ''' Returns the FX_INTRADAY endpoint of the Alpha Vantage API.
143-
144- Params:
145- from_currency: The symbol to convert
146- to_currency: The symbol to convert to
147- interval: Choose between['1min', '5min', '15min', '30min', '60min']
148- output_format: Choose between['json', 'csv', 'pandas']
149-
150- Returns:
151- pandas, csv, or json
152- '''
153- if output_format :
154- self ._foreignexchange .output_format = output_format
155- data , _ = self ._foreignexchange .get_currency_exchange_intraday (
156- from_symbol = from_symbol , to_symbol = to_symbol , interval = interval , outputsize = outputsize )
157- return data
158-
159- def exchange_rate (self , from_currency , to_currency ):
160- ''' Returns the exchange rate of two currencies, digital or physical.
161- CURRENCY_EXCHANGE_RATE endpoint of the Alpha Vantage API
162-
163- Params:
164- from_currency: The symbol to convert
165- to_currency: The symbol to convert to
166-
167- Returns:
168- json
169- '''
170- params = {'function' : "CURRENCY_EXCHANGE_RATE" ,
171- 'from_currency' : from_currency , 'to_currency' : to_currency }
172- data = self .get (params )
173- return data
174-
175- def historic_cryptocurrency_quotes (self , symbol , market , cadence = 'daily' , output_format = None ):
176- ''' Returns the one of the DIGITAL_CURRENCY_* endpoints of the Alpha Vantage API.
177-
178- Params:
179- symbol: The cryptocurrency to return
180- market: The market it's being sold on
181- cadence: Choose between ['daily', 'weekly', 'monthly'], to return the cadence
182- output_format: Choose between['json', 'csv', 'pandas']
183-
184- Returns:
185- pandas, csv, or json
186- '''
187- if output_format :
188- self ._cryptocurrencies .output_format = output_format
189- if cadence == 'daily' :
190- data , _ = self ._cryptocurrencies .get_digital_currency_daily (
191- symbol = symbol , market = market )
192- if cadence == 'weekly' :
193- data , _ = self ._cryptocurrencies .get_digital_currency_weekly (
194- symbol = symbol , market = market )
195- if cadence == 'monthly' :
196- data , _ = self ._cryptocurrencies .get_digital_currency_monthly (
197- symbol = symbol , market = market )
198- return data
199-
200- def techindicators (self , techindicator = 'SMA' , output_format = 'json' , ** kwargs ):
201- ''' Returns the one of the technical indicator endpoints of the Alpha Vantage API.
127+ def techindicators (
128+ self , techindicator = 'SMA' , output_format = 'json' , ** kwargs
129+ ):
130+ ''' Returns one of the technical indicator endpoints of the
131+ Alpha Vantage API.
202132
203133 Params:
204134 techindicator: The technical indicator of choice
0 commit comments