User input inside " ts.get_intraday "

1k Views Asked by At

I'm fairly new to python and I promise I looked around for a while before I came here but I'm trying to make a stock reader in which someone can just type in whichever stock they want and it shows the data for it. So far everything is going well but I am having trouble with the user input, here is my code:

from alpha_vantage.timeseries import TimeSeries     
import matplotlib.pyplot as plt

pwd = input('Enter Ticker Symbol Here: ')

ts = TimeSeries(key='HQL2R9KNYW99K4BT', output_format='pandas')   
data, meta_data = ts.get_intraday(symbol=**'TSLA'**, interval='1min', outputsize='full')       *#But Instead of tesla I want it to be user input.*

data['4. close'].plot()

plt.title('Intraday Times Series for the MSFT stock (1 min)')

plt.show()

The error I am getting is:

Traceback (most recent call last):
  File "C:/Users/abakh/PycharmProjects/stock1/Stock1.py", line 7, in <module>
    data, meta_data = ts.get_intraday(symbol=' + pwd + ', interval='1min', outputsize='full')
  File "C:\Users\abakh\PycharmProjects\stock1\venv\lib\site-packages\alpha_vantage\alphavantage.py", line 178, in _format_wrapper
    data = call_response[data_key]
KeyError: 'Time Series (1min)'
1

There are 1 best solutions below

0
Bakhrom Abdurakhmonov On

Never mind guys, While waiting for a response I was messing around and actually found a way to do it! instead of making a seperate imput I added a input on the meta_date line it self : data, meta_data = ts.get_intraday(symbol=input('Put here: '), interval='1min', outputsize='full')