auto skip non-trade day
This commit is contained in:
parent
9a18337326
commit
f2b95a1859
38
trade_day.py
Normal file
38
trade_day.py
Normal file
@ -0,0 +1,38 @@
|
||||
import time
|
||||
import baostock as bs
|
||||
|
||||
def is_trade_day(date=None):
|
||||
if date is None:
|
||||
date = time.strftime("%Y-%m-%d", time.localtime())
|
||||
#### 登陆系统 ####
|
||||
lg = bs.login()
|
||||
# 显示登陆返回信息
|
||||
if lg.error_code != str(0):
|
||||
print('login respond error_code:'+lg.error_code)
|
||||
print('login respond error_msg:'+lg.error_msg)
|
||||
return False, False
|
||||
|
||||
#### 获取交易日信息 ####
|
||||
rs = bs.query_trade_dates(start_date=date, end_date=date)
|
||||
if rs.error_code != str(0):
|
||||
print('query_trade_dates respond error_code:'+rs.error_code)
|
||||
print('query_trade_dates respond error_msg:'+rs.error_msg)
|
||||
bs.logout()
|
||||
return False, False
|
||||
|
||||
#### 打印结果集 ####
|
||||
trade = False
|
||||
while (rs.error_code == '0') & rs.next():
|
||||
# 获取一条记录,将记录合并在一起
|
||||
data_record = rs.get_row_data()
|
||||
if data_record[0] == date:
|
||||
trade = data_record[1] == '1'
|
||||
break
|
||||
|
||||
#### 登出系统 ####
|
||||
bs.logout()
|
||||
return True, trade
|
||||
|
||||
|
||||
# ok, trade = is_trade_day("2025-04-30")
|
||||
# print("result:{0}, trading:{1}".format(ok, trade))
|
||||
Loading…
x
Reference in New Issue
Block a user