Administrator
2023-08-18 8a8cefbd8c7218a5c9ef8894e31ec496375a0483
bug修改
3个文件已修改
30 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_source_util.py 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_manager.py 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -471,14 +471,13 @@
        # 守护30s以外的数据
        if time_space <= constant.S_CANCEL_EXPIRE_TIME:
            return False, None
        l2_log.cancel_debug(code, "H级是否需要撤单,数据范围:{}-{} ", start_index, end_index)
        # 获取成交进度
        origin_progress_index, latest_progress_index = self.__get_traded_progress_cache(code)
        if latest_progress_index is None:
            latest_progress_index = -1
        # 监听的数据
        watch_indexs_dict = {}
        if start_index >= 1956:
            print("进入测试")
        # 初始化为1防止分母为0
        total_nums = 1
        if origin_progress_index is not None:
@@ -504,7 +503,7 @@
        processed_index, cancel_num = self.__get_compute_data_cache(code)
        l2_log.cancel_debug(code, "H级是否需要撤单,数据范围:{}-{} ", start_index, end_index)
        # 获取下单次数
        cancel_rate_threshold = self.__hCancelParamsManager.get_cancel_rate(volume_index)
        process_index = start_index
@@ -533,8 +532,10 @@
                val = data["val"]
                if L2DataUtil.is_limit_up_price_buy_cancel(val):
                    # 查询买入位置
                    l2_log.cancel_debug(code,"查询买入位置开始:{}",i)
                    buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, data,
                                                                                                     local_today_num_operate_map)
                    l2_log.cancel_debug(code, "查询买入位置结束:{}",i)
                    if buy_index is not None and buy_index in watch_indexs_dict:
                        has_watch_canceled = True
                        cancel_num += data["re"] * val["num"]
l2/l2_data_source_util.py
@@ -125,13 +125,14 @@
    def get_buy_index_with_cancel_data(cls, code, cancel_data, local_today_num_operate_map):
        key = "{}-{}-{}".format(cancel_data["val"]["num"], "1", cancel_data["val"]["price"])
        cancel_datas = local_today_num_operate_map.get(key)
        try:
            cancel_datas.sort(key=lambda t: t["index"])
        except Exception as e:
            print("测试")
        for item in cancel_datas:
            # 提前做计算
            cls.__get_buy_index_with_cancel_data(code, item, local_today_num_operate_map)
        if cancel_datas:
            try:
                cancel_datas.sort(key=lambda t: t["index"])
            except Exception as e:
                print("测试")
            for item in cancel_datas:
                # 提前做计算
                cls.__get_buy_index_with_cancel_data(code, item, local_today_num_operate_map)
        return cls.__get_buy_index_with_cancel_data(code, cancel_data, local_today_num_operate_map)
trade/trade_manager.py
@@ -384,6 +384,9 @@
        RedisUtils.realse(redis)
__CodesTradeStateManager = CodesTradeStateManager()
# 开始交易
def start_buy(code, capture_timestamp, last_data, last_data_index):
    # @dask.delayed
@@ -394,7 +397,7 @@
    # @dask.delayed
    def is_state_right(code):
        trade_state = CodesTradeStateManager().get_trade_state_cache(code)
        trade_state = __CodesTradeStateManager.get_trade_state_cache(code)
        if trade_state != TRADE_STATE_NOT_TRADE and trade_state != TRADE_STATE_BUY_CANCEL_SUCCESS and trade_state != TRADE_STATE_BUY_CANCEL_ING:
            return Exception("代码处于不可交易状态"), trade_state
        return None, trade_state
@@ -433,7 +436,7 @@
    print("开始买入")
    logger_trade.info("{}开始买入".format(code))
    CodesTradeStateManager().set_trade_state(code, TRADE_STATE_BUY_PLACE_ORDER)
    __CodesTradeStateManager.set_trade_state(code, TRADE_STATE_BUY_PLACE_ORDER)
    # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "买入判断时间", force=True)
    __buy(code, price, trade_state, capture_timestamp, last_data, last_data_index)
    # l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "异步买入时间", force=True)
@@ -471,7 +474,6 @@
def __place_order_success(code, capture_timestamp, last_data, last_data_index):
    # 买入结束点
    use_time = round(time.time() * 1000) - capture_timestamp
    logger_trade.info("{}-从截图到下单成功总费时:{}".format(code, use_time))
    # 下单成功,加入固定代码库
    if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS:
        l2_data_manager.add_to_l2_fixed_codes(code)