我正在尝试获取任何给定股票过去 10 分钟的所有数据。我的代码在以前的代码中可以工作,但现在不起作用。
我认为问题可能与错误的间隔或日期有关,但我看不出任何问题。起初我怀疑这只是因为我试图在股市休市时运行它,但即使在今天它也不起作用。
是否只是它认为我正在使用纽约证券交易所,所以我需要设置一个参数说我在伦敦?
ticker = str(input("Input the symbol to predict: \n").upper())
start = datetime.now() - timedelta(minutes = 10)
end = datetime.now()
try:
data = yf.download(tickers = ticker, start = start, end = end, interval = "1m")
print("Data collection successful, beginning plotting...")
except:
print("Failure in download")
df = pd.DataFrame(data)
这是我的控制台日志:
Input the symbol to predict:
^GSPC
[*********************100%%**********************] 1 of 1 completed
1 Failed download:
['^GSPC']: YFChartError("%ticker%: Data doesn't exist for startDate = 1725282425, endDate = 1725283025")
Data collection successful, beginning plotting...
Traceback (most recent call last):
File "c:\6thForm\machines\patternaiRUN.py", line 53, in <module>
img = image.load_img(img_path, target_size = (224,224))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\TTJC2\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\keras\src\utils\image_utils.py", line 235, in load_img
with open(path, "rb") as f:
^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:/6thForm/machines/prediction graph.png'
(请注意,下载失败后出现的错误是由于数据不足造成的。)
别担心 - 您的代码中没有错误!股市将于 2024 年 11 月 2 日因美国联邦假日劳动节休市。因此,即使不再是周末,也不会出现新的金融数据。明天股市重新开盘后,您的代码应该可以正常工作。