Administrator
2024-03-26 df0247018a218abde8701d59ad9e290b37a3031d
G撤修改/新增大卖单撤
4个文件已修改
63 ■■■■ 已修改文件
constant.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 52 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_manager.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_processor.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
constant.py
@@ -157,7 +157,7 @@
########华鑫配置########
if not is_windows() or True:
    # 下单1手
    BUY_MONEY_PER_CODE = 500 if constant.IS_A else 20000
    BUY_MONEY_PER_CODE = 500 # 500 if constant.IS_A else 20000
    L2_SOURCE_TYPE = L2_SOURCE_TYPE_HUAXIN
    JUEJIN_LOCAL_API = False
    TRADE_WAY = TRADE_WAY_HUAXIN
l2/cancel_buy_strategy.py
@@ -51,6 +51,8 @@
    __s_cancel_real_place_order_index_cache = {}
    __s_down_watch_indexes_dict = {}
    __recompute_l_down_time_dict = {}
    # 最近处理的卖单号
    __latest_process_sell_order_no = {}
    __instance = None
@@ -231,6 +233,12 @@
            # 保存卖单信息
            self.__s_down_watch_indexes_dict[code] = (latest_deal_time, watch_indexes)
    # 是否有大卖单需要撤
    def __need_cancel_for_big_sell_order(self, code, big_sell_order_info):
        total_deal_money = sum([x[1] * x[2] for x in big_sell_order_info[1]])
        if total_deal_money >= 299 * 10000:
            return True, f"近1s有大卖单({round(total_deal_money / 10000, 1)}万/299万)"
    #  big_sell_order_info格式:[总共的卖单金额, 大卖单详情列表]
    def set_big_sell_order_info_for_cancel(self, code, big_sell_order_info, order_begin_pos: OrderBeginPosInfo):
        if order_begin_pos is None or order_begin_pos.buy_exec_index is None or order_begin_pos.buy_exec_index < 0:
@@ -238,17 +246,25 @@
        if big_sell_order_info[0] < 500000 or not big_sell_order_info[1]:
            return False, "无大单卖"
        try:
            need_cancel, cancel_msg = self.__need_cancel_for_big_sell_order(code, big_sell_order_info)
            if need_cancel:
                return need_cancel, cancel_msg
        total_datas = local_today_datas.get(code)
        need_cancel, cancel_msg = self.__need_cancel_for_up(code, big_sell_order_info, total_datas)
        if need_cancel:
            return need_cancel, cancel_msg
        # 获取最新的成交时间
        latest_trade_time = l2_huaxin_util.convert_time(big_sell_order_info[1][-1][4][0])
        if tool.trade_time_sub(latest_trade_time, total_datas[order_begin_pos.buy_single_index]['val']['time']) >= 180:
            self.__compute_down_cancel_watch_index(code, big_sell_order_info, total_datas)
        return False, "不满足撤单条件"
            total_datas = local_today_datas.get(code)
            need_cancel, cancel_msg = self.__need_cancel_for_up(code, big_sell_order_info, total_datas)
            if need_cancel:
                return need_cancel, cancel_msg
            if self.__latest_process_sell_order_no.get(code) != big_sell_order_info[1][-1][0]:
                # 不处理重复的卖单
                # 获取最新的成交时间
                latest_trade_time = l2_huaxin_util.convert_time(big_sell_order_info[1][-1][4][0])
                if tool.trade_time_sub(latest_trade_time,
                                       total_datas[order_begin_pos.buy_single_index]['val']['time']) >= 180:
                    self.__compute_down_cancel_watch_index(code, big_sell_order_info, total_datas)
            return False, "不满足撤单条件"
        finally:
            self.__latest_process_sell_order_no[code] = big_sell_order_info[1][-1][0]
    def need_cancel_for_down(self, code, start_index, end_index):
        watch_index_info = self.__s_down_watch_indexes_dict.get(code)
@@ -1700,6 +1716,8 @@
    __watch_indexes_dict = {}
    __watch_indexes_by_dict = {}
    __expire_time_dict = {}
    # 最新处理的卖单
    __latest_process_sell_order_no_dict = {}
    __instance = None
@@ -1743,6 +1761,11 @@
        if tool.trade_time_sub(total_datas[-1]['val']['time'],
                               total_datas[real_place_order_info[0]]['val']['time']) <= 15:
            return
        # 不重复处理同一卖单号
        if self.__latest_process_sell_order_no_dict.get(code) == big_sell_order_info[1][-1][0]:
            return
        # 查找真实成交位置
        real_order_index = real_place_order_info[0]
        start_order_no = big_sell_order_info[1][-1][4][1]
@@ -1759,6 +1782,7 @@
        l2_log.g_cancel_debug(code, f"大单卖触发重新囊括,真实成交位置:{real_trade_index},卖信息:{big_sell_order_info}")
        self.__commpute_watch_indexes(code, real_trade_index, real_place_order_info, recompute=True)
        self.__reset_expire_time(code, total_datas[real_trade_index]['val']['time'])
        self.__latest_process_sell_order_no_dict[code] = big_sell_order_info[1][-1][0]
    def clear(self, code=None):
        if code:
@@ -1852,6 +1876,14 @@
                    val = data["val"]
                    if not L2DataUtil.is_limit_up_price_buy(val):
                        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:
                        continue
                    if val["num"] * float(val["price"]) < 5000:
                        continue
                    temp_list.append((val["num"], data))
l2/l2_transaction_data_manager.py
@@ -98,6 +98,7 @@
    # 最近的卖单, 格式{code:[卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)]}
    __latest_sell_order_dict = {}
    # 返回最近1s的大单卖:(总卖金额,[(卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)),...])
    @classmethod
    def add_transaction_datas(cls, code, datas):
        # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'],
@@ -119,13 +120,13 @@
                    cls.__latest_sell_order_dict[code][2] = d[1]
                    cls.__latest_sell_order_dict[code][4] = (d[3], d[6])
                else:
                    info = cls.__latest_sell_order_dict[code]
                    # 上个卖单成交完成
                    # 封存数据,计算新起点
                    # 大于50w的卖单才会保存
                    if cls.__latest_sell_order_dict[code][1] * cls.__latest_sell_order_dict[code][2] > 50*10000:
                        l2_log.info(code, hx_logger_l2_transaction_sell_order, f"{cls.__latest_sell_order_dict[code]}")
                    # 大于50w加入卖单
                    info = cls.__latest_sell_order_dict[code]
                    if info[1] * info[2] >= 500000:
                        l2_log.info(code, hx_logger_l2_transaction_sell_order, f"{cls.__latest_sell_order_dict[code]}")
                        cls.__big_sell_order_ids_dict[code].add(info[0])
                        cls.__big_sell_order_info_dict[code][info[0]] = info
l2/l2_transaction_data_processor.py
@@ -76,7 +76,7 @@
                                                                                                     order_begin_pos)
                if need_cancel:
                    # async_log_util.error(logger_debug, f"{code} S前撤单:{cancel_msg}")
                    L2TradeDataProcessor.cancel_buy(code, f"S后撤:{cancel_msg}")
                    L2TradeDataProcessor.cancel_buy(code, f"S撤:{cancel_msg}")
                GCancelBigNumComputer().set_big_sell_order_info(code, big_sell_order_info)
            except Exception as e:
                async_log_util.error(logger_debug, f"卖单统计异常:{big_sell_order_info}")