1002 / MQL5 / USDⓈ-M FUTURES
How can MQL5 place multiple Binance USDⓈ-M futures orders?
Call ufPlaceMultipleOrders with a JSON array of orders through the MT5 Binance MQL API. On its first tick, this Classic-account EA submits an ETHUSDT GTC limit BUY and a BNBUSDT GTC limit SELL. It prints the synchronous response, then calls ufCancelAllOpenOrders for each symbol.
Cancellation covers all open orders for each symbol, not just this EA’s two orders. This includes manual orders and orders placed by other EAs on ETHUSDT and BNBUSDT. The code cancels immediately after submission without waiting for fills. Cancellation does not close positions already filled.
What do you need to run this EA?
- Install and configure MT5 Binance and start the market data and trading services. See the installation guide and API key setup.
- Use a Binance Classic account with the appropriate USDⓈ-M futures API trading permissions. Make
mt5binance.mqhandJAson.mqhavailable to MQL5. - Both ETHUSDT and BNBUSDT must have valid last prices,
SYMBOL_VOLUME_STEPandSYMBOL_DIGITSin MT5. The symbols are hard-coded and do not depend on the chart hosting the EA. - The account, margin, prices and quantities must satisfy current exchange requirements.
How are submission and cancellation executed?
- Initialize and query position mode:
OnInit()initializes credentials, curl handles and the response buffer, then callsufGetCurrentPositionMode. On a query error, the existing code prints the response but still returnsINIT_SUCCEEDED, leaving the mode flag at its defaultfalse. - Calculate both orders: On the first
OnTick(), read each symbol’s last price and normalize quantities calculated as100 / last. Set the ETH BUY price to 80% of its last price and the BNB SELL price to 120% of its last price. - Build the JSON array: Both orders use
LIMITandGTC. OmitpositionSidein One-way Mode; specifyLONGfor ETH andSHORTfor BNB in Hedge Mode. - Submit the batch: Call
ufPlaceMultipleOrders(handles, orders, recvWindow, resultChar), convert the synchronous response to UTF-8 text and print it. This example does not parse individual order results or branch on them. - Cancel all open orders immediately: Call
ufCancelAllOpenOrdersfor ETHUSDT, then BNBUSDT, and print each response. There is no wait for fills and no client-order-ID restriction on cancellation. - Mark the sequence as completed: Set
isRun=true. Later ticks during the same attachment do not repeat or retry the sequence automatically. Reloading the EA may run it again. - Handle events and clean up:
OnChartEvent()extracts and deserializes JSON forid==3333without further event-field processing.OnDeinit()releases curl handles.
What are the default parameters?
| Parameter | Default value | Purpose in this example |
|---|---|---|
| Symbols and sides | ETHUSDT / BUYBNBUSDT / SELL | One batch request contains two orders. |
orderSizeUsdt | 100 | A reference amount for calculating quantity at the last price, not margin or a guarantee of the submitted limit-order notional. |
| ETH / BNB limit prices | 0.8 × last1.2 × last | Ignoring rounding, the submitted notionals are approximately 80 / 120 USDT, not exactly 100 USDT each. |
type / timeInForce | LIMIT / GTC | Limit orders followed by explicit cancellation calls. |
positionSide | Omitted / LONG, SHORT | Omitted in One-way Mode; LONG and SHORT respectively in Hedge Mode. |
recvWindow | 3000 | A request timing window of 3,000 milliseconds. |
| Client order ID prefixes | ea1002Eth / ea1002Bnb | Combined with GetTickCount() to distinguish orders; not a uniqueness guarantee across processes or restarts. |
| Quantity precision branches | Derived from volume step | For steps of at least 1, the existing code uses 0 decimal places for ETH and 1 for BNB. This documents the current source without changing its algorithm. |
| Cancellation scope | All open orders on both symbols | Includes manual orders and orders from other EAs; does not close filled positions. |