OHLC Data Access¶
Ticker data fetch for AlphaVantage.
- class src.data_access.DataAccess(ticker, source, access_config, access_userdata, logger_name)¶
Bases:
src.lib.data_access.alphavantage.AlphaVantage
,src.lib.data_access.yahoofinance.YahooFinance
Data Access class.
- ticker¶
A string with the acronym of the ticker to be fetched. This value must match to the API expectation.
- Type
string
- ticker_name¶
A string with the full name of the ticker.
- Type
string
- source¶
A string with the reference to the source of the data, for example, AlphaVantage.
- Type
string
- access_config¶
A dictionary with the configuration for access the API specified by source. See template below.
- Type
dictionary
- access_userdata¶
A dictionary with the configuration for the user access the API specified by source, for example, the API key.
- Type
dictionary
- type_series¶
- Type
None
- period¶
- Type
None
- adjusted¶
- Type
None
- start¶
- Type
None
- end¶
- Type
None
- data_json¶
A dictionary which stores the results of the fetch of the OHLC data for the given ticker.
- Type
dictionary
- data_pandas¶
A pandas dataframe which stores the results of the fetch of the OHLC data for the given ticker.
- Type
Pandas data frame
Examples
For the dictionary access_config:
{ "api": { "fetching": { "AlphaVantage": { "user_data": { "APIKEY": "<YOUR API KEY>" } } } } }
For the dictionary access_userdata:
{ "data_source": { "AlphaVantage": { "user_data": { "APIKEY": "<YOUR API KEY>" } } } }
For acesing the data and class usage, the example below will fetch all the OHLC data for the Google ticker:
google = DataAccess(ticker="GOOG", source=config.data_source_name, access_config=config.data_source_access_data, access_userdata=config.data_source_user_data, logger_name=LOGGER_NAME, ) google_data = google.update_values(type_series="TIMESERIES", period="DAILY", adjusted=True, start="", end="" )
- update_values(type_series='TIMESERIES', period='DAILY', adjusted=True, start='', end='')¶
Updates the OHLC values for given ticker.
- Parameters
type_series (string, optional) – The first parameter.
period (string, optional) – Time base of the data: daily, monthly, etc.
adjusted (bool, optional) – For True it will return the adjusted closure value, otherwise it returns the regular closure.
start (datetime, optional) – The second parameter.
end (datetime, optional) – The end date for the time series to be fetched.
- Returns
The returned dataframe is composed of the following items (headers):
”Date”
”Open”
”High”
”Low”
”Close”
”Close Final”
”Volume”
”Dividend Amount”
”Split Coefficient”
- Return type
Pandas dataframe
Examples
An input example for using this method: To retrieve the complete time series (from first historical data, up to today) from AlphaVantage, where it entry in the series represents the OHLC data for a day, the inputs are:
google_data = google.update_values(type_series="TIMESERIES", period="DAILY", adjusted=True, start="", end="" )