Administrator
2024-04-19 ef00e8743f4b30f2f88f10520757878d4dba2e60
S撤完善
6个文件已修改
157 ■■■■■ 已修改文件
constant.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_data_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_transaction_data_processor.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/l2_trade_test.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constant.py
@@ -143,7 +143,7 @@
# G撤单
G_CANCEL_RATE = 0.39
# 行情好时的撤单比例
G_CANCEL_RATE_FOR_GOOD_MARKET = 0.49
G_CANCEL_RATE_FOR_GOOD_MARKET = 0.39
# 华鑫L2的卡位数量
HUAXIN_L2_MAX_CODES_COUNT = 70
huaxin_client/l2_data_manager.py
@@ -50,7 +50,7 @@
    def set_order_fileter_condition(self, code, min_volume, limit_up_price, shadow_price, buy_volume):
        if code not in self.filter_order_condition_dict:
            self.filter_order_condition_dict[code] = [(min_volume, limit_up_price, shadow_price, buy_volume,
                                                       min_volume // 25)]
                                                       min_volume // 50)]
            huaxin_l2_log.info(logger_local_huaxin_l2_subscript,
                               f"({code})常规过滤条件设置:{self.filter_order_condition_dict[code]}")
l2/cancel_buy_strategy.py
@@ -208,6 +208,12 @@
        return False, ""
    def __need_cancel_for_slow_sell(self, code, total_datas):
        """
        S慢撤的目的是判断较大金额卖占整个卖的比例不能太大
        @param code:
        @param total_datas:
        @return:
        """
        if code not in self.__s_slow_sell_watch_indexes_dict:
            return False, "S慢砸没有囊括"
        # 下单3分钟内有效
@@ -292,22 +298,17 @@
            real_order_time_ms = total_datas[real_order_index]["val"]["time"] + ".{0:0>3}".format(
                total_datas[real_order_index]["val"]["tms"])
        max_money = 0
        for x in big_sell_order_info[1]:
            deal_time = l2_huaxin_util.convert_time(x[4][0], with_ms=True)
            if real_order_time_ms:
                if tool.trade_time_sub_with_ms(deal_time, real_order_time_ms) >= 0:
                    m = x[1] * x[2]
                    if max_money < m:
                        max_money = m
                    total_deal_money += m
            else:
                m = x[1] * x[2]
                if max_money < m:
                    max_money = m
                total_deal_money += m
        if max_money >= 4990000:
            return True, f"有大于499w大卖单({max_money})"
        if total_deal_money >= 4990000:
            return True, f"1s内大于499w大卖单({total_deal_money})"
        limit_up_price = gpcode_manager.get_limit_up_price(code)
        # 判断是否为激进下单
@@ -315,7 +316,7 @@
        total_fast_num = 0
        if order_begin_pos.mode == OrderBeginPosInfo.MODE_ACTIVE:
            try:
                # 真实成交位距离真实下单位,10笔以内且金额≤1000万 , 且在180s内
                # 15分钟内真实成交位距离真实下单位,金额≤800万 ,大单阈值变为200w
                trade_index, is_default = TradeBuyQueue().get_traded_index(code)
                if trade_index is None:
                    trade_index = 0
@@ -325,36 +326,31 @@
                    fdeal = big_sell_order_info[1][0][3]
                    start_order_no = fdeal[1]
                    sell_time_str = l2_huaxin_util.convert_time(fdeal[0], with_ms=False)
                    is_s_slow_timw = tool.trade_time_sub(sell_time_str,
                                                         total_datas[real_order_index]["val"]["time"]) < 180
                    total_slow_num = 0
                    total_slow_count = 0
                    # 获取正在成交的数据
                    dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code)
                    for i in range(trade_index, real_order_index):
                        data = total_datas[i]
                        val = data['val']
                        if int(val['orderNo']) < start_order_no:
                            continue
                        if i == trade_index and dealing_info and str(
                                total_datas[trade_index]["val"]["orderNo"]) == str(
                            dealing_info[0]):
                            # 减去当前正在成交的数据中已经成交了的数据
                            if is_s_slow_timw:
                                total_slow_num -= dealing_info[1] // 100
                        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:
                            if is_s_slow_timw:
                                total_slow_num += val["num"]
                                total_slow_count += 1
                            total_fast_num += val['num']
                    if total_slow_num * float(limit_up_price) < 800 * 100:
                        threash_money_w = 200
                    if tool.trade_time_sub(sell_time_str, total_datas[real_order_index]['val']['time']) < 15 * 60:
                        total_num = 0
                        # 获取正在成交的数据
                        dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code)
                        for i in range(trade_index, real_order_index):
                            data = total_datas[i]
                            val = data['val']
                            if int(val['orderNo']) < start_order_no:
                                continue
                            if i == trade_index and dealing_info and str(
                                    total_datas[trade_index]["val"]["orderNo"]) == str(
                                dealing_info[0]):
                                # 减去当前正在成交的数据中已经成交了的数据
                                total_num -= dealing_info[1] // 100
                            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:
                                total_num += val["num"]
                                total_fast_num += val['num']
                        if total_num * float(limit_up_price) < 800 * 100:
                            threash_money_w = 200
            except Exception as e:
                l2_log.s_cancel_debug(code, f"S撤激进下单计算大单卖阈值出错:{str(e)}")
        total_fast_money = int(total_fast_num * 100 * float(limit_up_price))
@@ -365,7 +361,8 @@
        if total_deal_money >= threash_money_w * 10000 and rate >= 0.25:
            return True, f"近1s有大卖单({round(total_deal_money / 10000, 1)}万/{threash_money_w}万,成交占比:{total_deal_money}/{total_fast_money})"
        else:
            l2_log.s_cancel_debug(code, f"S快撤没达到撤单比例:成交金额({total_deal_money})/囊括金额({total_fast_money}),比例:{rate} 大单阈值:{threash_money_w}w")
            l2_log.s_cancel_debug(code,
                                  f"S快撤没达到撤单比例:成交金额({total_deal_money})/囊括金额({total_fast_money}),比例:{rate} 大单阈值:{threash_money_w}w")
        return False, f"无{threash_money_w}大单"
    #  big_sell_order_info格式:[总共的卖单金额, 大卖单详情列表]
@@ -397,45 +394,6 @@
        finally:
            # self.__latest_process_sell_order_no[code] = big_sell_order_info[1][-1][0]
            pass
    def need_cancel_for_down(self, code, start_index, end_index):
        watch_index_info = self.__s_down_watch_indexes_dict.get(code)
        if not watch_index_info:
            return False, "没获取到囊括范围"
        total_datas = local_today_datas.get(code)
        if tool.trade_time_sub(total_datas[-1]["val"]["time"], watch_index_info[0].split(".")[0]) > 9:
            return False, "超过守护时间"
        watch_indexes = watch_index_info[1]
        watch_order_nos = set([total_datas[d]['val']['orderNo'] for d in watch_indexes])
        # 计算是否有撤单
        need_compute = False
        for i in range(start_index, end_index + 1):
            data = total_datas[i]
            val = data['val']
            if not L2DataUtil.is_limit_up_price_buy_cancel(val):
                continue
            if val['orderNo'] in watch_order_nos:
                need_compute = True
                break
        if not need_compute:
            return False, "没有监听范围内的单撤单"
        # 计算撤单比例
        total_num = 0
        cancel_num = 0
        for index in watch_indexes:
            total_num += total_datas[index]["val"]['num']
            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, index,
                                                                                                     total_datas,
                                                                                                     local_today_canceled_buyno_map.get(
                                                                                                         code))
            if left_count <= 0:
                cancel_num += total_datas[index]["val"]['num']
        cancel_rate = round(cancel_num / total_num, 4)
        if cancel_rate >= 0.25:
            return True, f"达到撤单比例:{cancel_rate}  监听范围:{watch_index_info}"
        return False, "没达到撤单比例"
    # ----------------------------S慢砸范围计算------------------------------------
    def __compute_s_slow_sell(self, code):
@@ -1771,7 +1729,7 @@
    def cancel_success(self, code):
        self.clear(code)
    # 下单3分钟内距离下单位置不足3笔且不到300w就需要撤单
    # 下单3分钟内距离下单位置不足3笔(包含正在成交)且不到300w就需要撤单
    def need_cancel_for_deal_fast(self, code, trade_index=None):
        if trade_index is None:
            trade_info = TradeBuyQueue().get_traded_index(code)
@@ -1863,7 +1821,7 @@
            real_trade_index = i
            break
        # 是否是下单5分钟内
        # 是否是下单3分钟内
        if tool.trade_time_sub(total_datas[-1]['val']['time'], total_datas[real_order_index]['val']['time']) > 180:
            return False, "下单超过180s"
@@ -1947,6 +1905,7 @@
        self.__expire_time_dict[code] = tool.trade_time_add_second(now_time, 15)
    # 大有单卖
    # 暂时不启用
    def set_big_sell_order_info(self, code, big_sell_order_info):
        money = big_sell_order_info[0]
        if money < 50 * 10000:
@@ -2098,9 +2057,14 @@
                    if len(temp_list) > 15:
                        break
                temp_list.sort(key=lambda x: x[0], reverse=True)
                # 次大单的笔数1-3笔
                THRESH_COUNT = len(temp_list) // 5
                if THRESH_COUNT < 1:
                    THRESH_COUNT = 1
                if temp_list:
                    l2_log.g_cancel_debug(code, f"小单备用监听位置:{temp_list[0][1]['index']}")
                    watch_indexes.add(temp_list[0][1]["index"])
                    for i in range(THRESH_COUNT):
                        l2_log.g_cancel_debug(code, f"小单备用监听位置:{temp_list[i][1]['index']}")
                        watch_indexes.add(temp_list[i][1]["index"])
                    self.__watch_indexes_by_dict[code] = origin_watch_index_by | watch_indexes
    def set_trade_progress(self, code, buy_single_index, index):
l2/l2_data_manager_new.py
@@ -520,28 +520,6 @@
            return
        cls.__latest_process_order_unique_keys[code] = unique_key
        # S撤
        def s_cancel(_buy_single_index, _buy_exec_index):
            _start_time = round(t.time() * 1000)
            # S撤单计算,看秒级大单撤单
            try:
                b_need_cancel, b_cancel_msg = cls.__SCancelBigNumComputer.need_cancel_for_down(code, start_index,
                                                                                               end_index)
                if b_need_cancel:
                    async_log_util.error(logger_debug, f"{code} S后撤单:{b_cancel_msg}")
                    return total_data[end_index], f"S后撤({b_cancel_msg})"
                    # return None, ""
            except Exception as e:
                logging.exception(e)
                async_log_util.error(logger_l2_error,
                                     f"S撤出错 参数:buy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index}")
                async_log_util.exception(logger_l2_error, e)
            finally:
                # l2_data_log.l2_time(code, round(t.time() * 1000) - _start_time,
                #                     "已下单-s级大单估算")
                pass
            return None, ""
        # H撤
        def h_cancel(_buy_single_index, _buy_exec_index):
            _start_time = round(t.time() * 1000)
l2/l2_transaction_data_processor.py
@@ -67,7 +67,7 @@
                    if need_cancel:
                        L2TradeDataProcessor.cancel_buy(code, cancel_msg)
                    GCancelBigNumComputer().set_big_sell_order_info(code, big_sell_order_info)
                    # GCancelBigNumComputer().set_big_sell_order_info(code, big_sell_order_info)
                    use_time_list.append(("处理卖单相关撤数据", time.time() - _start_time))
                    _start_time = time.time()
            except Exception as e:
test/l2_trade_test.py
@@ -224,7 +224,6 @@
                                                                                          order_begin_pos)
        l2.cancel_buy_strategy.SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, sell_order_info,
                                                                                          order_begin_pos)
        l2.cancel_buy_strategy.SCancelBigNumComputer().need_cancel_for_down(code, 154, 222)
    @unittest.skip("跳过此单元测试")
    def test_h_cancel(self):