Results and errors¶
Expected failures are values, not exceptions
(ADR 0002). What to do about each
ErrorKind is in the user guide.
Result
module-attribute
¶
Either Ok(value) or Err(error); every trading call returns one.
Ok
dataclass
¶
Err
dataclass
¶
TradeError
dataclass
¶
TradeError(kind: ErrorKind, message: str, retcode: int | None = None, receipt: TradeReceipt | None = None, ticket: int | None = None)
An expected failure: its ErrorKind, a message and the broker's answer if any.
receipt is the broker's raw answer when there was one; ticket names
the position or order when the failure concerns one item of a batch.
ErrorKind
¶
Bases: Enum
Why a call failed. What to do about each kind is in the user guide.
INVALID_ARGUMENT
class-attribute
instance-attribute
¶
An argument MT5 would misread or refuse: checked before sending, or refused by the server.
INVALID_VOLUME
class-attribute
instance-attribute
¶
The volume is outside the symbol's min/max, off its step, or above the position's.
INVALID_PRICE
class-attribute
instance-attribute
¶
The price is invalid, e.g. a limit on the wrong side of the market.
INVALID_STOPS
class-attribute
instance-attribute
¶
A stop-loss or take-profit is zero, negative, not finite or refused by the server.
INVALID_FILLING
class-attribute
instance-attribute
¶
The server refused the filling mode chosen from the symbol's flags (10030).
MARKET_CLOSED
class-attribute
instance-attribute
¶
The market for the symbol is closed.
TRADE_DISABLED
class-attribute
instance-attribute
¶
Trading is not allowed now: on the symbol or account, or in this direction.
ALGO_TRADING_DISABLED
class-attribute
instance-attribute
¶
Algo Trading is off in the terminal (10027) or forbidden by the server (10026).
LIMIT_REACHED
class-attribute
instance-attribute
¶
A broker limit on orders, positions or volume is reached.
PARTIAL_FILL
class-attribute
instance-attribute
¶
Only part of the volume was executed; the rest is still open or unfilled.
OUTCOME_UNKNOWN
class-attribute
instance-attribute
¶
The request may or may not have reached the server: check positions, never auto-retried.
RETRIES_EXHAUSTED
class-attribute
instance-attribute
¶
Requotes, price changes, no quotes or too many requests outlasted the RetryPolicy.
REJECTED
class-attribute
instance-attribute
¶
Any other refusal by the server, unknown retcodes included.
SYMBOL_NOT_FOUND
class-attribute
instance-attribute
¶
The terminal does not know the symbol.
TERMINAL_ERROR
class-attribute
instance-attribute
¶
A terminal call failed before anything reached the trade server.
BROKEN_SYMBOL_DATA
class-attribute
instance-attribute
¶
The terminal's symbol data cannot price an order (point 0, NaN tick size, step 0).
Unlike TERMINAL_ERROR it does not clear on a resend, so it has its own kind: a bot must escalate, not retry.
CONNECTION_FAILED
class-attribute
instance-attribute
¶
The terminal did not start or the login failed.
BatchFailure
dataclass
¶
BatchFailure(succeeded: tuple[TradeReceipt, ...], errors: tuple[TradeError, ...])
Some items of a batch (close all / cancel all) failed; others may have succeeded.