From 7b4dbbfc406509f87b8e6e1842b7b4cb88f97a2d Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 07 七月 2023 11:20:15 +0800
Subject: [PATCH] 华鑫适配

---
 trade/current_price_process_manager.py |  107 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 62 insertions(+), 45 deletions(-)

diff --git a/trade/current_price_process_manager.py b/trade/current_price_process_manager.py
index d8cf196..f314025 100644
--- a/trade/current_price_process_manager.py
+++ b/trade/current_price_process_manager.py
@@ -8,6 +8,7 @@
 from ths import client_manager
 import constant
 from code_attribute import gpcode_manager
+from trade.huaxin import huaxin_trade_api
 from utils import tool, import_util
 from ths.l2_code_operate import L2CodeOperate
 from trade import trade_manager, l2_trade_util
@@ -67,26 +68,30 @@
         # -------------------------------澶勭悊浜ゆ槗浣嶇疆鍒嗛厤---------------------------------
         # 鎺掑簭
         new_code_list = sorted(_code_list, key=lambda e: (e.__getitem__(2), e.__getitem__(0)), reverse=True)
-        # 棰勫~鍏呬笅鍗曚唬鐮�
-        _buy_win_codes = []
-        for d in new_code_list:
-            _buy_win_codes.append(d[1])
-        for d in _delete_list:
-            _buy_win_codes.append(d[1])
-        try:
-            if not constant.API_TRADE_ENABLE and trade_gui is not None:
-                trade_gui.THSBuyWinManagerNew.fill_codes(_buy_win_codes)
-        except Exception as e:
-            logging.exception(e)
-            pass
+        if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS:
+            # 棰勫~鍏呬笅鍗曚唬鐮�
+            _buy_win_codes = []
+            for d in new_code_list:
+                _buy_win_codes.append(d[1])
+            for d in _delete_list:
+                _buy_win_codes.append(d[1])
+            try:
+                if not constant.API_TRADE_ENABLE and trade_gui is not None:
+                    trade_gui.THSBuyWinManagerNew.fill_codes(_buy_win_codes)
+            except Exception as e:
+                logging.exception(e)
+                pass
 
         # -------------------------------澶勭悊L2鐩戝惉---------------------------------
-
-        client_ids = client_manager.getValidL2Clients()
-        # 鏈�澶氬~鍏呯殑浠g爜鏁伴噺
-        max_count = len(client_ids) * constant.L2_CODE_COUNT_PER_DEVICE
-        if max_count == 0:
-            max_count = constant.L2_CODE_COUNT_PER_DEVICE
+        max_count = 0
+        if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS:
+            client_ids = client_manager.getValidL2Clients()
+            # 鏈�澶氬~鍏呯殑浠g爜鏁伴噺
+            max_count = len(client_ids) * constant.L2_CODE_COUNT_PER_DEVICE
+            if max_count == 0:
+                max_count = constant.L2_CODE_COUNT_PER_DEVICE
+        else:
+            max_count = constant.HUAXIN_L2_MAX_CODES_COUNT
 
         _delete_list = []
         for item in new_code_list:
@@ -108,32 +113,44 @@
         for d in _delete_list:
             del_code_list.append(d[1])
 
-        # 鍚庨潰鐨勪唬鐮佹暟閲�
-        # 鍏堝垹闄ゅ簲璇ュ垹闄ょ殑浠g爜
-        for code in del_code_list:
-            if gpcode_manager.is_listen_old(code):
-                cid, pid = gpcode_manager.get_listen_code_pos(code)
-                # 寮哄埗绉婚櫎
-                if cid and pid:
-                    gpcode_manager.set_listen_code_by_pos(cid, pid, "")
-                # 鍒ゆ柇鏄惁鍦ㄧ洃鍚噷闈�
-                L2CodeOperate.get_instance().add_operate(0, code, "鐜颁环鍙樺寲")
-        # 澧炲姞搴旇澧炲姞鐨勪唬鐮�
-        for code in add_code_list:
-            if not gpcode_manager.is_listen_old(code):
-                L2CodeOperate.get_instance().add_operate(1, code, "鐜颁环鍙樺寲")
+        if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN:
+            # 鍗庨懌L2,鑾峰彇鍔犲叆浠g爜鐨勬定鍋滀环
+            add_datas = []
+            for d in add_code_list:
+                limit_up_price = gpcode_manager.get_limit_up_price(d)
+                min_volume = 50 * 10000 // limit_up_price
+                add_datas.append((d, min_volume, limit_up_price))
+                try:
+                    huaxin_trade_api.set_l2_codes_data(add_datas)
+                except Exception as e:
+                    logging.exception(e)
+        else:
+            # 鍚庨潰鐨勪唬鐮佹暟閲�
+            # 鍏堝垹闄ゅ簲璇ュ垹闄ょ殑浠g爜
+            for code in del_code_list:
+                if gpcode_manager.is_listen_old(code):
+                    cid, pid = gpcode_manager.get_listen_code_pos(code)
+                    # 寮哄埗绉婚櫎
+                    if cid and pid:
+                        gpcode_manager.set_listen_code_by_pos(cid, pid, "")
+                    # 鍒ゆ柇鏄惁鍦ㄧ洃鍚噷闈�
+                    L2CodeOperate.get_instance().add_operate(0, code, "鐜颁环鍙樺寲")
+            # 澧炲姞搴旇澧炲姞鐨勪唬鐮�
+            for code in add_code_list:
+                if not gpcode_manager.is_listen_old(code):
+                    L2CodeOperate.get_instance().add_operate(1, code, "鐜颁环鍙樺寲")
 
-        # 鑾峰彇鍗′綅鏁伴噺
-        free_count = gpcode_manager.get_free_listen_pos_count()
-        if free_count < 2:
-            # 绌洪棽浣嶇疆涓嶈冻
-            listen_codes = gpcode_manager.get_listen_codes()
-            for code in listen_codes:
-                if not gpcode_manager.is_in_gp_pool(code):
-                    client_id, pos = gpcode_manager.get_listen_code_pos(code)
-                    gpcode_manager.set_listen_code_by_pos(client_id, pos, "")
-                    free_count += 1
-                    if free_count > 2:
-                        break
+            # 鑾峰彇鍗′綅鏁伴噺
+            free_count = gpcode_manager.get_free_listen_pos_count()
+            if free_count < 2:
+                # 绌洪棽浣嶇疆涓嶈冻
+                listen_codes = gpcode_manager.get_listen_codes()
+                for code in listen_codes:
+                    if not gpcode_manager.is_in_gp_pool(code):
+                        client_id, pos = gpcode_manager.get_listen_code_pos(code)
+                        gpcode_manager.set_listen_code_by_pos(client_id, pos, "")
+                        free_count += 1
+                        if free_count > 2:
+                            break
 
-        print(add_code_list, del_code_list)
+            print(add_code_list, del_code_list)

--
Gitblit v1.8.0