Search code examples
pythonterminalalpha-vantage

Alpha Vantage Daily Information Call Import Error


I have recently attempted to utilise Alpha Vantage, a financial API, to attain stock market information concerning a provided stock, Microsoft; in order to complete this, I have utilised the module information provided upon the official module documentation website, displayed below:

https://alpha-vantage.readthedocs.io/en/latest/source/alpha_vantage.html#module-alpha_vantage

Within this particular website, the official standard reference to calling daily data for a particular stock is listed as the following:

"get_daily(*args, **kwargs)

Return daily time series in two json objects as data and meta_data. It raises ValueError when problems arise

Keyword Arguments:

symbol – the symbol for the equity we want to get its data outputsize – The size of the call, supported values are ‘compact’ and ‘full; the first returns the last 100 points in the data series, and ‘full’ returns the full-length daily times series, commonly above 1MB (default ‘compact’)"

In addition to this, I followed the previously referenced instructions upon the website, which mandated the establishment of an environmental or conditional variable for the placement of the API key one is utilising to access the Alpha Vantage API. With such a key, I entered the Python shell via the MacOS terminal, utilising the command 'python'. Following this, I wrote the following lines of code, utilising all conditional variables listed:

>>> from alpha_vantage.timeseries import TimeSeries
>>> API_KEY = '9DE8M4Z80PTU2272'
>>> import matplotlib.pyplot as plt
>>> stock = TimeSeries.get_daily(key = API_KEY, symbol = 'MSFT', outputsize = 'full')

However, the shell within the terminal provided the following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: _format_wrapper() missing 1 required positional argument: 'self'

Having provided all necessary variables for the utilisation of the module, as stated upon the official website, I am unsure of the source of this error with regards to the aforementioned program. Would one happen to know why it is providing the following error? I am utilising the alpha_vantage library within the Python shell via the MacOS terminal. Thank you for your assistance.


Solution

  • Close, as Bailey Kocin mentioned, you have to create an instance of the TimeSeries object and then call the function on that instance.

    Try this instead:

    >>> from alpha_vantage.timeseries import TimeSeries
    >>> API_KEY = 'XXXXXXXX'
    >>> import matplotlib.pyplot as plt
    >>> ts = TimeSeries(key=API_KEY)
    >>> ts.get_daily(symbol = 'MSFT', outputsize = 'full')