Search code examples
pythonpandasstockalpha-vantage

Error using Alpha Vantage while following tutorial, - Pylint error


I'm learning about the alpha vantage package, and I've have been following this tutorial https://www.youtube.com/watch?v=JJO9fKj3_u4 by Derrick Sherrill, but I have run into some problems.

Here is my code:

import pandas as pd
from alpha_vantage.techindicators import TechIndicators
from alpha_vantage.timeseries import TimeSeries
import matplotlib.pyplot as plt

api_key = 'XXXX'

ts = TimeSeries(key=api_key, output_format='pandas')
data_ts, meta_data_ts = ts.get_intraday(
symbol='MSFT', interval='1min', outputsize='full')

period = 60

ti = TechIndicators(key=api_key, output_format='pandas')
data_ti, meta_data_ti = ti.get_sma(
symbol='MSFT', interval='1min', time_period=period, series_type='close')

df1 = data_ti
df2 = data_ts['4. close'].iloc[period-1::]

df2.index = df1.index

total_df = pd.concat([df1, df2], axis=1)
print(total_df)

When defining the variable df2 I get a red underline and tells me:

Sequence index is not an int, slice, or instance with __index__pylint(invalid-sequence-index)

Although I'm not sure that's the problem.

I'm pretty sure I'm supposed to get a set of data, but thats not the case at the moment.

This is the full terminal message after trying to run the script:

  File "/Users/ludvighenriksen/Desktop/Code/api.py", line 15, in <module>
    data_ti, meta_data_ti = ti.get_sma(symbol='MSFT', interval='1',
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/alpha_vantage/alphavantage.py", line 218, in _format_wrapper
    call_response, data_key, meta_data_key = func(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/alpha_vantage/alphavantage.py", line 160, in _call_wrapper
    return self._handle_api_call(url), data_key, meta_data_key
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/alpha_vantage/alphavantage.py", line 337, in _handle_api_call
    raise ValueError(json_response["Error Message"])
ValueError: Invalid API call. Please retry or visit the documentation (https://www.alphavantage.co/documentation/) for SMA.

enter image description here

Hope you are able to help, thanks in advance!


Solution

  • There are some misunderstandings here.

    The red line squiggle you see under df2 is a pylint error. Pylint is a form of linting tool, which can often find parts of your code that will break, but it also find stylistic errors. A stylistic error is an error of how you write your code, it may not actually break the code. The error you got can be found here from the pylint documentation.

    You can disable this "code cleanness checker" a few ways. Look here or here for more information. Mac: Command+Shift+P > type "python: enable linting" > set "off" Windows: CTRL+SHIFT+P > Select linter > Disabled Linter.

    The original error you got seems to have been some user error from before, maybe you had the wrong symbol, but your output screenshot does not seem to have the reproduced error.