Administrator
2024-04-15 a20fbda0343efeab3f477ba0d5596f4e9b867c66
新版深证下单完善
1个文件已修改
195 ■■■■■ 已修改文件
l2/l2_data_manager_new.py 195 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py
@@ -1239,17 +1239,18 @@
    @classmethod
    def __cancel_buy(cls, code):
        try:
            l2_log.debug(code, "开始执行撤单")
            trade_manager.start_cancel_buy(code)
            l2_log.debug(code, "执行撤单成功")
            return True
        except Exception as e:
            logging.exception(e)
            l2_log.debug(code, "执行撤单异常:{}", str(e))
            return False
        finally:
            pass
        with cls.__buy_lock_dict[code]:
            try:
                l2_log.debug(code, "开始执行撤单")
                trade_manager.start_cancel_buy(code)
                l2_log.debug(code, "执行撤单成功")
                return True
            except Exception as e:
                logging.exception(e)
                l2_log.debug(code, "执行撤单异常:{}", str(e))
                return False
            finally:
                pass
    @classmethod
    def cancel_buy(cls, code, msg=None, source="l2", cancel_index=None):
@@ -1466,7 +1467,8 @@
        # 买入纯买额统计
        new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new, not_buy_msg = None, None, None, None, [], ""
        if order_begin_pos.mode == OrderBeginPosInfo.MODE_ACTIVE:
            threshold_money = order_begin_pos.threshold_money
            # 设置为总卖额
            threshold_money = order_begin_pos.sell_info[0]
            new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_active(
                code,
                start_process_index,
@@ -1572,7 +1574,7 @@
    @classmethod
    def save_order_begin_data(cls, code, info: OrderBeginPosInfo):
        cls.__save_order_begin_data(code,info)
        cls.__save_order_begin_data(code, info)
    # 计算下单起始信号
    # compute_data_count 用于计算的l2数据数量
@@ -1689,83 +1691,101 @@
        start_time_str = total_datas[start_index]["val"]["time"]
        # 获取最近的总卖信息
        refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, start_time_str)
        if refer_sell_data is None and start_time_str != '09:30:00':
            return False, -1, "总卖为空"
        if refer_sell_data is None:
            refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0))
            l2_log.debug(code, f"丢失总卖额,设置默认为0,计算范围:{start_index}-{end_index}")
        # 获取当前是否可激进买
        # 获取板块是否可以激进买
        # 可买的板块, 是否独苗, 消息, 可买的强势板块, 关键词, 激进买的板块
        can_buy_result = CodePlateKeyBuyManager.can_buy(code)
        if (can_buy_result and can_buy_result[0] and can_buy_result[5]) or constant.ALL_ACTIVE_BUY:
            # 有可买板块,有激进买板块
            # 第一步: 计算总卖额
            threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0]
            if code.find("60") == 0:
                threshold_money = 0
            else:
                pass
                # for i in range(start_index - 1, -1, -1):
                #     val = total_datas[i]["val"]
                #     if tool.compare_time(val["time"], refer_sell_data[0]) < 0:
                #         # 将本s的计算上去
                #         break
                #     if L2DataUtil.is_sell(val):
                #         threshold_money += val["num"] * int(float(val["price"]) * 100)
                #     elif L2DataUtil.is_sell_cancel(val):
                #         threshold_money -= val["num"] * int(float(val["price"]) * 100)
                #     elif L2DataUtil.is_buy(val):
                #         # 判断价格(大于卖1) 被买吃掉
                #         if round(float(val["price"]), 2) - sell_1_price >= 0:
                #             threshold_money -= val["num"] * int(float(val["price"]) * 100)
            # 第二步:计算起始信号
            second_930 = 9 * 3600 + 30 * 60 + 0
            total_datas = local_today_datas.get(code)
            if end_index - start_index + 1 < continue_count:
                return False, -1, "信号不连续"
            last_index = None
            count = 0
            start = None
        if code.find("60") == 0:
            if refer_sell_data is None:
                # 设置默认卖信息
                refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0))
            # 上证:只要有一个涨停买的就是信号
            for i in range(start_index, end_index + 1):
                _val = total_datas[i]["val"]
                time_s = L2DataUtil.get_time_as_second(_val["time"])
                # 时间要>=09:30:00
                if time_s < second_930:
                if not L2DataUtil.is_limit_up_price_buy(_val):
                    continue
                if L2DataUtil.is_limit_up_price_buy(_val):
                    # 金额要大于50万
                    if _val["num"] * float(_val["price"]) < 5000:
                        continue
                    if last_index is None or (total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]):
                        if code.find("00") == 0 and threshold_money > 0:
                            # 深证非板上放量需要判断是否有信号
                            single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single(code,
                                                                                                                     tool.to_time_with_ms(
                                                                                                                         _val['time'],
                                                                                                                         _val['tms']))
                            if not single:
                                continue
                        if start is None:
                            start = i
                        last_index = i
                        count += total_datas[i]["re"]
                        if count >= continue_count:
                            return True, start, [refer_sell_data[0], threshold_money]
                    else:
                        # 本条数据作为起点
                        last_index = i
                        count = total_datas[i]["re"]
                        start = i
                elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val):
                    # 剔除卖与卖撤
                    last_index = None
                    count = 0
                    start = None
            return False, -1, "未获取到激进买的起始信号"
                # 时间要>=09:30:00
                if tool.trade_time_sub(_val["time"], "09:30:00") < 0:
                    continue
                # 金额要大于50万
                if _val["num"] * float(_val["price"]) < 5000:
                    continue
                return True, i, [refer_sell_data[0], 0]
        else:
            return False, -1, "不可激进买"
            # 深证
            if refer_sell_data is None and start_time_str != '09:30:00':
                return False, -1, "总卖为空"
            if refer_sell_data is None:
                refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0))
                l2_log.debug(code, f"丢失总卖额,设置默认为0,计算范围:{start_index}-{end_index}")
            # 获取当前是否可激进买
            # 获取板块是否可以激进买
            # 可买的板块, 是否独苗, 消息, 可买的强势板块, 关键词, 激进买的板块
            can_buy_result = CodePlateKeyBuyManager.can_buy(code)
            if (can_buy_result and can_buy_result[0] and can_buy_result[5]) or constant.ALL_ACTIVE_BUY:
                # 有可买板块,有激进买板块
                # 第一步: 计算总卖额
                threshold_money, sell_1_price = refer_sell_data[1], refer_sell_data[3][0]
                if code.find("60") == 0:
                    threshold_money = 0
                else:
                    pass
                    # for i in range(start_index - 1, -1, -1):
                    #     val = total_datas[i]["val"]
                    #     if tool.compare_time(val["time"], refer_sell_data[0]) < 0:
                    #         # 将本s的计算上去
                    #         break
                    #     if L2DataUtil.is_sell(val):
                    #         threshold_money += val["num"] * int(float(val["price"]) * 100)
                    #     elif L2DataUtil.is_sell_cancel(val):
                    #         threshold_money -= val["num"] * int(float(val["price"]) * 100)
                    #     elif L2DataUtil.is_buy(val):
                    #         # 判断价格(大于卖1) 被买吃掉
                    #         if round(float(val["price"]), 2) - sell_1_price >= 0:
                    #             threshold_money -= val["num"] * int(float(val["price"]) * 100)
                # 第二步:计算起始信号
                second_930 = 9 * 3600 + 30 * 60 + 0
                total_datas = local_today_datas.get(code)
                if end_index - start_index + 1 < continue_count:
                    return False, -1, "信号不连续"
                last_index = None
                count = 0
                start = None
                for i in range(start_index, end_index + 1):
                    _val = total_datas[i]["val"]
                    time_s = L2DataUtil.get_time_as_second(_val["time"])
                    # 时间要>=09:30:00
                    if time_s < second_930:
                        continue
                    if L2DataUtil.is_limit_up_price_buy(_val):
                        # 金额要大于50万
                        if _val["num"] * float(_val["price"]) < 5000:
                            continue
                        if last_index is None or (
                                total_datas[last_index]["val"]["time"] == total_datas[i]["val"]["time"]):
                            if code.find("00") == 0 and threshold_money > 0:
                                # 深证非板上放量需要判断是否有信号
                                single = place_order_single_data_manager.L2TradeSingleDataManager.get_valid_trade_single(
                                    code,
                                    tool.to_time_with_ms(
                                        _val['time'],
                                        _val['tms']))
                                if not single:
                                    continue
                            if start is None:
                                start = i
                            last_index = i
                            count += total_datas[i]["re"]
                            if count >= continue_count:
                                return True, start, [refer_sell_data[0], threshold_money]
                        else:
                            # 本条数据作为起点
                            last_index = i
                            count = total_datas[i]["re"]
                            start = i
                    elif not L2DataUtil.is_sell(_val) and not L2DataUtil.is_sell_cancel(_val):
                        # 剔除卖与卖撤
                        last_index = None
                        count = 0
                        start = None
            return False, -1, "未获取到激进买的起始信号"
    @classmethod
    def __get_threshmoney(cls, code):
@@ -2141,7 +2161,8 @@
        if code.find("00") == 0 and threshold_money > 0:
            # 深证非板上放量
            max_space_time_ms = 1 * 1000
            threshold_num = 0
        # 不看纯买额
        threshold_num = 0
        # 不下单的信息
        not_buy_msg = ""