Administrator
2023-11-15 ca781c1651ee7f148ec6caeba51d52f2a6a75d1b
H撤囊括时间修改
1个文件已修改
44 ■■■■ 已修改文件
l2/cancel_buy_strategy.py 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -384,6 +384,8 @@
    # 成交位置
    __transaction_progress_index_dict = {}
    # 成交位置更新时间
    __transaction_progress_index_updatetime_dict = {}
    # 缓存
    __cancel_watch_indexs_cache = {}
@@ -575,8 +577,11 @@
    def set_transaction_index(self, code, buy_single_index, index):
        try:
            if index == self.__transaction_progress_index_dict.get(code):
                if code in self.__transaction_progress_index_updatetime_dict and time.time() - self.__transaction_progress_index_updatetime_dict.get(
                        code) < 3:
                return
            self.__transaction_progress_index_dict[code] = index
            self.__transaction_progress_index_updatetime_dict[code] = time.time()
            if self.__need_compute_watch_indexes(code, index):
                self.__compute_watch_index(code, buy_single_index)
        except Exception as e:
@@ -870,6 +875,14 @@
                code = k.split("-")[-1]
                val = RedisUtils.smembers(__redis, k)
                CodeDataCacheUtil.set_cache(cls.__cancel_watch_index_cache, code, val)
            keys = RedisUtils.keys(__redis, "l_cancel_real_place_order_index-*")
            for k in keys:
                code = k.split("-")[-1]
                val = RedisUtils.get(__redis, k)
                val = int(val)
                CodeDataCacheUtil.set_cache(cls.__real_place_order_index_dict, code, val)
            keys = RedisUtils.keys(__redis, "l_cancel_near_by_index-*")
            for k in keys:
                code = k.split("-")[-1]
@@ -958,6 +971,7 @@
            self.del_watch_index(code)
            if code in self.__real_place_order_index_dict:
                self.__real_place_order_index_dict.pop(code)
                RedisUtils.delete_async(self.__db, f"l_cancel_real_place_order_index-{code}")
        else:
            keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_watch_index-*")
            for k in keys:
@@ -967,6 +981,9 @@
                if code in self.__real_place_order_index_dict:
                    self.__real_place_order_index_dict.pop(code)
                self.del_watch_index(code)
            keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_real_place_order_index-*")
            for k in keys:
                RedisUtils.delete(self.__get_redis(), k)
    # 计算观察索引,倒序计算
    def compute_watch_index(self, code, buy_single_index, start_index, end_index):
@@ -979,7 +996,7 @@
                # thresh_hold_money = int(thresh_hold_money * 2.5)
                min_num = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
                # 统计净涨停买的数量
                not_cancel_indexes = []
                not_cancel_indexes_with_num = []
                re_start_index = start_index
                MAX_COUNT = 5
                for j in range(start_index, end_index):
@@ -997,18 +1014,20 @@
                                                                                                             local_today_canceled_buyno_map.get(
                                                                                                                 code))
                    if left_count > 0:
                        not_cancel_indexes.append(j)
                if not_cancel_indexes:
                    temp_count = len(not_cancel_indexes)
                        not_cancel_indexes_with_num.append((j, val["num"]))
                min_num = 0
                if not_cancel_indexes_with_num:
                    temp_count = len(not_cancel_indexes_with_num)
                    # 取后1/3的数据
                    if temp_count >= 30:
                        temp_index = int(temp_count * 5 / 6)
                        re_start_index = not_cancel_indexes[temp_index]
                        MAX_COUNT = len(not_cancel_indexes[temp_index:])
                    elif temp_count >= 5:
                        re_start_index = not_cancel_indexes[-5]
                        re_start_index = not_cancel_indexes_with_num[temp_index][0]
                        MAX_COUNT = len(not_cancel_indexes_with_num[temp_index:])
                    else:
                        re_start_index = not_cancel_indexes[0]
                        not_cancel_indexes_with_num.sort(key=lambda x: x[1])
                        if temp_count >= 10:
                            # 获取中位数
                            min_num = not_cancel_indexes_with_num[temp_count // 2][1]
                MIN_MONEYS = [300, 200, 100, 50]
                watch_indexes = set()
                for min_money in MIN_MONEYS:
@@ -1021,6 +1040,10 @@
                            # 小金额过滤
                            if float(val['price']) * val['num'] < min_money * 100:
                                continue
                            if val['num'] < min_num:
                                continue
                            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                                code,
                                i,
@@ -1076,7 +1099,8 @@
    def set_real_place_order_index(self, code, index, buy_single_index=None):
        l2_log.l_cancel_debug(code, f"设置真实下单位-{index},buy_single_index-{buy_single_index}")
        self.__real_place_order_index_dict[code] = index
        if buy_single_index:
        RedisUtils.setex_async(self.__db, f"l_cancel_real_place_order_index-{code}", tool.get_expire(), index)
        if buy_single_index is not None:
            self.compute_watch_index(code, buy_single_index, buy_single_index, index)
        if self.__last_trade_progress_dict.get(code):
            self.__compute_trade_progress_near_by_indexes(code, buy_single_index,