From 38395204ab04bbca22a5e22be988d826afd5b227 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 10 十一月 2022 15:46:27 +0800
Subject: [PATCH] 修复bug,优化下单

---
 l2_data_manager.py |  241 ++----------------------------------------------
 1 files changed, 11 insertions(+), 230 deletions(-)

diff --git a/l2_data_manager.py b/l2_data_manager.py
index e989b6b..00112ff 100644
--- a/l2_data_manager.py
+++ b/l2_data_manager.py
@@ -251,23 +251,23 @@
     data = data["data"]
     limit_up_price = gpcode_manager.get_limit_up_price(code)
 
-
     datas = L2DataUtil.format_l2_data(data, code, limit_up_price)
     # 鑾峰彇娑ㄥ仠浠�
-    return day, client, channel, code, capture_time, process_time, datas,data
+    return day, client, channel, code, capture_time, process_time, datas, data
 
 
 # 淇濆瓨l2鏁版嵁
 def save_l2_data(code, datas, add_datas):
     redis = _redisManager.getRedis()
-    # 淇濆瓨鏈�杩戠殑鏁版嵁
-    __start_time = round(t.time()* 1000)
-    redis.setex("l2-data-latest-{}".format(code), tool.get_expire(), json.dumps(datas))
-    l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "淇濆瓨鏈�杩憀2鏁版嵁鐢ㄦ椂")
-    # 璁剧疆杩涘唴瀛�
-    local_latest_datas[code] = datas
-    __set_l2_data_latest_count(code, len(datas))
+    # 鍙湁鏈夋柊鏇炬暟鎹墠闇�瑕佷繚瀛�
     if len(add_datas) > 0:
+        # 淇濆瓨鏈�杩戠殑鏁版嵁
+        __start_time = round(t.time() * 1000)
+        redis.setex("l2-data-latest-{}".format(code), tool.get_expire(), json.dumps(datas))
+        l2_data_log.l2_time(code, round(t.time() * 1000) - __start_time, "淇濆瓨鏈�杩憀2鏁版嵁鐢ㄦ椂")
+        # 璁剧疆杩涘唴瀛�
+        local_latest_datas[code] = datas
+        __set_l2_data_latest_count(code, len(datas))
         saveL2Data(code, add_datas)
 
 
@@ -396,10 +396,8 @@
                 datas.append({"key": key, "val": item, "re": 1})
                 dataIndexs.setdefault(key, len(datas) - 1)
         # TODO 娴嬭瘯鐨勬椂鍊欏紑鍚紝鏂逛究璁板綍澶у崟鏁版嵁
-        #l2_data_util.save_big_data(code, same_time_num, data)
+        # l2_data_util.save_big_data(code, same_time_num, data)
         return datas
-
-
 
     @classmethod
     def get_time_as_second(cls, time_str):
@@ -1043,7 +1041,7 @@
 
     @classmethod
     def __get_threshmoney(cls, code):
-        money,msg = l2_trade_factor.L2TradeFactorUtil.compute_m_value(code)
+        money, msg = l2_trade_factor.L2TradeFactorUtil.compute_m_value(code)
         return money
 
     # 鑾峰彇棰勪及鎸備拱浣�
@@ -1915,223 +1913,6 @@
             process_index = end_index
         cls.__save_recod(code, process_index, count)
 
-
-# 娑ㄥ仠灏佸崟棰濈粺璁�
-class L2LimitUpMoneyStatisticUtil:
-    _redisManager = redis_manager.RedisManager(1)
-
-    @classmethod
-    def __get_redis(cls):
-        return cls._redisManager.getRedis()
-
-    # 璁剧疆l2鐨勬瘡涓�绉掓定鍋滃皝鍗曢鏁版嵁
-    @classmethod
-    def __set_l2_second_money_record(cls, code, time, num, from_index, to_index):
-        old_num, old_from, old_to = cls.__get_l2_second_money_record(code, time)
-        if old_num is None:
-            old_num = num
-            old_from = from_index
-            old_to = to_index
-        else:
-            old_num += num
-            old_to = to_index
-
-        key = "l2_limit_up_second_money-{}-{}".format(code, time.replace(":", ""))
-
-        cls.__get_redis().setex(key, tool.get_expire(), json.dumps((old_num, old_from, old_to)))
-
-    @classmethod
-    def __get_l2_second_money_record(cls, code, time):
-        key = "l2_limit_up_second_money-{}-{}".format(code, time.replace(":", ""))
-        val = cls.__get_redis().get(key)
-        return cls.__format_second_money_record_val(val)
-
-    @classmethod
-    def __format_second_money_record_val(cls, val):
-        if val is None:
-            return None, None, None
-        val = json.loads(val)
-        return val[0], val[1], val[2]
-
-    @classmethod
-    def __get_l2_second_money_record_keys(cls, code, time_regex):
-        key = "l2_limit_up_second_money-{}-{}".format(code, time_regex)
-        keys = cls.__get_redis().keys(key)
-        return keys
-
-    # 璁剧疆l2鏈�鏂扮殑灏佸崟棰濇暟鎹�
-    @classmethod
-    def __set_l2_latest_money_record(cls, code, index, num):
-        key = "l2_limit_up_money-{}".format(code)
-        cls.__get_redis().setex(key, tool.get_expire(), json.dumps((num, index)))
-
-    # 杩斿洖鏁伴噺,绱㈠紩
-    @classmethod
-    def __get_l2_latest_money_record(cls, code):
-        key = "l2_limit_up_money-{}".format(code)
-        result = cls.__get_redis().get(key)
-        if result:
-            result = json.loads(result)
-            return result[0], result[1]
-        else:
-            return 0, -1
-
-    # 鐭鏁版嵁
-    # 鐭鏂规硶涓哄彇鐭鏃堕棿涓や晶鐨勭鍒嗗竷鏁版嵁锛岀敤浜庣‘瀹氳绠楃粨鏉熷潗鏍�
-    @classmethod
-    def verify_num(cls, code, num, time_str):
-        time_ = time_str.replace(":", "")
-        key = None
-        for i in range(4, -2, -2):
-            # 鑾峰彇鏈�(鍒嗛挓/灏忔椂/澶�)鍐呯鍒嗗竷鏁版嵁
-            time_regex = "{}*".format(time_[:i])
-            keys_ = cls.__get_l2_second_money_record_keys(code, time_regex)
-            if keys_ and len(keys_) > 1:
-                # 闇�瑕佹帓搴�
-                keys = []
-                for k in keys_:
-                    keys.append(k)
-                keys.sort(key=lambda tup: int(tup.split("-")[-1]))
-                # 鏈�2涓厓绱�
-                for index in range(0, len(keys) - 1):
-                    time_1 = keys[index].split("-")[-1]
-                    time_2 = keys[index + 1].split("-")[-1]
-                    if int(time_1) <= int(time_) <= int(time_2):
-                        # 鍦ㄦ鏃堕棿鑼冨洿鍐�
-                        if time_ == time_2:
-                            key = keys[index + 1]
-                        else:
-                            key = keys[index]
-                        break
-            if key:
-                val = cls.__get_redis().get(key)
-                old_num, old_from, old_to = cls.__format_second_money_record_val(val)
-                end_index = old_to
-                # 淇濆瓨鏈�杩戠殑鏁版嵁
-                cls.__set_l2_latest_money_record(code, end_index, num)
-                break
-
-    # 璁$畻閲忥紝鐢ㄤ簬娑ㄥ仠灏佸崟閲忕殑璁$畻
-    @classmethod
-    def __compute_num(cls, code, data, buy_single_data):
-        if L2DataUtil.is_limit_up_price_buy_cancel(data["val"]) or L2DataUtil.is_sell(data["val"]):
-            # 娑ㄥ仠涔版挙涓庡崠
-            return 0 - int(data["val"]["num"]) * data["re"]
-        else:
-            # 鍗栨挙
-            if L2DataUtil.is_sell_cancel(data["val"]):
-                # 鍗栨挙鐨勪拱鏁版嵁鏄惁鍦ㄤ拱鍏ヤ俊鍙蜂箣鍓嶏紝濡傛灉鍦ㄤ箣鍓嶅氨涓嶈绠楋紝涓嶅湪涔嬪墠灏辫绠�
-                if l2_data_util.is_sell_index_before_target(data, buy_single_data,
-                                                            local_today_num_operate_map.get(code)):
-                    return 0
-
-            return int(data["val"]["num"]) * data["re"]
-
-    @classmethod
-    def clear(cls, code):
-        key = "l2_limit_up_money-{}".format(code)
-        cls.__get_redis().delete(key)
-
-    # 杩斿洖鍙栨秷鐨勬爣蹇楁暟鎹�
-    # with_cancel 鏄惁闇�瑕佸垽鏂槸鍚︽挙閿�
-    @classmethod
-    def process_data(cls, code, start_index, end_index, buy_single_begin_index, with_cancel=True):
-        start_time = round(t.time() * 1000)
-        total_datas = local_today_datas[code]
-        time_dict_num = {}
-        # 璁板綍璁$畻鐨勫潗鏍�
-        time_dict_num_index = {}
-        num_dict = {}
-        # 缁熻鏃堕棿鍒嗗竷
-        time_dict = {}
-        for i in range(start_index, end_index + 1):
-            data = total_datas[i]
-            val = data["val"]
-            time_ = val["time"]
-            if time_ not in time_dict:
-                time_dict[time_] = i
-
-        for i in range(start_index, end_index + 1):
-            data = total_datas[i]
-            val = data["val"]
-            time_ = val["time"]
-            if time_ not in time_dict_num:
-                time_dict_num[time_] = 0
-                time_dict_num_index[time_] = {"s": i, "e": i}
-            time_dict_num_index[time_]["e"] = i
-            num = cls.__compute_num(code, data, total_datas[buy_single_begin_index])
-            num_dict[i] = num
-            time_dict_num[time_] = time_dict_num[time_] + num
-        for t_ in time_dict_num:
-            cls.__set_l2_second_money_record(code, t_, time_dict_num[t_], time_dict_num_index[t_]["s"],
-                                             time_dict_num_index[t_]["e"])
-
-        print("淇濆瓨娑ㄥ仠灏佸崟棰濇椂闂达細", round(t.time() * 1000) - start_time)
-
-        # 绱鏈�鏂扮殑閲戦
-        total_num, index = cls.__get_l2_latest_money_record(code)
-        if index == -1:
-            # 娌℃湁鑾峰彇鍒版渶鏂扮殑鐭灏佸崟棰濓紝闇�瑕佷粠涔板叆淇″彿寮�濮嬬偣璁$畻
-            index = buy_single_begin_index - 1
-            total_num = 0
-        # TODO 寰呬紭鍖栬绠�
-        cancel_index = None
-        cancel_msg = None
-        # 寰呰绠楅噺
-        limit_up_price = gpcode_manager.get_limit_up_price(code)
-        min_volumn = round(10000000 / (limit_up_price * 100))
-        # 涓嶅悓鏃堕棿鐨勬暟鎹紑濮嬪潗鏍�
-        time_start_index_dict = {}
-        # 鏁版嵁鏃堕棿鍒嗗竷
-        time_list = []
-        # 鍒板綋鍓嶆椂闂寸疮绉殑涔�1閲�
-        time_total_num_dict = {}
-        for i in range(index + 1, end_index + 1):
-            data = total_datas[i]
-            time_ = data["val"]["time"]
-            if time_ not in time_start_index_dict:
-                # 璁板綍姣忎竴绉掔殑寮�濮嬩綅缃�
-                time_start_index_dict[time_] = i
-                # 璁板綍鏃堕棿鍒嗗竷
-                time_list.append(time_)
-                # 涓婁竴娈垫椂闂寸殑鎬绘暟
-                time_total_num_dict[time_] = total_num
-
-            val = num_dict.get(i)
-            if val is None:
-                val = cls.__compute_num(code, data, total_datas[buy_single_begin_index])
-            total_num += val
-            # 濡傛灉鏄噺灏忛」锛屼笖鍦ㄥ鐞嗘暟鎹殑鑼冨洿鍐咃紝灏遍渶瑕佸垽鏂槸鍚﹁鎾ゅ崟浜�
-            if val < 0 and start_index <= i <= end_index:
-                # 绱灏佸崟閲戦灏忎簬1000涓�
-                if total_num < min_volumn:
-                    cancel_index = i
-                    cancel_msg = "灏佸崟閲戦灏忎簬1000涓�"
-                    break
-                # 鐩搁偦2s鍐呯殑鏁版嵁鍑忓皬50%
-                # 涓�1s鐨勬�绘暟
-                last_second_total_volumn = time_total_num_dict.get(time_list[-1])
-                if last_second_total_volumn > 0 and (
-                        last_second_total_volumn - total_num) / last_second_total_volumn >= 0.5:
-                    # 鐩搁偦2s鍐呯殑鏁版嵁鍑忓皬50%
-                    cancel_index = i
-                    cancel_msg = "鐩搁偦2s({})鍐呯殑灏佸崟閲忓噺灏�50%({}->{})".format(time_, last_second_total_volumn,
-                                                                     total_num)
-                    break
-        if not with_cancel:
-            cancel_index = None
-
-        print("灏佸崟棰濊绠楁椂闂达細", round(t.time() * 1000) - start_time)
-        process_end_index = end_index
-        if cancel_index:
-            process_end_index = cancel_index
-        # 淇濆瓨鏈�鏂扮疮璁¢噾棰�
-        # cls.__set_l2_latest_money_record(code, process_end_index, total_num)
-        l2_data_log.l2_time(code, round(t.time() * 1000) - start_time, "l2鏁版嵁灏佸崟棰濊绠楁椂闂�",
-                            False)
-        if cancel_index:
-            return total_datas[cancel_index], cancel_msg
-        return None, None
 
 
 def __get_time_second(time_str):

--
Gitblit v1.8.0