VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 57
声望: 1

在组合模块的StrategyEngine类中,有如下发单方法,其中前一个reference=f"{APPNAME}{strategy.strategy_name}",后面又把它改成req.reference = strategy.strategy_name ,这个有啥讲究吗?感觉没必要改啊。

另外,我发现组合下单buy命令,成交的订单reference为空串。不知为什么,不知别人是不是这样?
order {'CTP.1_1760630402_1': OrderData(gateway_name='CTP', symbol='ag2212', exchange=<Exchange.SHFE: 'SHFE'>, orderid='1_1760630402_1', type=<OrderType.LIMIT: '限价'>, direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=4850.0, volume=1, traded=1, status=<Status.ALLTRADED: '全部成交'>, datetime=datetime.datetime(2022, 5, 27, 14, 0, 50, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), reference='')

    def send_order(
        self,
        strategy: StrategyTemplate,
        vt_symbol: str,
        direction: Direction,
        offset: Offset,
        price: float,
        volume: float,
        lock: bool,
        net: bool,
    ):
        """
        Send a new order to server.
        """
        contract: ContractData = self.main_engine.get_contract(vt_symbol)
        if not contract:
            self.write_log(f"委托失败,找不到合约:{vt_symbol}", strategy)
            return ""

        # Round order price and volume to nearest incremental value
        price = round_to(price, contract.pricetick)
        volume = round_to(volume, contract.min_volume)

        # Create request and send order.
        original_req = OrderRequest(
            symbol=contract.symbol,
            exchange=contract.exchange,
            direction=direction,
            offset=offset,
            type=OrderType.LIMIT,
            price=price,
            volume=volume,
            reference=f"{APP_NAME}_{strategy.strategy_name}"
        )

        # Convert with offset converter
        req_list = self.offset_converter.convert_order_request(original_req, lock, net)

        # Send Orders
        vt_orderids = []

        for req in req_list:
            req.reference = strategy.strategy_name      # Add strategy name as order reference

            vt_orderid = self.main_engine.send_order(
                req, contract.gateway_name)

            # Check if sending order successful
            if not vt_orderid:
                continue

            vt_orderids.append(vt_orderid)

            self.offset_converter.update_order_request(req, vt_orderid)

            # Save relationship between orderid and strategy.
            self.orderid_strategy_map[vt_orderid] = strategy

        return vt_orderids
Member
avatar
加入于:
帖子: 5005
声望: 301

加上模块名前缀,更好辨认,因为其他模块也可以策略交易的

Member
avatar
加入于:
帖子: 57
声望: 1

后面又把它改成req.reference = strategy.strategy_name ,去掉了APP_NAME呀。

Member
avatar
加入于:
帖子: 57
声望: 1

另外,我发现组合下单buy命令,成交的订单reference为空串。不知为什么
order {'CTP.1_1760630402_1': OrderData(gateway_name='CTP', symbol='ag2212', exchange=<Exchange.SHFE: 'SHFE'>, orderid='1_1760630402_1', type=<OrderType.LIMIT: '限价'>, direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=4850.0, volume=1, traded=1, status=<Status.ALLTRADED: '全部成交'>, datetime=datetime.datetime(2022, 5, 27, 14, 0, 50, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>), reference='')

Member
avatar
加入于:
帖子: 57
声望: 1

说明一下,我是no ui模式运行的。

Member
avatar
加入于:
帖子: 5005
声望: 301

是的,可以把下面那句代码删掉

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】