Administrator
2024-06-13 53755dd13c6c921d3b3a65b1aed54b563f84d152
L后后半段更新
2个文件已修改
158 ■■■■ 已修改文件
cancel_strategy/s_l_h_cancel_strategy.py 143 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test.py 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cancel_strategy/s_l_h_cancel_strategy.py
@@ -672,8 +672,6 @@
                    CodeDataCacheUtil.set_cache(cls.__cancel_l_down_after_place_order_index_cache, code, val)
                except:
                    pass
        finally:
            RedisUtils.realse(__redis)
@@ -916,42 +914,109 @@
                                watch_indexes.add(i)
                                break
                    # 获取真实下单位后面10笔大单
                    try:
                        # 真实下单位置后面的数据就只看大单
                        MIN_NUM = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
                        real_place_order_info = self.__real_place_order_index_dict.get(code)
                        if real_place_order_info and not real_place_order_info[1]:
                            # 从真实下单位往后找
                            after_count = 0
                            for i in range(real_place_order_info[0] + 1, total_datas[-1]['index'] + 1):
                                if after_count > 10:
                                    break
                                data = total_datas[i]
                                val = data['val']
                                # 涨停买,且未撤单
                                if not L2DataUtil.is_limit_up_price_buy(val):
                                    continue
                                # 小金额过滤
                                if val['num'] < MIN_NUM:
                                    continue
                                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                                    code, i,
                                    total_datas,
                                    local_today_canceled_buyno_map.get(
                                        code))
                                if left_count > 0:
                                    after_count += 1
                                    if l2_data_util.is_big_money(val):
                                        watch_indexes.add(i)
                                        self.__set_cancel_l_down_after_place_order_index(code, i, after_count - 1)
                    except Exception as e:
                        pass
                    watch_indexes_after = self.__compute_l_down_watch_index_after_real_place_order_index(code)
                    if watch_indexes_after:
                        watch_indexes |= watch_indexes_after
                    self.__set_watch_indexes(code, buy_single_index, re_compute, watch_indexes)
                    l2_log.l_cancel_debug(code,
                                          f"设置监听范围({msg}){'(重新计算)' if re_compute else ''}, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}")
        except Exception as e:
            l2_log.l_cancel_debug(code, f"计算L后囊括范围出错:{str(e)}")
            async_log_util.exception(logger_l2_l_cancel, e)
    def __need_update_l_down_after(self, code, start_index, end_index):
        """
        是否需要更新l后真实下单位置之后的囊括范围
        @param code:
        @return:
        """
        real_place_order_info = self.__real_place_order_index_dict.get(code)
        if not real_place_order_info or real_place_order_info[1]:
            return False
        # 判断L后是否包含后面的数据
        watch_indexes_info = self.__get_watch_indexes_cache(code)
        if not watch_indexes_info:
            # 没有囊括
            return False
        watch_indexes = set([int(i) for i in watch_indexes_info[2]])
        real_place_order_index = real_place_order_info[0]
        for index in watch_indexes:
            if index > real_place_order_index:
                # L后后段已经囊括
                return False
        # 下单位置之后数10笔卖单
        watch_indexes = set()
        total_datas = local_today_datas.get(code)
        MIN_NUM = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
        MAX_COUNT = 10
        for i in range(real_place_order_index + 1, end_index):
            data = total_datas[i]
            val = data['val']
            if not L2DataUtil.is_limit_up_price_buy(val):
                continue
            if val['num'] < MIN_NUM:
                continue
            watch_indexes.add(i)
            if len(watch_indexes) >= MAX_COUNT:
                break
        # 看里面的撤单率是否
        if len(watch_indexes) < MAX_COUNT:
            # 数量不够
            return False
        # 计算撤单比例是否足够
        canceled_buyno_map = local_today_canceled_buyno_map.get(code)
        cancel_count = 0
        for index in watch_indexes:
            # 是否撤单
            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                code, index,
                total_datas,
                canceled_buyno_map)
            if left_count <= 0:
                cancel_count += 1
        if cancel_count > len(watch_indexes) * 0.5:
            return True
        return False
    def __compute_l_down_watch_index_after_real_place_order_index(self, code):
        """
        计算L后真实下单位置之后的监控索引
        @return:
        """
        watch_indexes = set()
        total_datas = local_today_datas.get(code)
        try:
            # 真实下单位置后面的数据就只看大单
            MIN_NUM = int(5000 / (float(gpcode_manager.get_limit_up_price(code))))
            real_place_order_info = self.__real_place_order_index_dict.get(code)
            if real_place_order_info and not real_place_order_info[1]:
                # 从真实下单位往后找
                after_count = 0
                for i in range(real_place_order_info[0] + 1, total_datas[-1]['index'] + 1):
                    if after_count > 10:
                        break
                    data = total_datas[i]
                    val = data['val']
                    # 涨停买,且未撤单
                    if not L2DataUtil.is_limit_up_price_buy(val):
                        continue
                    # 小金额过滤
                    if val['num'] < MIN_NUM:
                        continue
                    left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                        code, i,
                        total_datas,
                        local_today_canceled_buyno_map.get(
                            code))
                    if left_count > 0:
                        after_count += 1
                        if l2_data_util.is_big_money(val):
                            watch_indexes.add(i)
                            # 记录索引的位置
                            self.__set_cancel_l_down_after_place_order_index(code, i, after_count - 1)
        except Exception as e:
            pass
        return watch_indexes
    # 设置真实下单位置
    def set_real_place_order_index(self, code, index, buy_single_index=None, is_default=False):
@@ -1411,6 +1476,20 @@
            except Exception as e:
                logger_l2_l_cancel.exception(e)
                raise e
        try:
            if self.__need_update_l_down_after(code, start_index, end_index):
                # 更新后半段
                watch_indexes = self.__compute_l_down_watch_index_after_real_place_order_index(code)
                if watch_indexes:
                    watch_indexes_info = self.__get_watch_indexes_cache(code)
                    if watch_indexes_info and watch_indexes_info[2]:
                        # 没有囊括
                        watch_indexes|=set(watch_indexes_info[2])
                        self.__set_watch_indexes(code, watch_indexes_info[0], watch_indexes_info[1], watch_indexes)
        except Exception as e:
            l2_log.l_cancel_debug(code,"L后后半段计算出错:{}", str(e))
        return can_cancel, cancel_data, extra_msg
    def place_order_success(self, code):
test/test.py
@@ -25,14 +25,7 @@
if __name__ == "__main__":
    codes_sh, codes_sz = l1_subscript_codes_manager.get_codes(False)
    codes = set()
    if codes_sh:
        for code_byte in codes_sh:
            codes.add(code_byte.decode())
        for code_byte in codes_sz:
            codes.add(code_byte.decode())
    updated_codes = ZYLTGBUtil.get_today_updated_volume_codes()
    codes = codes - set(updated_codes)
    print(codes)
    s1 = {"0", "1", "2"}
    s2 = {"3", "4", "5"}
    s1 |= s2
    print(s1)