0

我对 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)'
4

1 回答 1

0

没关系,伙计们,在等待回复时,我在胡闹,实际上找到了一种方法!我没有单独输入,而是在 meta_date 行上添加了一个输入:data, meta_data = ts.get_intraday(symbol=input('Put here: '), interval='1min', outputsize='full')

于 2018-12-14T01:54:35.880 回答