1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import hug
- from bottle import route, run,NORUN
- from WindPy import w
- import iFinDPy as THS
- 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'
- # 同花顺登录函数
- def thslogindemo():
- # 输入用户的帐号和密码
- thsLogin = THS.THS_iFinDLogin("hzmd150", "689719")
- print(thsLogin)
- if (thsLogin == 0 or thsLogin == -201):
- print('ths 登录成功')
- else:
- print('ths 登录失败')
- @hug.get('/edbInfo/ths')
- def GetEdbDataByThs(EdbCode, StartDate, EndDate):
- print("GetEdbDataByThs")
- thsLogin = THS.THS_iFinDLogin("账号", "密码")
- thsEDBDataQuery = THS.THS_EDBQuery(EdbCode, StartDate, EndDate, True)
- print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":start GetEdbDataByThs")
- print("thsEDBDataQuery")
- print(thsEDBDataQuery)
- thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
- result = json.loads(thsEDBDataQuery)
- print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":end GetEdbDataByThs")
- return result
- @hug.get('/edbInfo/ths/future_good')
- def GetFutureGoodEdbDataByThs(EdbCode, StartDate, EndDate):
- print("THS_HistoryQuotes start")
- thsLogin = THS.THS_iFinDLogin("账号", "密码")
- filed = 'lastclose,open,high,low,close,avgprice,change,changeper,volume,amount,hsl,lastsettlement,settlement,zdsettlement,zdfsettlement,ccl,ccbd,zf,zjlx,zjcd'
- # filed = 'open,high,low,close,volume,amount,settlement,ccl,zjlx'
- params = 'Interval:D,CPS:1,baseDate:1900-01-01,Currency:YSHB,fill:Previous'
- # params = 'YSHB;Tradedays'
- # print(params)
- thsEDBDataQuery = THS.THS_HistoryQuotes(EdbCode, filed, params, StartDate, EndDate, True)
- # thsEDBDataQuery = THS.THS_HQ(EdbCode, filed, params, StartDate, EndDate)
- # thsEDBDataQuery = THS.THS_EDBQuery(EdbCode, StartDate, EndDate, True)
- print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":start GetFutureGoodEdbDataByThs")
- print("THS_HistoryQuotes end")
- print(thsEDBDataQuery)
- thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
- result = json.loads(thsEDBDataQuery)
- print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":end GetFutureGoodEdbDataByThs")
- return result
- if __name__ == "__main__":
- # ths登录函数
- thslogindemo()
- app = __hug__.http.server()
- run(app=app, reloader=True, port=7000)
|