From 090c62e276a49fb5d16438a4a33f06522dbccc1f Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 17 八月 2023 18:07:44 +0800
Subject: [PATCH] 删除虚拟下单

---
 l2/l2_data_manager_new.py |  224 +++++++++++--------------------------------------------
 1 files changed, 47 insertions(+), 177 deletions(-)

diff --git a/l2/l2_data_manager_new.py b/l2/l2_data_manager_new.py
index 18b503d..f06962d 100644
--- a/l2/l2_data_manager_new.py
+++ b/l2/l2_data_manager_new.py
@@ -8,12 +8,13 @@
 from db.redis_manager_delegate import RedisUtils
 from l2.huaxin import l2_huaxin_util, huaxin_delegate_postion_manager
 from third_data import kpl_data_manager, block_info
+from trade.deal_big_money_manager import DealComputeProgressManager
 from utils import global_util, ths_industry_util, tool
 import l2_data_util
 from db import redis_manager_delegate as redis_manager
 from third_data.code_plate_key_manager import CodePlateKeyBuyManager
 from trade import trade_manager, trade_queue_manager, l2_trade_factor, l2_trade_util, \
-    trade_result_manager, first_code_score_manager, current_price_process_manager, trade_data_manager
+    trade_result_manager, first_code_score_manager, current_price_process_manager, trade_data_manager, trade_huaxin
 from l2 import safe_count_manager, l2_data_manager, l2_data_log, l2_log, l2_data_source_util, code_price_manager, \
     transaction_progress
 from l2.cancel_buy_strategy import SecondCancelBigNumComputer, HourCancelBigNumComputer, L2LimitUpMoneyStatisticUtil, \
@@ -220,13 +221,20 @@
     __SecondCancelBigNumComputer = SecondCancelBigNumComputer()
     __HourCancelBigNumComputer = HourCancelBigNumComputer()
     __LCancelBigNumComputer = LCancelBigNumComputer()
+    __DCancelBigNumComputer = DCancelBigNumComputer()
     __TradeStateManager = trade_manager.TradeStateManager()
     __CodesTradeStateManager = trade_manager.CodesTradeStateManager()
     __PauseBuyCodesManager = gpcode_manager.PauseBuyCodesManager()
     __Buy1PriceManager = code_price_manager.Buy1PriceManager()
     __AccountAvailableMoneyManager = AccountAvailableMoneyManager()
     __TradeBuyDataManager = trade_data_manager.TradeBuyDataManager()
-    __LimitUpTimeManager =  limit_up_time_manager.LimitUpTimeManager()
+    __LimitUpTimeManager = limit_up_time_manager.LimitUpTimeManager()
+    __BlackListCodeManager = l2_trade_util.BlackListCodeManager()
+    __WhiteListCodeManager = l2_trade_util.WhiteListCodeManager()
+    __WantBuyCodesManager = gpcode_manager.WantBuyCodesManager()
+    __TradeTargetCodeModeManager = TradeTargetCodeModeManager()
+    __DealComputeProgressManager = DealComputeProgressManager()
+    __TradeOrderIdManager = trade_huaxin.TradeOrderIdManager()
 
     # 鑾峰彇浠g爜璇勫垎
     @classmethod
@@ -304,7 +312,7 @@
             place_order_index = huaxin_delegate_postion_manager.get_l2_place_order_position(code, datas)
             if place_order_index:
                 logger_l2_process.info("code:{} 鑾峰彇鍒颁笅鍗曠湡瀹炰綅缃細{}", code, place_order_index)
-                DCancelBigNumComputer().set_real_order_index(code, place_order_index)
+                cls.__DCancelBigNumComputer.set_real_order_index(code, place_order_index)
             __start_time = round(t.time() * 1000)
             if len(datas) > 0:
                 cls.process_add_datas(code, datas, 0, __start_time)
@@ -451,52 +459,14 @@
             return
         cls.__latest_process_unique_keys[code] = unique_key
 
-        # 璁$畻瀹夊叏绗旀暟
-        @dask.delayed
-        def compute_safe_count():
-            _start_time = round(t.time() * 1000)
-            # 澶勭悊瀹夊叏绗旀暟
-            cls.__buyL2SafeCountManager.compute_left_rate(code, start_index, end_index, total_data,
-                                                          local_today_num_operate_map.get(code))
-
-            # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
-            #                     "宸蹭笅鍗�-鑾峰彇涔板叆淇℃伅鑰楁椂")
-            return None, ""
-
-        @dask.delayed
-        # m鍊煎ぇ鍗曡绠�
-        def compute_m_big_num():
-            _start_time = round(t.time() * 1000)
-            # 璁$畻m鍊煎ぇ鍗�
-            cls.l2BigNumForMProcessor.process(code, max(buy_single_index, start_index), end_index,
-                                              gpcode_manager.get_limit_up_price(code))
-            # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
-            #                     "宸蹭笅鍗�-m鍊煎ぇ鍗曡绠�")
-            return None, ""
-
-        # 涔�1鎾よ绠�
-        @dask.delayed
-        def buy_1_cancel():
-            _start_time = round(t.time() * 1000)
-            # 鎾ゅ崟璁$畻,鍙湅涔�1
-            cancel_data, cancel_msg = L2LimitUpMoneyStatisticUtil().process_data(code, start_index,
-                                                                                 end_index,
-                                                                                 buy_single_index, buy_exec_index)
-
-            # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
-            #                     "宸蹭笅鍗�-涔�1缁熻鑰楁椂")
-            # 涔�1涓嶄細瑙﹀彂鎾ゅ崟
-            return None, ""
-            # return cancel_data, cancel_msg
-
         # S鎾�
-        # @dask.delayed
-        def s_cancel(_buy_single_index,_buy_exec_index):
+        def s_cancel(_buy_single_index, _buy_exec_index):
             _start_time = round(t.time() * 1000)
             # S鎾ゅ崟璁$畻锛岀湅绉掔骇澶у崟鎾ゅ崟
             try:
                 b_need_cancel, b_cancel_data = cls.__SecondCancelBigNumComputer.need_cancel(code, _buy_single_index,
-                                                                                            _buy_exec_index, start_index,
+                                                                                            _buy_exec_index,
+                                                                                            start_index,
                                                                                             end_index, total_data,
                                                                                             code_volumn_manager.get_volume_rate_index(
                                                                                                 buy_volume_rate),
@@ -516,8 +486,7 @@
             return None, ""
 
         # H鎾�
-        # @dask.delayed
-        def h_cancel(_buy_single_index,_buy_exec_index):
+        def h_cancel(_buy_single_index, _buy_exec_index):
             _start_time = round(t.time() * 1000)
             try:
                 b_need_cancel, b_cancel_data = cls.__HourCancelBigNumComputer.need_cancel(code, _buy_single_index,
@@ -541,8 +510,7 @@
             return None, ""
 
         # L鎾�
-        # @dask.delayed
-        def l_cancel(_buy_single_index,_buy_exec_index):
+        def l_cancel(_buy_single_index, _buy_exec_index):
             _start_time = round(t.time() * 1000)
             try:
                 b_need_cancel, b_cancel_data = cls.__LCancelBigNumComputer.need_cancel(code,
@@ -561,37 +529,6 @@
                 pass
             return None, ""
 
-        # 鏉夸笂鍗栨挙
-        @dask.delayed
-        def sell_cancel():
-            _start_time = round(t.time() * 1000)
-            # 缁熻鏉夸笂鍗�
-            try:
-                cancel_data, cancel_msg = L2LimitUpSellStatisticUtil().process(code, start_index,
-                                                                               end_index,
-                                                                               buy_exec_index)
-                return cancel_data, cancel_msg
-            except Exception as e:
-                logging.exception(e)
-            finally:
-                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time, "宸蹭笅鍗�-鏉夸笂鍗栬�楁椂")
-                pass
-            return None, ""
-
-        # 鏄惁闇�瑕佹挙閿�
-        @dask.delayed
-        def is_need_cancel(*args):
-            try:
-                for i in range(0, len(args)):
-                    _cancel_data, _cancel_msg = args[i]
-                    if _cancel_data:
-                        return _cancel_data, _cancel_msg
-            except Exception as e:
-                logging.exception(e)
-            finally:
-                pass
-            return None, ""
-
         if start_index < 0:
             start_index = 0
 
@@ -602,20 +539,6 @@
         # 鑾峰彇涔板叆淇″彿璧峰鐐�
         buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos(
             code)
-        # 鑰佺増鏈挙鍗�
-        # f1 = compute_safe_count()
-        # f2 = compute_m_big_num()
-        # f3 = s_cancel()
-        # f4 = h_cancel()
-        # f5 = buy_1_cancel()
-        # f6 = sell_cancel()
-        # f7 = l_cancel()
-        # dask_result = is_need_cancel(f1, f2, f3, f4, f5, f6, f7)
-        # if is_first_code:
-        #     dask_result = is_need_cancel(f3, f4, f7)
-        # l2_log.debug(code, "鎾ゅ崟璁$畻寮�濮�")
-        # cancel_data, cancel_msg = dask_result.compute()
-        # l2_log.debug(code, "鎾ゅ崟璁$畻缁撴潫")
 
         # 渚濇澶勭悊
         cancel_data, cancel_msg = s_cancel(buy_single_index, buy_exec_index)
@@ -641,26 +564,7 @@
                 # 鎾ゅ崟灏氭湭鎴愬姛
                 pass
         else:
-            # 濡傛灉鏈夎櫄鎷熶笅鍗曢渶瑕佺湡瀹炰笅鍗�
-            unreal_buy_info = cls.unreal_buy_dict.get(code)
-            if unreal_buy_info is not None:
-                l2_log.debug(code, "鏈夎櫄鎷熶笅鍗曪紝鏃犱拱鎾や俊鍙凤紝寮�濮嬫墽琛屼拱鍏ワ紝鎵ц浣嶇疆锛歿},鎴浘鏃堕棿锛歿}", unreal_buy_info[0], capture_time)
-                # unreal_buy_info 鐨勫唴瀹规牸寮忎负锛�(瑙︽硶涔版搷浣滀笅鏍�,鎴浘鏃堕棿)
-                # 鐪熷疄涓嬪崟
-                cls.__buy(code, unreal_buy_info[1], local_today_datas[code][unreal_buy_info[0]],
-                          unreal_buy_info[0], is_first_code)
-                # lp = LineProfiler()
-                # lp.enable()
-                # lp_wrap = lp(cls.__buy)
-                # lp_wrap(code, unreal_buy_info[1], local_today_datas[code][unreal_buy_info[0]],
-                #         unreal_buy_info[0], is_first_code)
-                # output = io.StringIO()
-                # lp.print_stats(stream=output)
-                # lp.disable()
-                # logger_profile.info(output.getvalue())
-
-                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
-                #                                   "宸茶櫄鎷熶笅鍗�-鎵ц鐪熷疄涓嬪崟 澶栭儴鑰楁椂")
+            pass
 
     @classmethod
     def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code):
@@ -713,7 +617,7 @@
     def __can_cancel(cls, code):
         if constant.TEST:
             return True, ""
-        if l2_trade_util.WhiteListCodeManager().is_in_cache(code):
+        if cls.__WhiteListCodeManager.is_in_cache(code):
             return False, "浠g爜鍦ㄧ櫧鍚嶅崟涓�"
 
         # 鏆傛椂娉ㄩ噴鎺�
@@ -802,7 +706,7 @@
             if volumn_rate >= 1.3:
                 return False, False, "鏈�澶ч噺姣旇秴杩�1.3涓嶈兘涔�"
 
-            limit_up_time =cls.__LimitUpTimeManager.get_limit_up_time_cache(code)
+            limit_up_time = cls.__LimitUpTimeManager.get_limit_up_time_cache(code)
             if limit_up_time is not None:
                 limit_up_time_seconds = l2.l2_data_util.L2DataUtil.get_time_as_second(
                     limit_up_time)
@@ -962,8 +866,8 @@
         #                               cls.__l2PlaceOrderParamsManagerDict[code].score_index,
         #                               cls.__l2PlaceOrderParamsManagerDict[code].score_info)
 
-        if not gpcode_manager.WantBuyCodesManager().is_in_cache(code):
-            if TradeTargetCodeModeManager().get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES:
+        if not cls.__WantBuyCodesManager.is_in_cache(code):
+            if cls.__TradeTargetCodeModeManager.get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES:
                 return False, True, f"鍙拱鎯充拱鍗曚腑鐨勪唬鐮�"
             score_index = None  # cls.__l2PlaceOrderParamsManagerDict[code].score_index
             score = None  # cls.__l2PlaceOrderParamsManagerDict[code].score
@@ -1169,82 +1073,48 @@
                                         buy_nums, buy_count, max_num_set_new,
                                         cls.volume_rate_info[code][0])
             l2_log.debug(code, "__save_order_begin_data")
-            cls.__LimitUpTimeManager.save_limit_up_time(code,total_datas[compute_index]["val"]["time"])
+            cls.__LimitUpTimeManager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"])
             l2_log.debug(code, "save_limit_up_time")
             cls.__virtual_buy(code, buy_single_index, compute_index, capture_time)
             l2_log.debug(code, "__virtual_buy")
             cls.__TradePointManager.delete_buy_cancel_point(code)
             l2_log.debug(code, "delete_buy_cancel_point")
-            # 鏆傛椂涓嶉渶瑕�
-            # f5 = dask.delayed(L2LimitUpMoneyStatisticUtil.process_data)(code, buy_single_index,
-            #                                                             compute_index,
-            #                                                             buy_single_index,
-            #                                                             buy_exec_index, False)
-
-            # 宸茶骞惰澶勭悊
-            # # 璁板綍涔板叆淇″彿浣嶇疆
-            # cls.__save_order_begin_data(code, buy_single_index, compute_index, compute_index, buy_nums, buy_count,
-            #                             max_num_set_new)
-            # # 濡傛灉鏄粖澶╃涓�娆℃湁涓嬪崟鎵ц淇″彿锛屾定鍋滄椂闂达紙涔板叆鎵ц浣嶆椂闂达級
-            # limit_up_time_manager.save_limit_up_time(code, total_datas[compute_index]["val"]["time"])
-            # # 铏氭嫙涓嬪崟
-            # cls.__virtual_buy(code, buy_single_index, compute_index, capture_time)
-            # # 鍒犻櫎涔嬪墠鐨勬墍鏈夋挙鍗曚俊鍙�
-            # l2_data_manager.TradePointManager.delete_buy_cancel_point(code)
-            #
-            # # 娑ㄥ仠灏佸崟棰濊绠�
-            # L2LimitUpMoneyStatisticUtil.process_data(cls.random_key[code], code, buy_single_index, compute_index,
-            #                                          buy_single_index,
-            #                                          buy_exec_index, False)
-
-            # l2_log.debug(code, "璁板綍鎵ц涔板叆鏁版嵁缁撴潫")
-
-            # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
-            #                                   "璁板綍鎵ц涔板叆鏁版嵁", force=True)
+            # 鐩存帴涓嬪崟
+            cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
 
             # 鏁版嵁鏄惁澶勭悊瀹屾瘯
             if compute_index >= compute_end_index:
-                need_cancel, cancel_data = cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index,
-                                                                                        compute_index,
-                                                                                        buy_single_index, compute_index,
-                                                                                        total_datas, is_first_code,
-                                                                                        cls.volume_rate_info[code][1],
-                                                                                        cls.volume_rate_info[code][1],
-                                                                                        True)
+                # need_cancel, cancel_data = cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index,
+                #                                                                         compute_index,
+                #                                                                         buy_single_index, compute_index,
+                #                                                                         total_datas, is_first_code,
+                #                                                                         cls.volume_rate_info[code][1],
+                #                                                                         cls.volume_rate_info[code][1],
+                #                                                                         True)
                 # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                 #                                   "S绾уぇ鍗曞鐞嗚�楁椂", force=True)
-                l2_log.debug(code, "鏁版嵁澶勭悊瀹屾瘯锛屼笅鍗�, 鏁版嵁鎴浘鏃堕棿-{}", capture_time)
+                # l2_log.debug(code, "鏁版嵁澶勭悊瀹屾瘯锛屼笅鍗�, 鏁版嵁鎴浘鏃堕棿-{}", capture_time)
                 # 鏁版嵁宸茬粡澶勭悊瀹屾瘯锛屽鏋滆繕娌℃挙鍗曞氨瀹為檯涓嬪崟
-                if need_cancel:
-                    if cls.cancel_buy(code, "S绾уぇ鍗曟挙閿�"):
-                        # 鎵ц鎾ゅ崟鎴愬姛
-                        pass
-                else:
-                    cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
+                # if need_cancel:
+                #     if cls.cancel_buy(code, "S绾уぇ鍗曟挙閿�"):
+                #         # 鎵ц鎾ゅ崟鎴愬姛
+                #         pass
+                # else:
+                # cls.__buy(code, capture_time, total_datas[compute_index], compute_index, is_first_code)
+                pass
             else:
-                cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index, compute_index, buy_single_index,
-                                                             compute_index, total_datas, is_first_code,
-                                                             cls.volume_rate_info[code][1],
-                                                             cls.volume_rate_info[code][1], False)
-                l2_log.debug(code, "S绾уぇ鍗曞鐞�")
+                # cls.__SecondCancelBigNumComputer.need_cancel(code, buy_single_index, compute_index, buy_single_index,
+                #                                              compute_index, total_datas, is_first_code,
+                #                                              cls.volume_rate_info[code][1],
+                #                                              cls.volume_rate_info[code][1], False)
+                # l2_log.debug(code, "S绾уぇ鍗曞鐞�")
 
                 # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
                 #                                   "S绾уぇ鍗曞鐞嗚�楁椂", force=True)
                 # 鏁版嵁灏氭湭澶勭悊瀹屾瘯锛岃繘琛屼笅涓�姝ュ鐞�
-                l2_log.debug(code, "鏁版嵁灏氭湭澶勭悊瀹屾瘯锛岃繘琛屼笅涓�姝ュ鐞嗭紝澶勭悊杩涘害锛歿} end_index:{}", compute_index, compute_end_index)
+                # l2_log.debug(code, "鏁版嵁灏氭湭澶勭悊瀹屾瘯锛岃繘琛屼笅涓�姝ュ鐞嗭紝澶勭悊杩涘害锛歿} end_index:{}", compute_index, compute_end_index)
                 # 澶勭悊鎾ゅ崟姝ラ
                 cls.__process_order(code, compute_index + 1, compute_end_index, capture_time, is_first_code, False)
-                # lp = LineProfiler()
-                # lp.enable()
-                # lp_wrap = lp(cls.__process_order)
-                # lp_wrap(code, compute_index + 1, compute_end_index, capture_time, is_first_code, False)
-                # output = io.StringIO()
-                # lp.print_stats(stream=output)
-                # lp.disable()
-                # logger_profile.info(output.getvalue())
-
-                # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time,
-                #                                   f"澶勭悊鎾ゅ崟姝ラ鑰楁椂锛岃寖鍥达細{compute_index + 1}-{compute_end_index}", force=True)
         else:
             # 鏈揪鍒颁笅鍗曟潯浠讹紝淇濆瓨绾拱棰濓紝璁剧疆绾拱棰�
             # 璁板綍涔板叆淇″彿浣嶇疆
@@ -1345,7 +1215,7 @@
 
         _start_time = t.time()
         total_datas = local_today_datas[code]
-        is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code)
+        # is_first_code = gpcode_manager.FirstCodeManager().is_in_first_record_cache(code)
 
         buy_nums = origin_num
         buy_count = origin_count
@@ -1382,7 +1252,7 @@
             trigger_buy = False
             # 蹇呴』涓鸿繛缁�2绉掑唴鐨勬暟鎹�
             if L2DataUtil.get_time_as_second(_val["time"]) - buy_single_time_seconds + 1 > max_space_time:
-                TradePointManager().delete_buy_point(code)
+                cls.__TradePointManager.delete_buy_point(code)
                 if i == compute_end_index:
                     # 鏁版嵁澶勭悊瀹屾瘯
                     return None, buy_nums, buy_count, None, max_buy_num_set

--
Gitblit v1.8.0