获取全部a股代码
#导入库
import pandasas pd
import numpyas np
import datetime
from WindPyimport *
#获取当天时间
date = datetime.today()
#1.获取全部a股数据
all_a = w.wset(“SectorConstituent”,date = date ,sector=u”全部A股”)
#获取所有a股代码
all_Code = list(pd.Series(all_a.Data[1]))#获取的是列表数据
#2.获取当天所有停牌股票信息
all_tp = w.wset(“TradeSuspend”,startdate = date,enddate = date,field = “wind_code,sec_name,suspend_type,suspend_reason”)
all_tp_code = list(pd.Series(all_tp.Data[0]))
#3.剔除ST
all_st = w.wset(“SectorConstituent”,date=date,sector=u”风险警示股票”,field=”wind_code,sec_name”)
all_st_code = list(pd.Series(all_st.Data[0]))
#4.获取当天剔除ST和停牌的全部A股代码
all_Code = set(all_Code)
all_st_code = set(all_st_code)
all_tp_code = set(all_tp_code)
code = all_Code – all_tp_code – all_st_code
#再将code转换为列表形式
code = list(code)
print(code)
#此时获得的code即为我们需要的a股代码。