from WindPy import w #from datetime import * w.start(); # 命令如何寫可以用命令生成器來輔助完成 # 定義打印輸出函數,用來展示數據使用 def printpy(outdata): if outdata.ErrorCode!=0: print('error code:'+str(outdata.ErrorCode)+'\n'); return(); for i in range(0,len(outdata.Data[0])): strTemp='' if len(outdata.Times)>1: strTemp=str(outdata.Times[i])+' ' for k in range(0, len(outdata.Fields)): strTemp=strTemp+str(outdata.Data[k][i])+' ' print(strTemp) # 通過wsd來提取時間序列數據,比如取開高低收成交量,成交額數據 print('\n\n'+'-----通過wsd來提取時間序列數據,比如取開高低收成交量,成交額數據-----'+'\n') wsddata1=w.wsd("000001.SZ", "open,high,low,close,volume,amt", "2015-11-22", "2015-12-22", "Fill=Previous") printpy(wsddata1) # 通過wsd來提取各個報告期財務數據 print('\n\n'+'-----通過wsd來提取各個報告期財務數據-----'+'\n') wsddata2=w.wsd("600000.SH", "tot_oper_rev,tot_oper_cost,opprofit,net_profit_is", "2008-01-01", "2015-12-22", "rptType=1;Period=Q;Days=Alldays;Fill=Previous") printpy(wsddata2) # 通過wss來取截面數據 print('\n\n'+'-----通過wss來取截面數據-----'+'\n') wssdata=w.wss("600000.SH,600007.SH,600016.SH", "ev,total_shares","tradeDate=20151222;industryType=1") printpy(wssdata) # 通過wst來取日內成交數據 print('\n\n'+'-----通過wst來取日內成交數據-----'+'\n') wstdata=w.wst("IF.CFE", "last,volume", "2015-12-22 09:00:00", "2015-12-22 14:04:45") printpy(wstdata) # 通過wsi來取日內分鍾數據 print('\n\n'+'-----通過wsi來取日內分鍾數據-----'+'\n') wsidata=w.wsi("IF.CFE", "open,high,low,close,volume,amt", "2015-12-22 09:00:00", "2015-12-22 14:06:15") printpy(wsidata) # 通過wset來取數據集數據 print('\n\n'+'-----通過wset來取數據集數據,獲取滬深300指數權重-----'+'\n') wsetdata=w.wset("IndexConstituent","date=20151222;windcode=000300.SH;field=date,wind_code,i_weight") printpy(wsetdata)
https://blog.csdn.net/qq_26948675/article/details/71172370
確保萬得返回了數據
from WindPy import w import sys w.start() wdata = w.wsd(...) if wdata.ErrorCode != 0: #確保wsd內參數設置沒有錯誤 print('Wind Error Code is: ',wdata.ErrorCode) sys.exit() if 0 == len(wdata.Data): #確保萬得返回了數據 print('Wind has no data returns') sys.exit()
- from WindPy import w
- #from datetime import *
- w.start();
- # 命令如何寫可以用命令生成器來輔助完成
- # 定義打印輸出函數,用來展示數據使用
- def printpy(outdata):
- if outdata.ErrorCode!=0:
- print('error code:'+str(outdata.ErrorCode)+'\n');
- return();
- for i in range(0,len(outdata.Data[0])):
- strTemp=''
- if len(outdata.Times)>1:
- strTemp=str(outdata.Times[i])+' '
- for k in range(0, len(outdata.Fields)):
- strTemp=strTemp+str(outdata.Data[k][i])+' '
- print(strTemp)
- # 通過wsd來提取時間序列數據,比如取開高低收成交量,成交額數據
- print('\n\n'+'-----通過wsd來提取時間序列數據,比如取開高低收成交量,成交額數據-----'+'\n')
- wsddata1=w.wsd("000001.SZ", "open,high,low,close,volume,amt", "2015-11-22", "2015-12-22", "Fill=Previous")
- printpy(wsddata1)
- # 通過wsd來提取各個報告期財務數據
- print('\n\n'+'-----通過wsd來提取各個報告期財務數據-----'+'\n')
- wsddata2=w.wsd("600000.SH", "tot_oper_rev,tot_oper_cost,opprofit,net_profit_is", "2008-01-01", "2015-12-22", "rptType=1;Period=Q;Days=Alldays;Fill=Previous")
- printpy(wsddata2)
- # 通過wss來取截面數據
- print('\n\n'+'-----通過wss來取截面數據-----'+'\n')
- wssdata=w.wss("600000.SH,600007.SH,600016.SH", "ev,total_shares","tradeDate=20151222;industryType=1")
- printpy(wssdata)
- # 通過wst來取日內成交數據
- print('\n\n'+'-----通過wst來取日內成交數據-----'+'\n')
- wstdata=w.wst("IF.CFE", "last,volume", "2015-12-22 09:00:00", "2015-12-22 14:04:45")
- printpy(wstdata)
- # 通過wsi來取日內分鍾數據
- print('\n\n'+'-----通過wsi來取日內分鍾數據-----'+'\n')
- wsidata=w.wsi("IF.CFE", "open,high,low,close,volume,amt", "2015-12-22 09:00:00", "2015-12-22 14:06:15")
- printpy(wsidata)
- # 通過wset來取數據集數據
- print('\n\n'+'-----通過wset來取數據集數據,獲取滬深300指數權重-----'+'\n')
- wsetdata=w.wset("IndexConstituent","date=20151222;windcode=000300.SH;field=date,wind_code,i_weight")
- printpy(wsetdata)
