在组合模块的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