我正试图使用NSEpy检索历史股票信息,但我无法做到这一点,因为每次我向它传递日期时,它都会引发ValueError,我似乎无法解决问题,希望得到任何帮助。这是我的代码:
from datetime import date, timedelta
ticker = input("Please enter symbol: ")
present_date = date.today()
prev_date = date.today() - timedelta(days = 5457)
get_stock_data(ticker,start_date = present_date, end_date = prev_date)
下面是另一个文件中的get_stock_data((函数:
import nsepy as nse
def get_stock_data(ticker, start_date, end_date):
data = nse.get_history(symbol=ticker, start=start_date,
end= end_date)
这是我每次运行文件时得到的错误:
Traceback (most recent call last):
File "ConvLSTM.py", line 79, in <module>
get_stock_data(ticker,start_date = present_date, end_date = prev_date)
File "G:Stocksget_data.py", line 11, in get_stock_data
end= end_date)
File "C:UsersshivaAppDataLocalProgramsPythonPython37libsite-packagesnsepyhistory.py", line 138, in get_hist
ory
return get_history_quanta(**kwargs)
File "C:UsersshivaAppDataLocalProgramsPythonPython37libsite-packagesnsepyhistory.py", line 142, in get_hist
ory_quanta
url, params, schema, headers, scaling = validate_params(**kwargs)
File "C:UsersshivaAppDataLocalProgramsPythonPython37libsite-packagesnsepyhistory.py", line 179, in validate
_params
raise ValueError('Please check start and end dates')
ValueError: Please check start and end dates
如果这是一个愚蠢的问题,我很抱歉,但我试图寻找答案,但找不到。提前谢谢。
开始日期必须小于结束日期。以下代码应有效:
from datetime import date, timedelta
ticker = input("Please enter symbol: ")
present_date = date.today()
prev_date = date.today() - timedelta(days = 5457)
get_stock_data(ticker,start_date = prev_date, end_date = present_date)