浏览代码

同花顺wind日期序列新增参数

hsun 1 周之前
父节点
当前提交
f4bee9ab06
共有 2 个文件被更改,包括 38 次插入23 次删除
  1. 23 10
      ths_api.py
  2. 15 13
      wind_api.py

+ 23 - 10
ths_api.py

@@ -126,33 +126,46 @@ def has_comma(input_string):
     return isinstance(input_string, str) and ',' in input_string
 
 
-def process_single_edb_code(StockCode, SingleEdbCode, StartDate, EndDate, ExtraPars=''):
+def process_single_edb_code(StockCode, SingleEdbCode, StartDate, EndDate, Days='', Interval='', ExtraPars=''):
     strExtra = ','.join(map(str, ExtraPars))
     print(strExtra)
-    thsEDBDataQuery = THS.THS_DS(StockCode, SingleEdbCode, strExtra, '', StartDate, EndDate)
+
+    funcParas = []
+    if Days:
+        funcParas.append(f"Days:{Days}")
+    if Interval:
+        funcParas.append(f"Interval:{Interval}")
+    funcPara = ",".join(funcParas)
+
+    thsEDBDataQuery = THS.THS_DS(StockCode, SingleEdbCode, strExtra, funcPara, StartDate, EndDate)
     print(thsEDBDataQuery)
     result = json.dumps(ths_data_to_dict(thsEDBDataQuery))
     return result
 
 
 @hug.get('/edbInfo/ths/ds')
-def GetEdbDataByThsDs(StockCode, EdbCode, StartDate, EndDate, ExtraPars=''):
-    print("GetEdbDataByThsDs-> StockCode: {}; EdbCode: {}; StartDate: {}; EndDate: {}; ExtraPars: {}".format(StockCode,
-                                                                                                             EdbCode,
-                                                                                                             StartDate,
-                                                                                                             EndDate,
-                                                                                                             ExtraPars))
+def GetEdbDataByThsDs(StockCode, EdbCode, StartDate, EndDate, Days='', Interval='', ExtraPars=''):
+    print(
+        "GetEdbDataByThsDs-> StockCode: {}; EdbCode: {}; StartDate: {}; EndDate: {}; Days: {}; Interval: {}; ExtraPars: {}".format(
+            StockCode,
+            EdbCode,
+            StartDate,
+            EndDate,
+            Days,
+            Interval,
+            ExtraPars))
     result_list = []
 
     if isinstance(EdbCode, list):
         for SingleEdbCode in EdbCode:
-            result_list.append(process_single_edb_code(StockCode, SingleEdbCode, StartDate, EndDate, ExtraPars))
+            result_list.append(
+                process_single_edb_code(StockCode, SingleEdbCode, StartDate, EndDate, Days, Interval, ExtraPars))
             print("THS_DS end")
         print(result_list)
         return result_list
     else:
         # 如果不包含逗号,直接处理
-        result = process_single_edb_code(StockCode, EdbCode, StartDate, EndDate, ExtraPars)
+        result = process_single_edb_code(StockCode, EdbCode, StartDate, EndDate, Days, Interval, ExtraPars)
         print(result)
         return result
 

+ 15 - 13
wind_api.py

@@ -3,11 +3,7 @@ from bottle import route, run, NORUN
 from WindPy import w
 import json
 import pandas as pd
-import time
 import os
-import sys
-from apscheduler.schedulers.background import BackgroundScheduler
-import time
 
 hug.API(__name__).http.output_format = hug.output_format.json
 
@@ -33,17 +29,14 @@ def GetEdbDataByWind(EdbCode, StartDate, EndDate):
 
     print("getdata")
     option = "Fill=Previous"
-    
+
     data = w.edb(EdbCode, StartDate, EndDate, option)
     print("wind data")
     print(data)
     df = pd.DataFrame()
-    if data.ErrorCode != 0:  # Internet Timeout 超时退出
-        os._exit(0)
-        return "a"
-    if data.ErrorCode != 0:  # corrupted response. 错误响应也重启
+    if data.ErrorCode != 0 and data.ErrorCode != -40522017:  # corrupted response. 如果不是提示超限,同时也不是正常返回,那么就退出
         os._exit(0)
-        return "b"
+        return "c"
     df['DT'] = data.Times
     df['CLOSE'] = data.Data[0]
     df['ErrorCode'] = data.ErrorCode
@@ -57,7 +50,7 @@ def GetEdbDataByWind(EdbCode, StartDate, EndDate):
 
 
 @hug.get('/edbInfo/wind/wsd')
-def GetEdbDataWindWsd(StockCode, EdbCode, StartDate, EndDate):
+def GetEdbDataWindWsd(StockCode, EdbCode, StartDate, EndDate, Days="", Period="", PriceAdj=""):
     print("GetEdbDataByWind:", EdbCode)
     isConnected = w.isconnected()
     print("isconnected")
@@ -69,7 +62,15 @@ def GetEdbDataWindWsd(StockCode, EdbCode, StartDate, EndDate):
         if isConnected == False:
             return "{'ErrMsg':'启动Wind接口失败'}"
 
-    option = "Fill=Previous"
+    options = ["Fill=Previous"]
+    if Days:
+        options.append(f"Days={Days}")
+    if Period:
+        options.append(f"Period={Period}")
+    if PriceAdj:
+        options.append(f"PriceAdj={PriceAdj}")
+    option = ";".join(options)
+    print(option)
     wsd_data = w.wsd(StockCode, EdbCode, StartDate, EndDate, option)
 
     if wsd_data.ErrorCode != 0:  # Internet Timeout 超时退出
@@ -81,6 +82,7 @@ def GetEdbDataWindWsd(StockCode, EdbCode, StartDate, EndDate):
     result = json.loads(json_data)
     return result
 
+
 # def check_wind_status():
 #     print("check wind login status")
 #      # wind 登录
@@ -107,6 +109,6 @@ if __name__ == "__main__":
     if wStart.ErrorCode != 0:
         print("启动万得API接口失败")
         os._exit(0)
-   
+
     app = __hug__.http.server()
     run(app=app, reloader=True, host='0.0.0.0', port=7000)