From a20fbda0343efeab3f477ba0d5596f4e9b867c66 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 15 四月 2024 13:32:34 +0800
Subject: [PATCH] 新版深证下单完善

---
 l2/l2_data_manager_new.py |  195 +++++++++++++++++++++++++++---------------------
 1 files changed, 108 insertions(+), 87 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 003a75d..0e934e1 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -1239,17 +1239,18 @@
 
     @classmethod
     def __cancel_buy(cls, code):
-        try:
-            l2_log.debug(code, "寮�濮嬫墽琛屾挙鍗�")
-            trade_manager.start_cancel_buy(code)
-            l2_log.debug(code, "鎵ц鎾ゅ崟鎴愬姛")
-            return True
-        except Exception as e:
-            logging.exception(e)
-            l2_log.debug(code, "鎵ц鎾ゅ崟寮傚父锛歿}", str(e))
-            return False
-        finally:
-            pass
+        with cls.__buy_lock_dict[code]:
+            try:
+                l2_log.debug(code, "寮�濮嬫墽琛屾挙鍗�")
+                trade_manager.start_cancel_buy(code)
+                l2_log.debug(code, "鎵ц鎾ゅ崟鎴愬姛")
+                return True
+            except Exception as e:
+                logging.exception(e)
+                l2_log.debug(code, "鎵ц鎾ゅ崟寮傚父锛歿}", str(e))
+                return False
+            finally:
+                pass
 
     @classmethod
     def cancel_buy(cls, code, msg=None, source="l2", cancel_index=None):
@@ -1466,7 +1467,8 @@
         # 涔板叆绾拱棰濈粺璁�
         new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new, not_buy_msg = None, None, None, None, [], ""
         if order_begin_pos.mode == OrderBeginPosInfo.MODE_ACTIVE:
-            threshold_money = order_begin_pos.threshold_money
+            # 璁剧疆涓烘�诲崠棰�
+            threshold_money = order_begin_pos.sell_info[0]
             new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_active(
                 code,
                 start_process_index,
@@ -1572,7 +1574,7 @@
 
     @classmethod
     def save_order_begin_data(cls, code, info: OrderBeginPosInfo):
-        cls.__save_order_begin_data(code,info)
+        cls.__save_order_begin_data(code, info)
 
     # 璁$畻涓嬪崟璧峰淇″彿
     # compute_data_count 鐢ㄤ簬璁$畻鐨刲2鏁版嵁鏁伴噺
@@ -1689,83 +1691,101 @@
         start_time_str = total_datas[start_index]["val"]["time"]
         # 鑾峰彇鏈�杩戠殑鎬诲崠淇℃伅
         refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, start_time_str)
-        if refer_sell_data is None and start_time_str != '09:30:00':
-            return False, -1, "鎬诲崠涓虹┖"
-        if refer_sell_data is None:
-            refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0))
-            l2_log.debug(code, f"涓㈠け鎬诲崠棰濓紝璁剧疆榛樿涓�0锛岃绠楄寖鍥达細{start_index}-{end_index}")
-        # 鑾峰彇褰撳墠鏄惁鍙縺杩涗拱
-        # 鑾峰彇鏉垮潡鏄惁鍙互婵�杩涗拱
-        # 鍙拱鐨勬澘鍧�, 鏄惁鐙嫍, 娑堟伅, 鍙拱鐨勫己鍔挎澘鍧�, 鍏抽敭璇�, 婵�杩涗拱鐨勬澘鍧�
-        can_buy_result = CodePlateKeyBuyManager.can_buy(code)
-        if (can_buy_result and can_buy_result[0] and can_buy_result[5]) or constant.ALL_ACTIVE_BUY:
-            # 鏈夊彲涔版澘鍧楋紝鏈夋縺杩涗拱鏉垮潡
-            # 绗竴姝ワ細 璁$畻鎬诲崠棰�
-            threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0]
-            if code.find("60") == 0:
-                threshold_money = 0
-            else:
-                pass
-                # for i in range(start_index - 1, -1, -1):
-                #     val = total_datas[i]["val"]
-                #     if tool.compare_time(val["time"], refer_sell_data[0]) < 0:
-                #         # 灏嗘湰s鐨勮绠椾笂鍘�
-                #         break
-                #     if L2DataUtil.is_sell(val):
-                #         threshold_money += val["num"] * int(float(val["price"]) * 100)
-                #     elif L2DataUtil.is_sell_cancel(val):
-                #         threshold_money -= val["num"] * int(float(val["price"]) * 100)
-                #     elif L2DataUtil.is_buy(val):
-                #         # 鍒ゆ柇浠锋牸锛堝ぇ浜庡崠1锛� 琚拱鍚冩帀
-                #         if round(float(val["price"]), 2) - sell_1_price >= 0:
-                #             threshold_money -= val["num"] * int(float(val["price"]) * 100)
-            # 绗簩姝ワ細璁$畻璧峰淇″彿
-            second_930 = 9 * 3600 + 30 * 60 + 0
-            total_datas = local_today_datas.get(code)
-            if end_index - start_index + 1 < continue_count:
-                return False, -1, "淇″彿涓嶈繛缁�"
-            last_index = None
-            count = 0
-            start = None
+        if code.find("60") == 0:
+            if refer_sell_data is None:
+                # 璁剧疆榛樿鍗栦俊鎭�
+                refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0))
+            # 涓婅瘉:鍙鏈変竴涓定鍋滀拱鐨勫氨鏄俊鍙�
             for i in range(start_index, end_index + 1):
                 _val = total_datas[i]["val"]
-                time_s = L2DataUtil.get_time_as_second(_val["time"])
-                # 鏃堕棿瑕�>=09:30:00
-                if time_s < second_930:
+                if not L2DataUtil.is_limit_up_price_buy(_val):
                     continue
-                if L2DataUtil.is_limit_up_price_buy(_val):
-                    # 閲戦瑕佸ぇ浜�50涓�
-                    if _val["num"] * float(_val["price"]) < 5000:
-                        continue
-                    if last_index is None or (total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]):
-                        if code.find("00") == 0 and threshold_money > 0:
-                            # 娣辫瘉闈炴澘涓婃斁閲忛渶瑕佸垽鏂槸鍚︽湁淇″彿
-                            single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single(code,
-                                                                                                                     tool.to_time_with_ms(
-                                                                                                                         _val['time'],
-                                                                                                                         _val['tms']))
-                            if not single:
-                                continue
-                        if start is None:
-                            start = i
-                        last_index = i
-                        count += total_datas[i]["re"]
-                        if count >= continue_count:
-                            return True, start, [refer_sell_data[0], threshold_money]
-                    else:
-                        # 鏈潯鏁版嵁浣滀负璧风偣
-                        last_index = i
-                        count = total_datas[i]["re"]
-                        start = i
-
-                elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val):
-                    # 鍓旈櫎鍗栦笌鍗栨挙
-                    last_index = None
-                    count = 0
-                    start = None
-            return False, -1, "鏈幏鍙栧埌婵�杩涗拱鐨勮捣濮嬩俊鍙�"
+                # 鏃堕棿瑕�>=09:30:00
+                if tool.trade_time_sub(_val["time"], "09:30:00") < 0:
+                    continue
+                # 閲戦瑕佸ぇ浜�50涓�
+                if _val["num"] * float(_val["price"]) < 5000:
+                    continue
+                return True, i, [refer_sell_data[0], 0]
         else:
-            return False, -1, "涓嶅彲婵�杩涗拱"
+            # 娣辫瘉
+            if refer_sell_data is None and start_time_str != '09:30:00':
+                return False, -1, "鎬诲崠涓虹┖"
+            if refer_sell_data is None:
+                refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0))
+                l2_log.debug(code, f"涓㈠け鎬诲崠棰濓紝璁剧疆榛樿涓�0锛岃绠楄寖鍥达細{start_index}-{end_index}")
+            # 鑾峰彇褰撳墠鏄惁鍙縺杩涗拱
+            # 鑾峰彇鏉垮潡鏄惁鍙互婵�杩涗拱
+            # 鍙拱鐨勬澘鍧�, 鏄惁鐙嫍, 娑堟伅, 鍙拱鐨勫己鍔挎澘鍧�, 鍏抽敭璇�, 婵�杩涗拱鐨勬澘鍧�
+            can_buy_result = CodePlateKeyBuyManager.can_buy(code)
+            if (can_buy_result and can_buy_result[0] and can_buy_result[5]) or constant.ALL_ACTIVE_BUY:
+                # 鏈夊彲涔版澘鍧楋紝鏈夋縺杩涗拱鏉垮潡
+                # 绗竴姝ワ細 璁$畻鎬诲崠棰�
+                threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0]
+                if code.find("60") == 0:
+                    threshold_money = 0
+                else:
+                    pass
+                    # for i in range(start_index - 1, -1, -1):
+                    #     val = total_datas[i]["val"]
+                    #     if tool.compare_time(val["time"], refer_sell_data[0]) < 0:
+                    #         # 灏嗘湰s鐨勮绠椾笂鍘�
+                    #         break
+                    #     if L2DataUtil.is_sell(val):
+                    #         threshold_money += val["num"] * int(float(val["price"]) * 100)
+                    #     elif L2DataUtil.is_sell_cancel(val):
+                    #         threshold_money -= val["num"] * int(float(val["price"]) * 100)
+                    #     elif L2DataUtil.is_buy(val):
+                    #         # 鍒ゆ柇浠锋牸锛堝ぇ浜庡崠1锛� 琚拱鍚冩帀
+                    #         if round(float(val["price"]), 2) - sell_1_price >= 0:
+                    #             threshold_money -= val["num"] * int(float(val["price"]) * 100)
+                # 绗簩姝ワ細璁$畻璧峰淇″彿
+                second_930 = 9 * 3600 + 30 * 60 + 0
+                total_datas = local_today_datas.get(code)
+                if end_index - start_index + 1 < continue_count:
+                    return False, -1, "淇″彿涓嶈繛缁�"
+                last_index = None
+                count = 0
+                start = None
+                for i in range(start_index, end_index + 1):
+                    _val = total_datas[i]["val"]
+                    time_s = L2DataUtil.get_time_as_second(_val["time"])
+                    # 鏃堕棿瑕�>=09:30:00
+                    if time_s < second_930:
+                        continue
+                    if L2DataUtil.is_limit_up_price_buy(_val):
+                        # 閲戦瑕佸ぇ浜�50涓�
+                        if _val["num"] * float(_val["price"]) < 5000:
+                            continue
+                        if last_index is None or (
+                                total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]):
+                            if code.find("00") == 0 and threshold_money > 0:
+                                # 娣辫瘉闈炴澘涓婃斁閲忛渶瑕佸垽鏂槸鍚︽湁淇″彿
+                                single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single(
+                                    code,
+                                    tool.to_time_with_ms(
+                                        _val['time'],
+                                        _val['tms']))
+                                if not single:
+                                    continue
+                            if start is None:
+                                start = i
+                            last_index = i
+                            count += total_datas[i]["re"]
+                            if count >= continue_count:
+                                return True, start, [refer_sell_data[0], threshold_money]
+                        else:
+                            # 鏈潯鏁版嵁浣滀负璧风偣
+                            last_index = i
+                            count = total_datas[i]["re"]
+                            start = i
+
+                    elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val):
+                        # 鍓旈櫎鍗栦笌鍗栨挙
+                        last_index = None
+                        count = 0
+                        start = None
+            return False, -1, "鏈幏鍙栧埌婵�杩涗拱鐨勮捣濮嬩俊鍙�"
 
     @classmethod
     def __get_threshmoney(cls, code):
@@ -2141,7 +2161,8 @@
         if code.find("00") == 0 and threshold_money > 0:
             # 娣辫瘉闈炴澘涓婃斁閲�
             max_space_time_ms = 1 * 1000
-            threshold_num = 0
+        # 涓嶇湅绾拱棰�
+        threshold_num = 0
 
         # 涓嶄笅鍗曠殑淇℃伅
         not_buy_msg = ""

--
Gitblit v1.8.0