Administrator
2024-04-22 30b8187bb288e69750e3280d3e1f4cccc0a01d85
l2/cancel_buy_strategy.py
@@ -19,7 +19,7 @@
from l2.huaxin import l2_huaxin_util
from l2.l2_data_manager import OrderBeginPosInfo
from l2.l2_sell_manager import L2LimitUpSellManager
from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager
from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager, BigOrderDealManager
from log_module import async_log_util
from trade.deal_big_money_manager import DealOrderNoManager
from trade.sell.sell_rule_manager import TradeRuleManager
@@ -860,8 +860,8 @@
                    block_rate = rates[count]
            deal_rate = 0
            # if code in cls.__big_num_deal_rate_dict:
            #     temp_rate = cls.__big_num_deal_rate_dict[code]
            if code in cls.__big_num_deal_rate_dict:
                deal_rate =round( cls.__big_num_deal_rate_dict[code]/100)
            #     if temp_rate >= 1:
            #         if temp_rate > 3:
            #             temp_rate = 3
@@ -890,33 +890,25 @@
            for c in codes:
                cls.__block_limit_up_count_dict[c] = len(codes) - 1
    # 设置大单成交金额➗固定m值比例
    @classmethod
    def set_big_num_deal_rate(cls, code, rate):
    def set_big_num_deal_info(cls, code, buy_money, sell_money):
        left_money_w = (buy_money-sell_money)//10000
        if left_money_w > 0:
            rate = ((left_money_w+300)//900)*2
        else:
            rate = ((left_money_w + 599) // 900) * 2
        if rate <-10:
            rate = -10
        if rate > 10:
            rate = 10
        cls.__big_num_deal_rate_dict[code] = rate
        l2_log.l_cancel_debug(code, f"设置大单成交金额比值:{rate}")
    @classmethod
    def compute_big_num_deal_rate(cls, code):
        total_datas = local_today_datas.get(code)
        order_no_map = local_today_buyno_map.get(code)
        # 获取成交大单手数
        total_deal_nums = DealOrderNoManager().get_deal_nums(code, order_no_map)
        # 获取板上卖手数
        total_sell_nums = 0
        sell_indexs = L2LimitUpSellManager().get_limit_up_sell_indexes(code)
        if sell_indexs:
            for index in sell_indexs:
                total_sell_nums += total_datas[int(index)]["val"]["num"]
        l2_log.l_cancel_debug(code, f"大单买-{total_deal_nums} 板上卖-{total_sell_nums}")
        total_deal_nums -= total_sell_nums
        if total_deal_nums < 0:
            total_deal_nums = 0
        thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
        limit_up_price = gpcode_manager.get_limit_up_price(code)
        if limit_up_price:
            rate = round(total_deal_nums / (thresh_hold_money // (float(limit_up_price) * 100)), 2)
            cls.set_big_num_deal_rate(code, rate)
    def compute_big_num_deal_info(cls, code):
        total_buy_money = BigOrderDealManager().get_total_buy_money(code)
        total_sell_money = BigOrderDealManager().get_total_sell_money(code)
        cls.set_big_num_deal_info(code, total_buy_money, total_sell_money)
# 计算成交位置之后的大单(特定笔数)的撤单比例
@@ -1334,6 +1326,7 @@
        if not self.__is_l_down_can_cancel(code, buy_single_index):
            # L后已经不能守护
            l2_log.l_cancel_debug(code, f"L后已经无法生效:buy_single_index-{buy_single_index}")
            HourCancelBigNumComputer().start_compute_watch_indexes(code, buy_single_index)
        real_place_order_index_info = self.__real_place_order_index_dict.get(code)
@@ -1985,7 +1978,7 @@
                need_find_by = True
                for i in origin_watch_index_by:
                    if i >= start_index:
                        # 在成交位置之后
                        # 只要有一个还没成交就不需要重新计算
                        need_find_by = False
                        break
            if need_find_by and (not is_default or not watch_indexes):
@@ -2018,7 +2011,7 @@
                    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
                    self.__watch_indexes_by_dict[code] = watch_indexes
    def set_trade_progress(self, code, buy_single_index, index):
        if self.__trade_progress_index_dict.get(code) != index:
@@ -2049,6 +2042,7 @@
        if watch_indexes_by is None:
            watch_indexes_by = set()
        need_compute = False
        need_compute_by = False
        for i in range(start_index, end_index + 1):
            data = total_datas[i]
            val = data["val"]
@@ -2062,8 +2056,10 @@
            if buy_index is not None and buy_index < real_place_order_index and (
                    buy_index in watch_indexes or buy_index in watch_indexes_by):
                if buy_index in watch_indexes_by:
                    need_compute_by = True
                    break
                    # 备用撤单,直接撤
                    return True, data, f"次大单撤:{buy_index}"
                    # return True, data, f"次大单撤:{buy_index}"
                elif buy_index in watch_indexes:
                    # 大单撤需要重新计算大单撤单比例
                    need_compute = True
@@ -2086,6 +2082,25 @@
                canceled_indexes_list = list(canceled_indexes)
                canceled_indexes_list.sort()
                return True, total_datas[canceled_indexes_list[-1]], f"撤单比例:{cancel_rate}"
        # 计算备用
        if need_compute_by and watch_indexes_by:
            canceled_indexes = set()
            for index in watch_indexes_by:
                cancel_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code, index,
                                                                                                      total_datas,
                                                                                                      local_today_canceled_buyno_map.get(
                                                                                                          code))
                if cancel_data:
                    canceled_indexes.add(cancel_data["index"])
            cancel_rate = round(len(canceled_indexes) / len(watch_indexes_by), 2)
            threshhold_rate = constant.G_CANCEL_RATE
            situation = trade_manager.MarketSituationManager().get_situation_cache()
            if situation == trade_manager.MarketSituationManager.SITUATION_GOOD:
                threshhold_rate = constant.G_CANCEL_RATE_FOR_GOOD_MARKET
            if cancel_rate > threshhold_rate:
                canceled_indexes_list = list(canceled_indexes)
                canceled_indexes_list.sort()
                return True, total_datas[canceled_indexes_list[-1]], f"次大单撤单比例:{cancel_rate}"
        return False, None, ""