Using the Tushare library, he has a function that reads whether all dates are open and the return value is Dataframe type
import tushare as tsts.trade_cal()
IsOpen 1 is the opening.
The full source code is as follows:
import tushare as tsimport datetimeimport timedef JiaoYiRiQi(): while True: DatetimeNOW = datetime.datetime.now().strftime(‘%Y-%m-%d‘) OpenList = ts.trade_cal() OpentimeList = OpenList.isOpen[OpenList.calendarDate == DatetimeNOW] if OpentimeList.values[0] == 1: XianZaiShiJian = datetime.datetime.now().strftime(‘%H%M%S‘) if 93000 < int(XianZaiShiJian) < 150000: break else: pass else: pass time.sleep(60)
If you jump out of the loop within the trading hours, wait 60 seconds to execute again.
Python determines whether the stock day
Tags: python A shares
Original: http://blog.51cto.com/12541359/2122463,
Function name pending modification, function to be verified
Python determines whether the trading day is on the market