Administrator
3 天以前 8821049f3faee04e03f5535c6259d07bfb8b6433
订阅规则修改/增加新的外部接口/删除不必要的debug日志
5个文件已修改
195 ■■■■■ 已修改文件
api/outside_api_command_callback.py 167 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cancel_strategy/s_l_h_cancel_strategy.py 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/current_price_process_manager.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/outside_api_command_callback.py
@@ -1034,6 +1034,167 @@
                result = {"code": 0, "data": {"account_available_money": account_available_money, "delegates": fdatas}}
                self.send_response(result, client_id, request_id)
            elif ctype == "get_delegated_buy_code_infos_v2":
                account_available_money = trade_data_manager.AccountMoneyManager().get_available_money_cache()
                # 获取委托中的代码
                current_delegates = huaxin_trade_record_manager.DelegateRecordManager().list_current_delegates()
                fdatas = []
                if current_delegates:
                    codes_set = set()
                    for c in current_delegates:
                        _start_time = time.time()
                        try:
                            if int(c["direction"]) != huaxin_util.TORA_TSTP_D_Buy:
                                continue
                            code = c["securityID"]
                            if code in codes_set:
                                continue
                            orderSysID = c.get("orderSysID")
                            codes_set.add(code)
                            code_name = gpcode_manager.get_code_name(code)
                            # 获取下单位置信息
                            order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code)
                            if order_begin_pos is None or order_begin_pos.buy_single_index is None:
                                order_begin_pos = OrderBeginPosInfo(buy_single_index=0, buy_exec_index=0)
                            l2_data_util.load_l2_data(code)
                            total_datas = l2_data_util.local_today_datas.get(code)
                            if not total_datas:
                                continue
                            trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
                            if trade_index is None:
                                trade_index = 0
                            # 下单位置
                            place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code)
                            if place_order_index is None:
                                place_order_index = 0
                            # 获取剩下的笔数
                            total_left_count = 0
                            total_left_num = 0
                            for i in range(trade_index + 1, place_order_index):
                                data = total_datas[i]
                                val = data["val"]
                                if not L2DataUtil.is_limit_up_price_buy(val):
                                    continue
                                if val["num"] * float(val["price"]) < 5000:
                                    continue
                                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                                    code,
                                    i,
                                    total_datas,
                                    l2_data_util.local_today_canceled_buyno_map.get(
                                        code))
                                if left_count > 0:
                                    total_left_count += left_count
                                    total_left_num += val["num"] * left_count
                            # 获取正在成交
                            dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code)
                            if dealing_info:
                                if str(total_datas[trade_index]["val"]["orderNo"]) == str(dealing_info[0]):
                                    total_left_num += (total_datas[trade_index]["val"]["num"] - dealing_info[1] // 100)
                            limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
                            buy1_money = Buy1PriceManager().get_latest_buy1_money(code)
                            if buy1_money is None:
                                buy1_money = 1
                            real_place_order_after_count = 0
                            real_place_order_after_num = 0
                            is_ge_code = tool.is_ge_code(code)
                            # 统计真实下单位置后面未撤的金额
                            for i in range(place_order_index, total_datas[-1]["index"]):
                                val = total_datas[i]["val"]
                                if not L2DataUtil.is_limit_up_price_buy(val):
                                    continue
                                # 是不是大单
                                if not l2_data_util_old.is_big_money(val, is_ge_code):
                                    continue
                                canceled_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(
                                    code,
                                    i,
                                    total_datas,
                                    l2_data_util.local_today_canceled_buyno_map.get(
                                        code))
                                if not canceled_data:
                                    real_place_order_after_count += 1
                                    real_place_order_after_num += val["num"]
                            # 是否需要注意
                            need_pay_attention = (total_left_count <= 10 or total_left_num * float(
                                limit_up_price) * 100 < 1500 * 10000) and (
                                                         real_place_order_after_count <= 10 or real_place_order_after_num * limit_up_price * 100 < 1500 * 10000)
                            # L撤比例
                            l_down_cancel_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code,
                                                                                                                buy_mode=OrderBeginPosInfo.MODE_RADICAL)
                            fdata = {"id": orderSysID, "code_info": (code, code_name),
                                     "buy1_money": output_util.money_desc(buy1_money),
                                     "left_count": total_left_count,
                                     "left_money": output_util.money_desc(total_left_num * float(limit_up_price) * 100),
                                     "pay_attention": need_pay_attention,
                                     "trade_progress_percent": round(
                                         total_left_num * float(limit_up_price) * 100 * 100 / buy1_money, 2),  # 成交进度比例
                                     "limit_up_price": limit_up_price,
                                     "block": '',
                                     "trade_queue": [],
                                     "l_down_cancel_rate": l_down_cancel_rate,
                                     "l_down_cancel_rate_info": cancel_rate_info,
                                     }
                            limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code)
                            # 获取当前板块
                            try:
                                limit_up_sequences = CodeLimitUpSequenceManager.get_current_limit_up_sequence(code)
                                if limit_up_sequences:
                                    buy_blocks = RadicalBuyDealCodesManager().get_code_blocks(code)
                                    blocks_info = []
                                    for limit_up_sequence in limit_up_sequences:
                                        # 获取代码下单的板块
                                        if buy_blocks and limit_up_sequence[0] not in buy_blocks:
                                            continue
                                        blocks_info.append(
                                            f"{limit_up_sequence[0]}-{limit_up_sequence[1]}({limit_up_sequence[2]}&{limit_up_sequence[2] - limit_up_sequence[3]})")
                                    if buy_blocks:
                                        fdata['block'] = "/".join(blocks_info)
                            except:
                                pass
                            # 获取涨停时间
                            if limit_up_data:
                                fdata['limit_up_time'] = tool.to_time_str(limit_up_data[2])
                                # 获取委托队列
                            try:
                                real_place_order_index = SCancelBigNumComputer().get_real_place_order_index_cache(code)
                                if real_place_order_index is not None:
                                    trade_queue = l2_output_util.get_trade_queue_at_near_place_order(code,
                                                                                                     real_place_order_index,
                                                                                                     9)
                                    fdata['trade_queue'] = trade_queue
                                # 自由流通股本
                                zyltgb = global_util.zyltgb_map.get(code)
                                if zyltgb is not None:
                                    fdata['zyltgb'] = output_util.money_desc(zyltgb)
                            except:
                                pass
                            # L后囊括快照
                            try:
                                __start_time = time.time()
                                current_info = LCancelBigNumComputer().statistic_l_down_watch_indexes_info(code)
                                fdata['l_down_watch_indexes_info'] = {}
                                if current_info:
                                    fdata['l_down_watch_indexes_info']['current'] = current_info
                                use_time = time.time() - __start_time
                                if use_time > 0.05:
                                    async_log_util.info(logger_debug, f"统计实撤用时:{code} - {use_time}")
                            except Exception as e:
                                logger_debug.exception(e)
                            fdatas.append(fdata)
                        except Exception as e:
                            logger_debug.exception(e)
                        finally:
                            use_time = time.time() - _start_time
                            if use_time > 0.1:
                                async_log_util.info(logger_debug, f"委托信息统计耗时:{c['securityID']}-{use_time}")
                result = {"code": 0, "data": {"account_available_money": account_available_money, "delegates": fdatas}}
                self.send_response(result, client_id, request_id)
            elif ctype == "set_real_place_order_index":
                # 设置真实下单位置
                code = data["code"]
@@ -1398,10 +1559,10 @@
                old_rate = LCancelRateManager().get_cancel_rate(0)[0]
                CancelRateHumanSettingManager().set_l_down(code, rate)
                # L后重新囊括
                if rate < old_rate:
                # if rate < old_rate:
                    # 改小才能重新囊括
                    trade_record_log_util.add_common_msg(code, "L后重新囊括", msg=f"修改撤单比例: {old_rate}->{rate}")
                    LCancelBigNumComputer().re_compute_l_down_watch_indexes(code, is_force=True)
                trade_record_log_util.add_common_msg(code, "L后重新囊括", msg=f"修改撤单比例: {old_rate}->{rate}")
                LCancelBigNumComputer().re_compute_l_down_watch_indexes(code, is_force=True)
                self.send_response({"code": 0, "data": {}},
                                   client_id,
cancel_strategy/s_l_h_cancel_strategy.py
@@ -703,6 +703,7 @@
        self.l_down = {}
    def set_l_down(self, code, rate):
        async_log_util.info(logger_l2_l_cancel, f"人为修改L后撤单比例:{code}-{rate}")
        self.l_down[code] = rate
    def get_l_down(self, code):
@@ -1559,7 +1560,11 @@
            l2_log.l_cancel_debug(code, "将L2后后半段备用大单加入计算出错:{}", str(e))
        # 计算监听的总条数
        total_num = 0
        # 超大单的手数
        super_big_num_thresold = int(2e7/gpcode_manager.get_limit_up_price_as_num(code)/100)
        max_num, max_num_count = 0, 0
        thresh_hold_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code)
        for wi in watch_indexes:
            if str(wi) in after_place_order_index_dict:
@@ -1573,8 +1578,11 @@
                    total_num += total_data[wi]["val"]["num"] * (
                            10 - after_place_order_index_by_dict[str(wi)]) // 10
                continue
            total_num += total_data[wi]["val"]["num"] * total_data[wi]["re"]
            # 超过超大单就算超大单
            if total_data[wi]["val"]["num"] < super_big_num_thresold:
                total_num += total_data[wi]["val"]["num"]
            else:
                total_num += super_big_num_thresold
            if total_data[wi]["val"]["num"] > max_num:
                max_num = total_data[wi]["val"]["num"]
                max_num_count = 1
@@ -1666,7 +1674,7 @@
        total_num = 0
        max_num, max_num_count = 0, 0
        thresh_hold_rate, must_buy, cancel_rate_info = LCancelRateManager.get_cancel_rate(code)
        super_big_num_thresold = int(2e7 / gpcode_manager.get_limit_up_price_as_num(code) / 100)
        for wi in watch_indexes:
            if str(wi) in after_place_order_index_dict:
                # 如果加红就需要计算分母
@@ -1679,8 +1687,10 @@
                    total_num += total_data[wi]["val"]["num"] * (
                            10 - after_place_order_index_by_dict[str(wi)]) // 10
                continue
            total_num += total_data[wi]["val"]["num"] * total_data[wi]["re"]
            if total_data[wi]["val"]["num"] < super_big_num_thresold:
                total_num += total_data[wi]["val"]["num"]
            else:
                total_num += super_big_num_thresold
            if total_data[wi]["val"]["num"] > max_num:
                max_num = total_data[wi]["val"]["num"]
                max_num_count = 1
third_data/code_plate_key_manager.py
@@ -407,7 +407,7 @@
                    # async_log_util.info(logger_debug, f"板块平均涨幅 {b}-{average_rate}")
                self.__kpl_forbidden_plates_cache = forbidden_blocks
                async_log_util.info(logger_debug, f"拉黑板块:{forbidden_blocks}")
                # async_log_util.info(logger_debug, f"拉黑板块:{forbidden_blocks}")
        except Exception as e:
            logger_debug.exception(e)
trade/buy_radical/radical_buy_data_manager.py
@@ -2202,7 +2202,7 @@
    response_data = json.loads(r_str)
    if response_data["code"] == 0:
        datas = response_data["data"]
        async_log_util.info(logger_debug, f"拉取订阅之前的数据:{code_}-{datas}")
        # async_log_util.info(logger_debug, f"拉取订阅之前的数据:{code_}-{datas}")
        if datas:
            # [(金额,价格,订单号)]
            buy_datas = datas["buy"]
trade/current_price_process_manager.py
@@ -176,8 +176,8 @@
                    # 创业板的涨幅需要打折
                    rate = rate / 2
                if order_index >= 0:
                    if order_index < 1000 and rate >= 5:
                        # 涨幅大于3%的才能订阅
                    if order_index < 1000 and rate >= 7:
                        # 涨幅大于7%的才能订阅
                        _code_list.append((rate, code, order_index))
                    else:
                        _delete_list.append((rate, code, 0))