python使用用Wind接口获取全部A股历史交易数据

上传人:飞*** 文档编号:60575868 上传时间:2022-03-08 格式:DOCX 页数:8 大小:18.74KB
返回 下载 相关 举报
python使用用Wind接口获取全部A股历史交易数据_第1页
第1页 / 共8页
python使用用Wind接口获取全部A股历史交易数据_第2页
第2页 / 共8页
python使用用Wind接口获取全部A股历史交易数据_第3页
第3页 / 共8页
点击查看更多>>
资源描述
python使用用Wind接口获取全部A股历史交易数据果然是中文编码的问题。搞定了,新鲜出炉一个小脚本。谢谢各位大神的解答。Author:wenrongliDate:2014-11-18Version:V1.0#!/user/python# -*-coding:gb2312-*-importosimportsysimportgetoptfromWindPyimport*fromdatetimeimport*classLoadHisInfo:def_init_(self):self.OutputDir=rE:self.StockCodeList=defStartWind(self):w.start()defLoadStockList(self):res=w.wset(SectorConstituent,date=;sector=全部A股)ifres.ErrorCode!=0:print(Error+str(res.ErrorCode)+loadstockcodelistfailn)sys.exit()foriinrange(0,len(res.Data0):forkinrange(0,len(res.Fields):if(res.Fieldsk=date):date=res.Datakiif(res.Fieldsk=wind_code):code=res.Datakiif(res.Fieldsk=sec_name):name=res.Datakiself.StockCodeList.append(code)defLoadHisInfo(self):forcodeinself.StockCodeList:outputPath=self.OutputDir+code+r.txtdata=w.wsd(code,open,high,low,close,19900101,showblank=0)ifdata.ErrorCode!=0:print(Error+str(data.ErrorCode)+loadhistoryinfofailn)sys.exit()fOutputObj=open(outputPath.encode(gbk),a)foriinrange(0,len(data.Data0):date=str(data.Timesi)forkinrange(0,len(data.Fields):if(data.Fieldsk=OPEN):openPrice=data.Datakiif(data.Fieldsk=LOW):lowPrice=data.Datakiif(data.Fieldsk=HIGH):highPrice=data.Datakiif(data.Fieldsk=CLOSE):closePrice=data.Datakiif(openPrice=0)or(lowPrice=0)or(highPrice=0)or(closePrice=0):continueresult=date0:10+,+str(openPrice)+,+str(highPrice)+,+str(lowPrice)+,+str(closePrice)+nfOutputObj.write(result)fOutputObj.close()defRun(self):self.StartWind()self.LoadStockList()self.LoadHisInfo()if_name_=_main_:loadInfoObj=LoadHisInfo()iflen(sys.argv)<3:print(pythonLoadWindInfo.py-ooutPutDir)sys.exit()opts,args=getopt.getopt(sys.argv1:,o:)forop,valueinopts:ifop=-o:loadInfoObj.OutputDir=valueelse:print(pythonLoadWindInfo.py-ooutPutDir)sys.exit()loadInfoObj.Run()本来想获取A股股票代码列表,通过文档例子,返回了错误码-103,没找到这个错误码的说明,w.wset(SectorConstituent,udate=20130608;sector=全部A股),现在只能通过同花顺导出股票代码列表,然后通过配置文件的形式来拉数据,哪位大神知道怎么使用这个接口的还请赐教,不胜感激这里分享一个python获取A股历史交易数据的例子。#!/user/python# -*-coding:utf-8-*-importmathimportosimportsysimportgetoptfromWindPyimport*fromdecimalimport*fromdatetimeimport*WorkSpace=E:WorkSpacedatadataconfigconfigStockConfig.txturl=fConfigObj=open(config,r)count=0forlineinfConfigObj.readlines():iflen(line)<8:continuecode=line2:8codeName=line2:8+.+line0:2outputPath=rE:/WorkSpace/data/+code+r.txtw.start()data=w.wsd(codeName,open,high,low,close,19900101,showblank=0)ifdata.ErrorCode!=0:print(errorcode:+str(data.ErrorCode)+n)sys.exit()fOutputObj=open(outputPath.encode(gbk),a)foriinrange(0,len(data.Data0):date=str(data.Timesi)forkinrange(0,len(data.Fields):if(data.Fieldsk=OPEN):openPrice=data.Datakiif(data.Fieldsk=LOW):lowPrice=data.Datakiif(data.Fieldsk=HIGH):highPrice=data.Datakiif(data.Fieldsk=CLOSE):closePrice=data.Datakiif(openPrice=0)or(lowPrice=0)or(highPrice=0)or(closePrice=0):continueresult=date0:10+,+str(openPrice)+,+str(highPrice)+,+str(lowPrice)+,+str(closePrice)+nfOutputObj.write(result)fOutputObj.close()fConfigObj.close()
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 商业管理 > 营销创新


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!