直接上代码
import tushare as ts
import datetime
def last_train_data():
alldays = ts.trade_cal()
tradingdays = alldays[alldays['isOpen'] == 1]
nowTime = time.mktime(time.strptime( datetime.datetime.now().strftime('%Y-%m-%d'),"%Y-%m-%d"))
trandtime = time.mktime(time.strptime(tradingdays['calendarDate'].values[-1],"%Y-%m-%d"))
i=1
while int(nowTime)-int(trandtime)<0:
i+=1
trandtime = time.mktime(time.strptime(tradingdays['calendarDate'].values[-i],"%Y-%m-%d"))
trandtime=tradingdays['calendarDate'].values[-i]
return trandtime