1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import hug
- from bottle import route, run,NORUN
- from WindPy import w
- import json
- import pandas as pd
- import time
- import os
- import sys
- hug.API(__name__).http.output_format = hug.output_format.json
- @hug.get('/hz_server')
- def hello():
- return 1
- # return 'wind true'
- @hug.get('/edbInfo/wind')
- def GetEdbDataByWind(EdbCode, StartDate, EndDate):
- print("GetEdbDataByWind:", EdbCode)
- isConnected = w.isconnected()
- print("isconnected")
- print(isConnected)
- if isConnected == False:
- print("re isconnected")
- w.start()
- isConnected = w.isconnected()
- if isConnected == False:
- return "{'ErrMsg':'启动Wind接口失败'}"
- print("getdata")
- option = "Fill=Previous"
- data = w.edb(EdbCode, StartDate, EndDate, option)
- print("wind data")
- print(data)
- df = pd.DataFrame()
- if data.ErrorCode == -40521010: # Internet Timeout 超时退出
- os._exit(0)
- return "a"
- df['DT'] = data.Times
- df['CLOSE'] = data.Data[0]
- df['ErrorCode'] = data.ErrorCode
- df = df[['DT', 'CLOSE', 'ErrorCode']]
- df = df.dropna()
- json_data = df.to_json()
- # w.stop()
- print("wind data end")
- result = json.loads(json_data)
- return result
- @hug.get('/edbInfo/wind/wsd')
- def GetEdbDataWindWsd(StockCode,EdbCode, StartDate, EndDate):
- print("GetEdbDataByWind:", EdbCode)
- isConnected = w.isconnected()
- print("isconnected")
- print(isConnected)
- if isConnected == False:
- print("re isconnected")
- w.start()
- isConnected = w.isconnected()
- if isConnected == False:
- return "{'ErrMsg':'启动Wind接口失败'}"
- option = "Fill=Previous"
- wsd_data = w.wsd(StockCode,EdbCode, StartDate, EndDate, option)
- if wsd_data.ErrorCode == -40521010: # Internet Timeout 超时退出
- os._exit(0)
- return "a"
-
- fm=pd.DataFrame(wsd_data.Data,index=wsd_data.Fields,columns=wsd_data.Times)
- json_data=fm.to_json()
- result = json.loads(json_data)
- return result
- if __name__ == "__main__":
- # wind 登录
- wStart = w.start()
- if wStart.ErrorCode != 0:
- print("启动万得API接口失败")
- print(wStart)
- app = __hug__.http.server()
- run(app=app, reloader=True,host='0.0.0.0', port=7000)
|