pipsocketDOCS
API reference / Orders

Check an order

POST/v1/accounts/{account}/orders/check

MT5's OrderCheck: whether the order would pass, and the margin it would take. Nothing is sent to the trade server. Takes the same body as Place an order.

Path

accountstringrequired

The account's id, acc_ and 26 characters, as the dashboard shows it.

Body

Left out: MT5's empty values
symbolstringrequired
MT5 · symbol

The symbol exactly as the broker names it, such as EURUSD.

typeenumrequired
MT5 · type

What to send. buy and sell fill now; the others wait at price. close_by is refused here: use Close by.

buysellbuy_limitsell_limitbuy_stopsell_stopbuy_stop_limitsell_stop_limitclose_by
volumenumberrequired
MT5 · volume

Lots. MT5 rejects a volume outside the symbol's minimum, maximum and step.

type_fillingenumrequired
MT5 · type_filling

How the order may fill. Required: each symbol allows its own modes (its filling_modes).

fokiocreturnboc
pricenumberoptional
MT5 · price

Required for pending orders: the price the order waits for. For a market order it is sent as given (0 if left out): brokers with instant or request execution need it, those with market or exchange execution ignore it.

stoplimitnumberoptional
MT5 · stoplimit

Required for buy_stop_limit and sell_stop_limit: the price of the limit order placed once price is reached.

slnumberoptional
MT5 · sl

Stop loss price, set in the same request. 0 or left out: none.

tpnumberoptional
MT5 · tp

Take profit price, set in the same request. 0 or left out: none.

deviationintegeroptional
MT5 · deviation

The largest difference from price MT5 accepts, in points, for instant or request execution.

type_timeenumoptional
MT5 · type_time

How long a pending order lasts. gtc if left out.

gtcdayspecifiedspecified_day
expirationintegeroptional
MT5 · expiration

When a pending order expires: broker server time, seconds since 1970. Required for type_time specified and specified_day.

magicintegeroptional
MT5 · magic

Your own number for the order, kept by MT5 on the order, its deals and its position.

commentstringoptional
MT5 · comment

Up to 31 characters, kept by MT5 on the order. Brokers may replace it.

Response

sentobject

MT5's MqlTradeRequest, field for field, exactly as recorded to send to the terminal: the request's state and result say whether it reached MT5. Fields the call does not use carry MT5's empty values (0, "", fok, gtc).

Fields of sent
actionenum
MT5 · action

What the request does.

dealpendingsltpmodifyremoveclose_by
symbolstring
MT5 · symbol

The symbol, exactly as the broker names it.

typeenum
MT5 · type

The order type.

buysellbuy_limitsell_limitbuy_stopsell_stopbuy_stop_limitsell_stop_limitclose_by
volumenumber
MT5 · volume

Lots.

pricenumber
MT5 · price

The price: a pending order's, or the one instant and request execution trade at.

stoplimitnumber
MT5 · stoplimit

A stop-limit order's limit price, placed once price is reached.

slnumber
MT5 · sl

Stop loss price; 0 for none.

tpnumber
MT5 · tp

Take profit price; 0 for none.

deviationinteger
MT5 · deviation

The largest difference from price MT5 accepts, in points.

type_fillingenum
MT5 · type_filling

How the order may fill.

fokiocreturnboc
type_timeenum
MT5 · type_time

How long a pending order lasts.

gtcdayspecifiedspecified_day
expirationinteger
MT5 · expiration

Broker server time, seconds since 1970, as MT5 takes it.

orderinteger
MT5 · order

The pending order the request is about (modify, remove).

positioninteger
MT5 · position

The position the request is about (close, stops, close by).

position_byinteger
MT5 · position_by

The opposite position, for close by.

magicinteger
MT5 · magic

Your own number, kept by MT5 on the order, its deals and its position.

commentstring
MT5 · comment

Up to 31 characters, kept by MT5 on the order.

resultobject

MT5's MqlTradeCheckResult.

Fields of result
passedboolean

Whether OrderCheck passed the request.

retcodeinteger
MT5 · retcode

MT5's return code: 0 when the check passed.

retcode_nameenum

The return code's name; UNKNOWN for a code MT5 doesn't document.

OKTRADE_RETCODE_REQUOTETRADE_RETCODE_REJECTTRADE_RETCODE_CANCELTRADE_RETCODE_PLACEDTRADE_RETCODE_DONETRADE_RETCODE_DONE_PARTIALTRADE_RETCODE_ERRORTRADE_RETCODE_TIMEOUTTRADE_RETCODE_INVALIDTRADE_RETCODE_INVALID_VOLUMETRADE_RETCODE_INVALID_PRICETRADE_RETCODE_INVALID_STOPSTRADE_RETCODE_TRADE_DISABLEDTRADE_RETCODE_MARKET_CLOSEDTRADE_RETCODE_NO_MONEYTRADE_RETCODE_PRICE_CHANGEDTRADE_RETCODE_PRICE_OFFTRADE_RETCODE_INVALID_EXPIRATIONTRADE_RETCODE_ORDER_CHANGEDTRADE_RETCODE_TOO_MANY_REQUESTSTRADE_RETCODE_NO_CHANGESTRADE_RETCODE_SERVER_DISABLES_ATTRADE_RETCODE_CLIENT_DISABLES_ATTRADE_RETCODE_LOCKEDTRADE_RETCODE_FROZENTRADE_RETCODE_INVALID_FILLTRADE_RETCODE_CONNECTIONTRADE_RETCODE_ONLY_REALTRADE_RETCODE_LIMIT_ORDERSTRADE_RETCODE_LIMIT_VOLUMETRADE_RETCODE_INVALID_ORDERTRADE_RETCODE_POSITION_CLOSEDTRADE_RETCODE_INVALID_CLOSE_VOLUMETRADE_RETCODE_CLOSE_ORDER_EXISTTRADE_RETCODE_LIMIT_POSITIONSTRADE_RETCODE_REJECT_CANCELTRADE_RETCODE_LONG_ONLYTRADE_RETCODE_SHORT_ONLYTRADE_RETCODE_CLOSE_ONLYTRADE_RETCODE_FIFO_CLOSETRADE_RETCODE_HEDGE_PROHIBITEDUNKNOWN
commentstring
MT5 · comment
balancenumber
MT5 · balance

The balance after the trade.

equitynumber
MT5 · equity

The equity after the trade.

profitnumber
MT5 · profit

The floating profit after the trade.

marginnumber
MT5 · margin

The margin the trade takes.

margin_freenumber
MT5 · margin_free

The free margin after the trade.

margin_levelnumber
MT5 · margin_level

The margin level after the trade, in percent.

messagestring

The return code's meaning, in a sentence.

Errors

401invalid_api_key

The key is not a workspace's current key (a rolled key stops working within about a minute).

401missing_api_key

No API key: send it as Authorization: Bearer <key>.

404no_such_account

No such account, or one the key's workspace doesn't have: the two look the same.

422invalid_request

A field, query parameter or header is missing, malformed or not allowed, or the body is not JSON. Nothing was sent.

503account_not_connected

The account's terminal is not connected to the engine (stopped, starting, or restarting). Nothing was sent, except by the kill switch: engaging it still engages it, and may already have deleted pending orders.

503bad_command

The terminal refused the command, for example a negative expiration, or a history range MT5 can't select.

503bridge_outdated

The account's terminal runs an older bridge that can't trade: restart the account to update it. Nothing was sent.

503engine_busy

The account's engine host has too many calls in flight (256). Nothing was done; try again.

503engine_unavailable

The account's engine host is not connected to Pipsocket, or disconnected while the call waited. A trade it already had is still settled: look it up.

504engine_timeout

The account's engine did not answer within 30 seconds.

504terminal_timeout

The account's terminal did not answer within 5 seconds.