From 0e642d0c27e40df326733401be6f8c8115e54911 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期三, 23 七月 2025 17:01:25 +0800
Subject: [PATCH] L后默认撤单率修改/启用F撤

---
 l2/l2_data_manager.py |  138 ++++++++++++++++++++++++++++++----------------
 1 files changed, 90 insertions(+), 48 deletions(-)

diff --git a/l2/l2_data_manager.py b/l2/l2_data_manager.py
index 643bb3f..bbbe0ef 100644
--- a/l2/l2_data_manager.py
+++ b/l2/l2_data_manager.py
@@ -5,12 +5,61 @@
 
 from db import redis_manager_delegate as redis_manager
 from db.redis_manager_delegate import RedisUtils
-from log_module.log import logger_debug
 from utils import tool
 from utils.tool import CodeDataCacheUtil
 
 _db = 1
 _redisManager = redis_manager.RedisManager(1)
+
+
+# 涓嬪崟涓存椂淇℃伅
+class OrderBeginPosInfo(object):
+    MODE_NORMAL = 0  # 鏅�氫笅鍗�
+    MODE_FAST = 1
+    MODE_ACTIVE = 2  # 绉瀬鍔ㄤ拱
+    MODE_RADICAL = 3  # 鎵叆
+    MODE_OPEN_LIMIT_UP = 4  # 鎺�1
+
+    # mode: 0-鏅�氫氦鏄�  1-蹇�熶氦鏄�
+    def __init__(self, buy_single_index=None, buy_exec_index=-1, buy_compute_index=None, num=0, count=0,
+                 max_num_set=None, buy_volume_rate=None, sell_info=None, threshold_money=None, mode=0, mode_desc=None,
+                 at_limit_up=False, first_limit_up_buy=False, min_order_no = None):
+        self.buy_single_index = buy_single_index
+        self.buy_exec_index = buy_exec_index
+        self.buy_compute_index = buy_compute_index
+        self.num = num
+        self.count = count
+        self.threshold_money = threshold_money
+        if max_num_set:
+            self.max_num_set = list(max_num_set)
+        else:
+            self.max_num_set = []
+        self.buy_volume_rate = buy_volume_rate
+        self.sell_info = sell_info
+        self.mode = mode
+        self.mode_desc = mode_desc
+        # 鏄惁鏄澘涓婁拱
+        self.at_limit_up = at_limit_up
+        # 鏄惁涓洪灏佷拱
+        self.first_limit_up_buy = first_limit_up_buy
+        # 缁熻鎵规澶у崟鎴愪氦鐨勬渶灏忚鍗曞彿
+        self.min_order_no = min_order_no
+
+    def get_max_num_set(self):
+        if self.max_num_set:
+            return set(self.max_num_set)
+        return None
+
+    def to_json_str(self):
+        return json.dumps(vars(self))
+
+    def to_dict(self):
+        return vars(self)
+
+    @classmethod
+    def to_object(cls, json_str: str):
+        d = json.loads(json_str)
+        return OrderBeginPosInfo(**d)
 
 
 class L2DataException(Exception):
@@ -38,6 +87,8 @@
     __buy_compute_index_info_cache = {}
     __buy_cancel_single_pos_cache = {}
     __instance = None
+    # 鏈�杩戠殑涓嬪崟妯″紡
+    __latest_place_order_mode_cache = {}
 
     def __new__(cls, *args, **kwargs):
         if not cls.__instance:
@@ -57,8 +108,8 @@
         for k in keys:
             code = k.split("-")[-1]
             val = RedisUtils.get(redis_, k)
-            val = json.loads(val)
-            CodeDataCacheUtil.set_cache(cls.__buy_compute_index_info_cache, code, val)
+            order = OrderBeginPosInfo.to_object(val)
+            CodeDataCacheUtil.set_cache(cls.__buy_compute_index_info_cache, code, order)
 
         keys = RedisUtils.keys(redis_, "buy_cancel_single_pos-*")
         for k in keys:
@@ -67,14 +118,12 @@
             CodeDataCacheUtil.set_cache(cls.__buy_cancel_single_pos_cache, code, int(val))
 
     # 鍒犻櫎涔板叆鐐规暟鎹�
-
     def delete_buy_point(self, code):
         CodeDataCacheUtil.clear_cache(self.__buy_compute_index_info_cache, code)
         RedisUtils.delete_async(self.__db, "buy_compute_index_info-{}".format(code))
 
     # 鑾峰彇涔板叆鐐逛俊鎭�
     # 杩斿洖鏁版嵁涓猴細涔板叆鐐� 绱绾拱棰� 宸茬粡璁$畻鐨勬暟鎹储寮�
-
     def get_buy_compute_start_data(self, code):
         _key = "buy_compute_index_info-{}".format(code)
         _data_json = RedisUtils.get(self.__get_redis(), _key)
@@ -83,11 +132,12 @@
         _data = json.loads(_data_json)
         return _data[0], _data[1], _data[2], _data[3], _data[4], _data[5], _data[6]
 
-    def get_buy_compute_start_data_cache(self, code):
+    def get_buy_compute_start_data_cache(self, code) -> OrderBeginPosInfo:
         cache_result = CodeDataCacheUtil.get_cache(self.__buy_compute_index_info_cache, code)
         if cache_result[0]:
             return cache_result[1]
-        return None, None, None, 0, 0, [], 0
+
+        return OrderBeginPosInfo()
 
     # 璁剧疆涔板叆鐐圭殑鍊�
     # buy_single_index 涔板叆淇″彿浣�
@@ -95,53 +145,36 @@
     # compute_index 璁$畻浣嶇疆
     # nums 绱绾拱棰�
 
-    def set_buy_compute_start_data(self, code, buy_single_index, buy_exec_index, compute_index, nums, count,
-                                   max_num_sets,
-                                   volume_rate):
+    def set_buy_compute_start_data_v2(self, code, order: OrderBeginPosInfo):
+
+        if order.mode is not None:
+            self.__latest_place_order_mode_cache[code] = order.mode
+
         expire = tool.get_expire()
         _key = "buy_compute_index_info-{}".format(code)
         data_ = None
-        if buy_single_index is not None:
-            data_ = (buy_single_index, buy_exec_index, compute_index, nums, count, list(max_num_sets),
-                     volume_rate)
+        if order.buy_single_index is not None:
+            data_ = order
         else:
-            _buy_single_index, _buy_exec_index, _compute_index, _nums, _count, _max_num_index, _volume_rate = self.get_buy_compute_start_data_cache(
-                code)
-            data_ = (_buy_single_index, buy_exec_index, compute_index, nums, count, list(max_num_sets),
-                     volume_rate)
-        logger_debug.info(f"淇濆瓨涔板叆鎵ц浣嶇疆淇℃伅{code}锛歿data_}")
+            old_order = self.get_buy_compute_start_data_cache(code)
+            order.buy_single_index = old_order.buy_single_index
+            data_ = order
         CodeDataCacheUtil.set_cache(self.__buy_compute_index_info_cache, code, data_)
-        RedisUtils.setex_async(self.__db, _key, expire, json.dumps(data_))
+        RedisUtils.setex_async(self.__db, _key, expire, data_.to_json_str())
 
-    # 鑾峰彇鎾や拱鍏ュ紑濮嬭绠楃殑淇℃伅
-    # 杩斿洖鏁版嵁鐨勫唴瀹逛负锛氭挙閿�鐐圭储寮� 鎾や拱绾拱棰� 璁$畻鐨勬暟鎹储寮�
+    # 鏄惁宸茬粡涓嬪崟
+    @classmethod
+    def is_placed_order(cls, order_begin_pos: OrderBeginPosInfo):
+        return order_begin_pos and order_begin_pos.buy_exec_index is not None and order_begin_pos.buy_exec_index > -1
 
-    def get_buy_cancel_single_pos(self, code):
-        info = RedisUtils.get(self.__get_redis(), "buy_cancel_single_pos-{}".format(code))
-        if info is None:
-            return None
-        else:
-            return int(info)
-
-    def get_buy_cancel_single_pos_cache(self, code):
-        cache_result = tool.CodeDataCacheUtil.get_cache(self.__buy_cancel_single_pos_cache, code)
-        if cache_result[0]:
-            return cache_result[1]
-        return None
-
-    # 璁剧疆涔版挙鐐逛俊鎭�
-    # buy_num 绾拱棰�  computed_index璁$畻鍒扮殑涓嬫爣  index鎾や拱淇″彿璧风偣
-
-    def set_buy_cancel_single_pos(self, code, index):
-        tool.CodeDataCacheUtil.set_cache(self.__buy_cancel_single_pos_cache, code, index)
-        expire = tool.get_expire()
-        RedisUtils.setex_async(self.__db, "buy_cancel_single_pos-{}".format(code), expire, index)
-
-    # 鍒犻櫎涔版挙鐐规暟鎹�
-    def delete_buy_cancel_point(self, code):
-        tool.CodeDataCacheUtil.clear_cache(self.__buy_cancel_single_pos_cache, code)
-        # TODO 娴嬭瘯
-        # RedisUtils.delete_async(self.__db, "buy_cancel_single_pos-{}".format(code))
+    @classmethod
+    def get_latest_place_order_mode(cls, code):
+        """
+        鑾峰彇鏈�杩戜笅鍗曠殑妯″紡
+        @param code:
+        @return:
+        """
+        return cls.__latest_place_order_mode_cache.get(code)
 
 
 # 娓呴櫎l2鏁版嵁
@@ -194,4 +227,13 @@
 
 
 if __name__ == "__main__":
-    TradePointManager().get_buy_compute_start_data_cache("603912")
+    code = "002886"
+    TradePointManager().set_buy_compute_start_data_v2(code, OrderBeginPosInfo(buy_single_index=10,
+                                                                              buy_exec_index=30,
+                                                                              buy_compute_index=40,
+                                                                              num=20000, count=10,
+                                                                              buy_volume_rate=0.6,
+                                                                              mode=OrderBeginPosInfo.MODE_NORMAL,
+                                                                              ))
+    print(TradePointManager().get_buy_compute_start_data_cache(code).max_num_set)
+    RedisUtils.run_loop()

--
Gitblit v1.8.0