用户输入“ ts.get_intraday”内

时间:2018-12-12 22:17:38

标签: input stock stock-data

我对python还是很陌生,我保证我会来这里之前逛了一会儿,但是我正在尝试制作一个股票阅读器,使人们可以在其中输入他们想要的任何股票,并显示数据。它。到目前为止,一切进展顺利,但是我在用户输入方面遇到了麻烦,这是我的代码:

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()

我得到的错误是:

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 个答案:

答案 0 :(得分:0)

没关系,在等待回复时,我在四处乱逛,实际上找到了一种方法!与其进行单独的输入,不如我自己在meta_date行上添加了输入:data,meta_data = ts.get_intraday(symbol = input('Put here:'),interval ='1min',outputsize ='full')