Skip to content

Metatrader trade response#

About#

Сontains trade command result. For a trade request see MetatraderTrade

Fields#

Name Type Required Description
numericCode number Yes numeric result code, see MT5 Trade return сodes and MT4 Trade return сodes
stringCode string Yes machine-readable string result code, see MT5 Trade return сodes and MT4 Trade return сodes
message string Yes human-readable error or result message
orderId string id of the order created or modified by the trade
positionId number id of the position created or modified by the trade

Example#

{
  "numericCode": 10009,
  "stringCode": "TRADE_RETCODE_DONE",
  "message": "Request completed",
  "orderId": 47138322,
  "positionId": 46648037
}

MT5 Error codes description#

Code Constant Description
-1 TRADE_RETCODE_UNKNOWN Unknown trade return code
4753 ERR_TRADE_POSITION_NOT_FOUND Position not found
4754 ERR_TRADE_ORDER_NOT_FOUND Order not found
10004 TRADE_RETCODE_REQUOTE Requote
10006 TRADE_RETCODE_REJECT Request rejected
10007 TRADE_RETCODE_CANCEL Request canceled by trader
10008 TRADE_RETCODE_PLACED Order placed
10009 TRADE_RETCODE_DONE Request completed
10010 TRADE_RETCODE_DONE_PARTIAL Only part of the request was completed
10011 TRADE_RETCODE_ERROR Request processing error
10012 TRADE_RETCODE_TIMEOUT Request canceled by timeout
10013 TRADE_RETCODE_INVALID Invalid request
10014 TRADE_RETCODE_INVALID_VOLUME Invalid volume in the request
10015 TRADE_RETCODE_INVALID_PRICE Invalid price in the request
10016 TRADE_RETCODE_INVALID_STOPS Invalid stops in the request
10017 TRADE_RETCODE_TRADE_DISABLED Trade is disabled
10018 TRADE_RETCODE_MARKET_CLOSED Market is closed
10019 TRADE_RETCODE_NO_MONEY There is not enough money to complete the request
10020 TRADE_RETCODE_PRICE_CHANGED Prices changed
10021 TRADE_RETCODE_PRICE_OFF There are no quotes to process the request
10022 TRADE_RETCODE_INVALID_EXPIRATION Invalid order expiration date in the request
10023 TRADE_RETCODE_ORDER_CHANGED Order state changed
10024 TRADE_RETCODE_TOO_MANY_REQUESTS Too frequent requests
10025 TRADE_RETCODE_NO_CHANGES No changes in request
10026 TRADE_RETCODE_SERVER_DISABLES_AT Autotrading disabled by server
10027 TRADE_RETCODE_CLIENT_DISABLES_AT Autotrading disabled by client terminal
10028 TRADE_RETCODE_LOCKED Request locked for processing
10029 TRADE_RETCODE_FROZEN Order or position frozen
10030 TRADE_RETCODE_INVALID_FILL Invalid order filling type
10031 TRADE_RETCODE_CONNECTION No connection with the trade server
10032 TRADE_RETCODE_ONLY_REAL Operation is allowed only for live accounts
10033 TRADE_RETCODE_LIMIT_ORDERS The number of pending orders has reached the limit
10034 TRADE_RETCODE_LIMIT_VOLUME The volume of orders and positions for the symbol has reached the limit
10035 TRADE_RETCODE_INVALID_ORDER Incorrect or prohibited order type
10036 TRADE_RETCODE_POSITION_CLOSED Position with the specified POSITION_IDENTIFIER has already been closed
10038 TRADE_RETCODE_INVALID_CLOSE_VOLUME A close volume exceeds the current position volume
10039 TRADE_RETCODE_CLOSE_ORDER_EXIST A close order already exists for a specified position. This may happen when working in the hedging system:
  • when attempting to close a position with an opposite one, while close orders for the position already exist
  • when attempting to fully or partially close a position if the total volume of the already present close orders and the newly placed one exceeds the current position volume
10040 TRADE_RETCODE_LIMIT_POSITIONS The number of open positions simultaneously present on an account can be limited by the server settings. After a limit is reached, the server returns the TRADE_RETCODE_LIMIT_POSITIONS error when attempting to place an order. The limitation operates differently depending on the position accounting type:
  • Netting — number of open positions is considered. When a limit is reached, the platform does not let placing new orders whose execution may increase the number of open positions. In fact, the platform allows placing orders only for the symbols that already have open positions. The current pending orders are not considered since their execution may lead to changes in the current positions but it cannot increase their number.
  • Hedging — pending orders are considered together with open positions, since a pending order activation always leads to opening a new position. When a limit is reached, the platform does not allow placing both new market orders for opening positions and pending orders.
10041 TRADE_RETCODE_REJECT_CANCEL The pending order activation request is rejected, the order is canceled
10042 TRADE_RETCODE_LONG_ONLY The request is rejected, because the "Only long positions are allowed" rule is set for the symbol (POSITION_TYPE_BUY)
10043 TRADE_RETCODE_SHORT_ONLY The request is rejected, because the "Only short positions are allowed" rule is set for the symbol (POSITION_TYPE_SELL)
10044 TRADE_RETCODE_CLOSE_ONLY The request is rejected, because the "Only position closing is allowed" rule is set for the symbol
10045 TRADE_RETCODE_FIFO_CLOSE The request is rejected, because "Position closing is allowed only by FIFO rule" flag is set for the trading account (ACCOUNT_FIFO_CLOSE=true)

MT4 Error codes description#

Code Constant Description
-3 ERR_ORDER_NOT_FOUND Order not found
-2 ERR_POSITION_NOT_FOUND Position not found
-1 TRADE_RETCODE_UNKNOWN Unknown trade return code
0 ERR_NO_ERROR No error returned
1 ERR_NO_RESULT No error returned, but the result is unknown
2 ERR_COMMON_ERROR Common error
3 ERR_INVALID_TRADE_PARAMETERS Invalid trade parameters
4 ERR_SERVER_BUSY Trade server is busy
5 ERR_OLD_VERSION Old version of the client terminal
6 ERR_NO_CONNECTION No connection with trade server
7 ERR_NOT_ENOUGH_RIGHTS Not enough rights
8 ERR_TOO_FREQUENT_REQUESTS Too frequent requests
9 ERR_MALFUNCTIONAL_TRADE Malfunctional trade operation
64 ERR_ACCOUNT_DISABLED Account disabled
65 ERR_INVALID_ACCOUNT Invalid account
128 ERR_TRADE_TIMEOUT Trade timeout
129 ERR_INVALID_PRICE Invalid price
130 ERR_INVALID_STOPS Invalid stops
131 ERR_INVALID_TRADE_VOLUME Invalid trade volume
132 ERR_MARKET_CLOSED Market is closed
133 ERR_TRADE_DISABLED Trade is disabled
134 ERR_NOT_ENOUGH_MONEY Not enough money
135 ERR_PRICE_CHANGED Price changed
136 ERR_OFF_QUOTES Off quotes
137 ERR_BROKER_BUSY Broker is busy
138 ERR_REQUOTE Requote
139 ERR_ORDER_LOCKED Order is locked
140 ERR_LONG_POSITIONS_ONLY_ALLOWED Long positions only allowed
141 ERR_TOO_MANY_REQUESTS Too many requests
145 ERR_TRADE_MODIFY_DENIED Modification denied because an order is too close to market
146 ERR_TRADE_CONTEXT_BUSY Trade context is busy
147 ERR_TRADE_EXPIRATION_DENIED Expirations are denied by broker
148 ERR_TRADE_TOO_MANY_ORDERS The amount of opened and pending orders has reached the limit set by a broker
4108 ERR_INVALID_TICKET Invalid ticket

Usages#