MT5 error 10012: Request canceled by timeout (TRADE_RETCODE_TIMEOUT)

The request ran out of time before a final answer came back. It may still have executed; check the account before sending again.

10012TRADE_RETCODE_TIMEOUT
Check firstSafe to retry?
MaybeCould it have executed?

What it means

You see this code in the retcode of a trade result, from OrderSend() in MQL5 or order_send() in Python.

10012 means the request was given up on because no answer arrived in time. The time limit expired on the terminal side, not necessarily on the broker's.

A timeout doesn't prove the broker did nothing. The request may have reached the server and been filled after the terminal stopped waiting.

Common causes

  • A slow or overloaded trade server.
  • A poor network path between the terminal and the broker.
  • A request sent during a reconnect.

How to fix it

  • Check positions, orders and deals for your request before doing anything else.
  • Check the terminal's connection and ping to the server.
  • If timeouts are frequent, move the terminal closer to the broker's servers.

Example in Python:

import MetaTrader5 as mt5
from datetime import datetime, timedelta

TAG = "job-4711"          # your own id for this order, also sent as the comment
MAGIC = 4711

def find_my_order(symbol):
    """Look for the effect of an order whose answer was unclear."""
    for p in mt5.positions_get(symbol=symbol) or ():
        if p.magic == MAGIC and p.comment == TAG:
            return "position", p.ticket
    for o in mt5.orders_get(symbol=symbol) or ():
        if o.magic == MAGIC and o.comment == TAG:
            return "pending order", o.ticket
    # Server time is not UTC, so search a wide window.
    now = datetime.now()
    deals = mt5.history_deals_get(now - timedelta(days=1), now + timedelta(days=1)) or ()
    for d in deals:
        if d.magic == MAGIC and d.comment == TAG:
            return "deal", d.ticket
    return None, None

r = mt5.order_send(request)
if r is not None and r.retcode == mt5.TRADE_RETCODE_TIMEOUT:
    kind, ticket = find_my_order(request["symbol"])
    print("found" if kind else "nothing found yet", kind, ticket)

Is it safe to retry?

Only after you have confirmed that the first request left no trace.

Could the order have executed?

Maybe. Timeouts are one of the classic ways to end up with a duplicate position.

How Tickwire handles it

Tickwire treats 10012 like a lost connection. It doesn't resend; it looks for the result and reports applied, rejected or unknown. See idempotency.

MT4 error 128 (trade timeout) gets the same care.

Related MT5 Python functions

All MetaTrader error codes

One API for MT4 and MT5

Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.