2个文件已修改
126 ■■■■ 已修改文件
servers/data_server.py 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/data_server.py
@@ -950,6 +950,29 @@
                                th_sell = 0
                            deal_big_money_info = radical_buy_data_manager.get_total_deal_big_order_info(
                                code, gpcode_manager.get_limit_up_price_as_num(code))
                            if deal_big_money_info[1] == 0 and len(codes) == 1:
                                deal_big_money_info = list(deal_big_money_info)
                                # 没有订阅L2会出现没有值的情况,如果涨停过就拉取之前的涨停买/卖大单
                                deal_big_orders_result = radical_buy_data_manager.request_deal_big_orders(code)
                                if deal_big_orders_result:
                                    buy_datas, sell_datas = deal_big_orders_result[0], deal_big_orders_result[1]
                                    limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
                                    limit_up_price_money_list = [x[0] for x in buy_datas if x[1] == limit_up_price]
                                    threshold_money = BeforeSubDealBigOrderManager().compute_re_limit_up_big_money_threshold(
                                        limit_up_price_money_list)
                                    logger_debug.info(f"{code}-临时回封均大单:{threshold_money}")
                                    # 设置买单阈值
                                    th_buy = threshold_money
                                    buy_money = sum(limit_up_price_money_list)
                                    sell_money = sum([x[0] for x in sell_datas if x[1] == limit_up_price])
                                    # 涨停大单净买入
                                    deal_big_money_info[1] = buy_money - sell_money
                                    deal_big_money_info[
                                        2] = radical_buy_data_manager.compute_total_deal_big_order_threshold_money(code,
                                                                                                                   limit_up_price,
                                                                                                                   threshold_money)
                                    logger_debug.info(f"{code}-累计大单阈值:{deal_big_money_info[2]}")
                            big_money_rate = radical_buy_data_manager.TotalDealBigOrderInfoManager.get_big_order_rate(
                                code)
                            if not big_money_rate:
@@ -971,11 +994,6 @@
                                # 加载涨停大单详情
                                limit_up_big_order_detail = radical_buy_data_manager.get_total_detal_big_order_details(
                                    code)
                                if max(limit_up_big_order_detail) == 0:
                                    # 没有数据,从网络加载
                                    limit_up_big_order_detail = list(limit_up_big_order_detail)
                                    limit_up_big_order_detail[1] = deal_big_order_detail_info[1][0]
                                    limit_up_big_order_detail[3] = deal_big_order_detail_info[2][0]
                                deal_big_order_info.append(
                                    output_util.money_desc(limit_up_big_order_detail[0] + limit_up_big_order_detail[1]))
                                deal_big_order_info.append(
@@ -987,7 +1005,7 @@
                            logger_debug.error(f"可能没有获取到涨停价:{code}")
                            if not gpcode_manager.get_limit_up_price(code):
                                init_data_util.re_set_price_pre(code)
                            # logger_debug.exception(e)
                            logger_debug.exception(e)
                            deal_big_order_info = None
                        code_name = gpcode_manager.get_code_name(code)
                        fresults.append((code, code_name, deal_big_order_info, deal_big_order_detail_info))
trade/buy_radical/radical_buy_data_manager.py
@@ -107,6 +107,19 @@
        redis_manager.RedisUtils.setex_async(self.__db, f"radical_big_sell_order_threshold-{code}", tool.get_expire(),
                                             f"{threshold_money}")
    @classmethod
    def compute_re_limit_up_big_money_threshold(cls, limit_up_price_money_list):
        """
        获取回封的大单阈值
        @param limit_up_price_money_list:
        @return:
        """
        average_money = sum(limit_up_price_money_list) // len(limit_up_price_money_list)
        max_money = max(limit_up_price_money_list)
        # 取max((平均值+最大单一半)/2, 平均值)
        threshold_money = max((max_money // 2 + average_money) // 2, average_money)
        return threshold_money
    def set_big_deal_order_list(self, code, buy_money_list, sell_money_list, limit_up_price):
        """
        设置大单成交数据
@@ -146,11 +159,7 @@
            total_deal_buy_money += info[0]
            total_deal_buy_money_info_list.append(info)
        if limit_up_price_money_list:
            # 计算大单的阈值
            average_money = sum(limit_up_price_money_list) // len(limit_up_price_money_list)
            max_money = max(limit_up_price_money_list)
            # 取max((平均值+最大单一半)/2, 平均值)
            threshold_money = max((max_money // 2 + average_money) // 2, average_money)
            threshold_money = self.compute_re_limit_up_big_money_threshold(limit_up_price_money_list)
            self.set_big_order_threshold(code, threshold_money)
        self.__already_total_deal_big_order_money[code] = (total_deal_buy_money, pre_limit_up_price_money_list)
        async_log_util.info(logger_l2_radical_buy_data,
@@ -1761,6 +1770,24 @@
    return buy_money, before_buy_money, sell_money, before_sell_money
def compute_total_deal_big_order_threshold_money(code, limit_up_price, threshold_money_per_order):
    """
    计算累计大单足够的阈值
    @param code:
    @param limit_up_price:
    @param threshold_money_per_order: 均大单阈值
    @return:
    """
    TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT = round(
        code_volumn_manager.CodeVolumeManager().get_radical_buy_refer_volume(code,
                                                                             limit_up_price) * limit_up_price / 1e8,
        2) * 3
    if tool.is_ge_code(code):
        TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT *= 1.5
    return TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT * threshold_money_per_order
def get_total_deal_big_order_info(code, limit_up_price, is_for_buy=False):
    """
    总成交大单啊是否足够
@@ -1769,15 +1796,9 @@
    """
    THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info(code)
    TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT = round(
        code_volumn_manager.CodeVolumeManager().get_radical_buy_refer_volume(code,
                                                                             limit_up_price) * limit_up_price / 1e8,
        2) * 3
    if tool.is_ge_code(code):
        TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT *= 3.3
    TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY_WITH_COMPUTE = TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT * THRESHOLD_MONEY
    TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY_WITH_COMPUTE = compute_total_deal_big_order_threshold_money(code,
                                                                                                     limit_up_price,
                                                                                                     THRESHOLD_MONEY)
    human_setting_money = TotalDealBigOrderThresholdMoneyManager().get_money_cache(code)
    if human_setting_money is not None:
@@ -2131,6 +2152,28 @@
        return round(0 - 0.44 * fvolume_rate + 0.722, 3)
def request_deal_big_orders(code_):
    """
    请求大单成交
    @param code_:
    @return:
    """
    response_data = requests.get(
        "http://127.0.0.1:9005/get_big_order_list?code=" + code_)
    r_str = response_data.text
    response_data = json.loads(r_str)
    if response_data["code"] == 0:
        datas = response_data["data"]
        async_log_util.info(logger_debug, f"拉取订阅之前的数据:{code_}-{datas}")
        if datas:
            # [(金额,价格,订单号)]
            buy_datas = datas["buy"]
            # [(金额,价格,订单号)]
            sell_datas = datas["sell"]
            return buy_datas, sell_datas
    return None
def pull_pre_deal_big_orders(code_):
    """
    拉取订阅之前成交的大单
@@ -2140,21 +2183,15 @@
    # 只有涨停过的代码才需要拉大单
    if code_ not in LimitUpDataConstant.get_history_limit_up_codes():
        return
    response_data = requests.get(
        "http://127.0.0.1:9005/get_big_order_list?code=" + code_)
    r_str = response_data.text
    response_data = json.loads(r_str)
    if response_data["code"] == 0:
        datas = response_data["data"]
        async_log_util.info(logger_debug, f"拉取订阅之前的数据:{code_}-{datas}")
        if datas:
            try:
                buy_datas = datas["buy"]
                sell_datas = datas["sell"]
                BeforeSubDealBigOrderManager().set_big_deal_order_list(code_, buy_datas, sell_datas,
                                                                       gpcode_manager.get_limit_up_price_as_num(code_))
            except Exception as e:
                logger_debug.exception(e)
    result = request_deal_big_orders(code_)
    if result:
        try:
            buy_datas, sell_datas = result[0], result[1]
            BeforeSubDealBigOrderManager().set_big_deal_order_list(code_, buy_datas, sell_datas,
                                                                   gpcode_manager.get_limit_up_price_as_num(code_))
        except Exception as e:
            logger_debug.exception(e)
def pull_pre_deal_big_orders_by_codes(codes):
@@ -2180,6 +2217,7 @@
        return datas
    return None
def list_l2_big_order_deal_info(codes):
    """
    获取成交大单信息