浏览代码

feat:新增同花顺接口

Roc 1 年之前
父节点
当前提交
51f4f2338b
共有 2 个文件被更改,包括 71 次插入22 次删除
  1. 71 0
      ths_api.py
  2. 0 22
      wind_api.py

+ 71 - 0
ths_api.py

@@ -0,0 +1,71 @@
+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)

+ 0 - 22
wind_api.py

@@ -16,28 +16,6 @@ def hello():
     return 1
     # return 'wind true'
 
-@hug.get('/edbInfo/ths/future_good')
-def GetFutureGoodEdbDataByThs(EdbCode, StartDate, EndDate):
-    print("THS_HistoryQuotes start")
-    thsLogin = THS.THS_iFinDLogin("hzmd150", "689719")
-
-    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
-
-
 @hug.get('/edbInfo/wind')
 def GetEdbDataByWind(EdbCode, StartDate, EndDate):
     print("GetEdbDataByWind:", EdbCode)