Administrator
2023-08-23 8c0891b4d7d0961402d28ba58c081d940464ff2a
新版S撤
3个文件已修改
75 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_delegate_postion_manager.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -31,6 +31,7 @@
    __redis_manager = redis_manager.RedisManager(0)
    __sCancelParamsManager = l2_trade_factor.SCancelParamsManager
    __s_big_num_cancel_compute_data_cache = {}
    __s_cancel_real_place_order_index_cache = {}
    __instance = None
@@ -54,6 +55,13 @@
                val = RedisUtils.get(__redis, k)
                val = json.loads(val)
                tool.CodeDataCacheUtil.set_cache(cls.__s_big_num_cancel_compute_data_cache, code, val)
            keys = RedisUtils.keys(__redis, "s_cancel_real_place_order_index-*")
            for k in keys:
                code = k.split("-")[-1]
                val = RedisUtils.get(__redis, k)
                val = int(val)
                tool.CodeDataCacheUtil.set_cache(cls.__s_cancel_real_place_order_index_cache, code, val)
        finally:
            RedisUtils.realse(__redis)
@@ -79,18 +87,42 @@
            return cache_result[1]
        return -1, 0, 0
    # 设置真实下单位置
    def __save_real_place_order_index(self, code, index):
        CodeDataCacheUtil.set_cache(self.__s_cancel_real_place_order_index_cache, code, index)
        key = "s_cancel_real_place_order_index-{}".format(code)
        RedisUtils.setex_async(self.__db, key, tool.get_expire(), index)
    def __get_real_place_order_index(self, code):
        key = "s_cancel_real_place_order_index-{}".format(code)
        val = RedisUtils.get(self.__get_redis(), key)
        if val is None:
            return None
        return int(val)
    def __get_real_place_order_index_cache(self, code):
        cache_result = CodeDataCacheUtil.get_cache(self.__s_cancel_real_place_order_index_cache, code)
        if cache_result[0]:
            return cache_result[1]
        return None
    def __clear_data(self, code):
        CodeDataCacheUtil.clear_cache(self.__s_big_num_cancel_compute_data_cache, code)
        ks = ["s_big_num_cancel_compute_data-{}".format(code)]
        CodeDataCacheUtil.clear_cache(self.__s_cancel_real_place_order_index_cache, code)
        ks = ["s_big_num_cancel_compute_data-{}".format(code), "s_cancel_real_place_order_index-{}".format(code)]
        for key in ks:
            RedisUtils.delete_async(self.__db, key)
    # 设置真实下单位置
    def set_real_place_order_index(self, code, index):
        self.__save_real_place_order_index(code, index)
    def clear_data(self):
        ks = ["s_big_num_cancel_compute_data-*"]
        ks = ["s_big_num_cancel_compute_data-*", "s_cancel_real_place_order_index-*"]
        for key in ks:
            keys = RedisUtils.keys(self.__get_redis(), key)
            for k in keys:
                code = k.replace("s_big_num_cancel_compute_data-", "")
                code = k.split("-")[1]
                self.__clear_data(code)
    # 计算净大单
@@ -167,29 +199,18 @@
        # 需要查询买入信号之前的同1s是否有涨停撤的数据
        process_index = process_index_old
        if buy_single_index == start_index:
        if process_index_old == -1:
            # 第1次计算需要计算买入信号-执行位的净值
            left_big_num = self.__compute_left_big_num(code, buy_single_index, buy_single_index, buy_exec_index,
                                                       total_data, volume_rate_index)
            buy_num += left_big_num
            # 设置买入信号-买入执行位的数据不需要处理
            start_index = end_index + 1
            process_index = end_index
            # for i in range(buy_single_index - 1, 0, -1):
            #     data = total_data[i]
            #     val = data["val"]
            #     if val["time"] != total_data[buy_single_index]["val"]["time"]:
            #         break
            #     if L2DataUtil.is_limit_up_price_buy_cancel(val) and int(val["cancelTime"]) == 0:
            #         # 涨停买撤销且撤销的间隔时间为0
            #         # 查询买入信号,如果无法查询到或者是买入位置比买入信号小就不算
            #         buy_index, buy_data = l2_data_util.get_buy_data_with_cancel_data(data,
            #                                                                          local_today_num_operate_map.get(
            #                                                                              code))
            #         if buy_index is not None and a_start_index <= buy_index <= a_end_index:
            #             # 在买入信号之后
            #             cls.__save_cancel_data(code, i)
        range_seconds = self.__sCancelParamsManager.get_buy_time_range(buy_volume_rate_index)
            process_index = buy_exec_index
        # 强制固定为1s
        range_seconds = 1  # self.__sCancelParamsManager.get_buy_time_range(buy_volume_rate_index)
        # 获取真实下单位置
        place_order_index = self.__get_real_place_order_index_cache(code)
        cancel_rate_threshold = self.__sCancelParamsManager.get_cancel_rate(volume_rate_index)
        try:
            for i in range(start_index, end_index + 1):
@@ -203,6 +224,10 @@
                    continue
                if L2DataUtil.is_limit_up_price_buy(val):
                    if place_order_index is not None and place_order_index < data["index"]:
                        # 不能比下单位置后
                        continue
                    # 如果在囊括时间范围内就可以计算买
                    if tool.trade_time_sub(val["time"], buy_exec_time) <= range_seconds:
                        buy_num += data["re"] * int(val["num"])
@@ -212,8 +237,10 @@
                                                                                                     local_today_num_operate_map.get(
                                                                                                         code))
                    if buy_index is not None and buy_single_index <= buy_index:
                        if place_order_index and place_order_index >= buy_index:
                            cancel_num += total_data[buy_index]["re"] * int(total_data[buy_index]["val"]["num"])
                        # 买入时间在囊括范围内
                        if tool.trade_time_sub(tool.trade_time_add_second(buy_exec_time, range_seconds),
                        elif tool.trade_time_sub(tool.trade_time_add_second(buy_exec_time, range_seconds),
                                               total_data[buy_index]["val"]["time"]) >= 0:
                            cancel_num += total_data[buy_index]["re"] * int(total_data[buy_index]["val"]["num"])
                    elif buy_index is None:
l2/huaxin/huaxin_delegate_postion_manager.py
@@ -18,7 +18,6 @@
# 获取下单信息
def get_order_info(code):
    info = _place_order_info_dict.get(code)
    logger_real_place_order_position.info("get_order_info:data-{}", info)
    if info and time.time() - info[3] > 3:
        logger_real_place_order_position.info("get_order_info 间隔3s以上:code-{}", code)
        # 间隔3s以上就无效了
l2/l2_data_manager_new.py
@@ -312,8 +312,9 @@
            # 获取下单位置
            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)
                cls.__DCancelBigNumComputer.set_real_order_index(code, place_order_index)
                cls.__SecondCancelBigNumComputer.set_real_place_order_index(code, place_order_index)
                async_log_util.info(logger_l2_process, "code:{} 获取到下单真实位置:{}", code, place_order_index)
            __start_time = round(t.time() * 1000)
            if len(datas) > 0:
                cls.process_add_datas(code, datas, 0, __start_time)