我正在开发 mt5 (MetaTrader 5) 插件。但我有一个问题。我尝试使用服务器 API 制作 TradeRequest 并将其添加到请求队列,但我在请求队列中找不到任何其他请求。 recode的值为0(表示成功)。我很困惑。为什么不? 另外,IMTOrder和IMTRrequest有什么区别?哪个类用于交易操作?感谢您考虑我的问题。
我有同样的问题,我尝试使用服务器 API 下新订单。 最后我用manager API解决了这个问题。 请使用Manager API的DealerSend。
我正在尝试使用 Python 在 MetaTrader 5 (MT5) 中下订单,但我的订单没有通过。下面是我正在使用的代码。
order = MTRequest(manager)
order.Login = login
order.Symbol = dto.symbol
order.Type = dto.type
order.Digits = symbolConfig.Digits
volume_in_uint64 = int(dto.volume * 10000)
order.VolumeCurrent = volume_in_uint64
order.Volume =volume_in_uint64
# Set prices based on order type
if dto.type in {OrderType.OP_BUY, OrderType.OP_SELL, OrderType.OP_BUY_LIMIT, OrderType.OP_SELL_LIMIT, OrderType.OP_BUY_STOP, OrderType.OP_SELL_STOP}:
order.PriceOrder = dto.price
# if dto.type in {OrderType.OP_BUY, OrderType.OP_SELL, OrderType.OP_BUY_LIMIT, OrderType.OP_SELL_LIMIT, OrderType.OP_BUY_STOP, OrderType.OP_SELL_STOP, OrderType.OP_BUY_STOP_LIMIT, OrderType.OP_SELL_STOP_LIMIT}:
# order.PriceTP = dto.tp
# order.PriceSL = dto.sl
# if dto.type in {OrderType.OP_BUY_STOP_LIMIT, OrderType.OP_SELL_STOP_LIMIT}:
# order.PriceTrigger = dto.price
sink = DealSink2()
if not manager.Req(order,sink):
# adding failed with an error
error = ManagerLastError()
print(error)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Order add failed with error: {error}"
)