Administrator
2023-09-25 b696ad64d69705c03d43406f1d1d2010b16923bb
首次下单机制修改/华鑫撤单撤2次
4个文件已修改
72 ■■■■ 已修改文件
huaxin_client/command_manager.py 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api.py 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/l2_trade_factor.py 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/command_manager.py
@@ -11,7 +11,7 @@
from huaxin_client import socket_util
from huaxin_client.client_network import SendResponseSkManager
from log_module import async_log_util
from log_module.log import logger_local_huaxin_trade_debug, logger_trade
from log_module.log import logger_local_huaxin_trade_debug, logger_trade, logger_local_huaxin_contact_debug
MSG_TYPE_HEART = "heart"
# 命令信息
@@ -82,6 +82,7 @@
    @classmethod
    def process_command(cls, _type, client_id, result_json, sk=None):
        async_log_util.info(logger_local_huaxin_contact_debug, f"process_command: {result_json}")
        # 查看是否是设置L2的代码
        if _type == CLIENT_TYPE_CMD_L2:
            cls.pipe_l2.send(
@@ -117,9 +118,9 @@
            elif _type == "test":
                cls.action_callback.OnTest(client_id, request_id, data, sk)
        except Exception as e:
            logger_local_huaxin_trade_debug.debug(f"process_command出错:{result_json}")
            logging.exception(e)
            logging.error(result_json)
            async_log_util.error(logger_local_huaxin_contact_debug, f"process_command出错: {result_json}")
            # logging.exception(e)
            # logging.error(result_json)
    @classmethod
    def run_process_command(cls, queue_strategy_trade: multiprocessing.Queue):
@@ -132,6 +133,7 @@
                    val = queue_strategy_trade.get()
                    if val:
                        _type = val["type"]
                        async_log_util.info(logger_local_huaxin_contact_debug, f"接受到信息: {_type}")
                        cls.process_command_thread_pool.submit(lambda: cls.process_command(_type, None, val))
                except Exception as e:
                    async_log_util.exception(logger_local_huaxin_trade_debug, e)
l2/l2_data_manager_new.py
@@ -758,14 +758,30 @@
            return False, True, f"股价大于{constant.MAX_CODE_PRICE}块"
        if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN:
            total_data = local_today_datas.get(code)
            trade_price = current_price_process_manager.get_trade_price(code)
            if trade_price is None:
                return False, True, f"尚未获取到当前成交价"
            if float(limit_up_price) - float(trade_price) > 0.00001:
                return False, False, f"当前成交价({trade_price})尚未在0档及以内"
                # 计算信号起始位置到当前的手数
                buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos(code)
                num_operate_map = local_today_num_operate_map.get(code)
                total_num = 0
                for i in range(buy_single_index, total_data[-1]["index"] + 1):
                    data = total_data[i]
                    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(code,
                                                                                                          data["index"],
                                                                                                          total_data,
                                                                                                          num_operate_map)
                    total_num += left_count * val["num"]
                m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
                thresh_hold_num = m_base_val//(float(gpcode_manager.get_limit_up_price(code))*100)
                if total_num < thresh_hold_num * 2:
                    return False, False, f"当前成交价({trade_price})尚未在0档及以内 且 纯买额({total_num})小于2倍M值({thresh_hold_num*2})"
            # 判断成交进度是否距离我们的位置很近
            total_data = local_today_datas.get(code)
            trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
            if False and not is_default and trade_index:
                not_cancel_num = 0
trade/huaxin/huaxin_trade_api.py
@@ -253,16 +253,16 @@
        start_time = time.time()
        queue_strategy_trade.put_nowait(root_data)
        # pipe_trade.send(json.dumps(root_data).encode("utf-8"))
        use_time = int((time.time() - start_time)*1000)
        use_time = int((time.time() - start_time) * 1000)
        if use_time > 10:
            async_log_util.info(hx_logger_trade_loop, f"发送耗时:request_id-{request_id} 耗时时间:{use_time}")
        if log_enable:
            async_log_util.info(hx_logger_trade_loop, "请求发送成功:request_id-{}", request_id)
    except BrokenPipeError as e:
        async_log_util.info(hx_logger_trade_loop,"请求发送异常:request_id-{} error-{}", request_id, str(e))
        async_log_util.info(hx_logger_trade_loop, "请求发送异常:request_id-{} error-{}", request_id, str(e))
        raise e
    except Exception as e:
        async_log_util.info(hx_logger_trade_loop,"请求发送异常: request_id-{} error-{}", request_id, str(e))
        async_log_util.info(hx_logger_trade_loop, "请求发送异常: request_id-{} error-{}", request_id, str(e))
        logging.exception(e)
        raise e
    return request_id
@@ -357,14 +357,18 @@
    if not sinfo:
        sinfo = f"cb_{code}_{round(time.time() * 1000)}_{random.randint(0, 10000)}"
    order_action_ref = huaxin_util.create_order_ref()
    request_id = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
                           {"type": ClientSocketManager.CLIENT_TYPE_TRADE, "trade_type": 2,
                            "direction": direction,
                            "code": code,
                            "orderRef": orderRef,
                            "orderActionRef": order_action_ref,
                            "orderSysID": orderSysID, "sinfo": sinfo}, request_id=request_id, blocking=blocking,
                           is_pipe=is_pipe_channel_normal())
    if not request_id:
        request_id = __get_request_id(ClientSocketManager.CLIENT_TYPE_TRADE)
    # 执行2次撤单,防止没有撤到
    for i in range(2):
        request_id = __request(ClientSocketManager.CLIENT_TYPE_TRADE,
                               {"type": ClientSocketManager.CLIENT_TYPE_TRADE, "trade_type": 2,
                                "direction": direction,
                                "code": code,
                                "orderRef": orderRef,
                                "orderActionRef": order_action_ref,
                                "orderSysID": orderSysID, "sinfo": sinfo}, request_id=request_id, blocking=blocking,
                               is_pipe=is_pipe_channel_normal())
    try:
        return __read_response(request_id, blocking)
    finally:
trade/l2_trade_factor.py
@@ -6,6 +6,7 @@
from code_attribute import big_money_num_manager, limit_up_time_manager, global_data_loader, gpcode_manager
import constant
from trade import trade_manager
from utils import global_util, tool
@@ -114,6 +115,11 @@
        self.now_time = now_time
        self.buy_rank = self.get_buy_rank()
    # 是否是初次下单
    @classmethod
    def is_first_place_order(cls, code):
        return trade_manager.CodesTradeStateManager().get_trade_state_cache(code) == trade_manager.TRADE_STATE_NOT_TRADE
    # 设置分数
    def set_score(self, score):
        score_ranks = [constant.BUY_SCORE_RANK_3, constant.BUY_SCORE_RANK_2, constant.BUY_SCORE_RANK_1,
@@ -146,6 +152,9 @@
        volume_rate_index = self.volume_rate_index
        if self.volume_rate_index >= len(ts):
            volume_rate_index = -1
        # 首次下单必须同1s
        if self.is_first_place_order(self.code):
            return 1
        return ts[volume_rate_index]
    # 获取需要的大单个数
@@ -161,6 +170,9 @@
        volume_rate_index = self.volume_rate_index
        if self.volume_rate_index >= len(counts):
            volume_rate_index = -1
        # 第一次下单必须为2个
        if self.is_first_place_order(self.code):
            return 2
        return counts[volume_rate_index]
    # 获取安全笔数影响比例
@@ -200,6 +212,8 @@
    # 获取m值
    def get_m_val(self):
        base_m = self.get_base_m_val(self.code)
        if self.is_first_place_order(self.code):
            base_m = int(base_m * 1.5)
        rate = self.get_m_val_rate(self.volume_rate_index)
        m = round(base_m * (1 + rate))
        return m, ""