Orders and reliability

Market Orders vs Pending Orders in an MT5 API

A market order trades now; a pending order waits at the broker for your price. How each behaves in an MT5 API, with one example and a comparison table.

The fxapis team2 min read

In short

  • A market order executes now, at the price available. Its result is a fill — or a rejection.
  • A pending order waits at the broker until the price reaches a level you set. Its result is a working order, not a position.
  • A limit waits for a better price; a stop waits for the price to break through. Buy limits sit below the market, buy stops above it.
  • Placing a pending order and having it fill are separate events. Treat working and filled as different states in your code.
On this page
  1. One scenario
  2. Side by side
  3. The three pending kinds
  4. In the API
  5. Working is not filled
  6. Which to use
  7. Next steps

Every trade in MetaTrader 5 starts as one of two kinds of order. A market order says "now". A pending order says "when the price gets here". They return different results, and code that treats them the same eventually tells someone they are in a trade they are not.

One scenario

EUR/USD is trading at 1.1000. You want to buy.

  • Buy now. Send a market order. It fills at about 1.1000 — the price available when it reaches the broker.
  • Buy if it dips to 1.0950. Send a pending buy limit at 1.0950. It waits at the broker and fills only if the price falls there.
  • Buy if it breaks above 1.1050. Send a pending buy stop at 1.1050. It waits and fills only if the price rises there.

Side by side

AspectMarket orderPending order
When it executesImmediatelyWhen the price reaches your level
The priceThe market's, nowYour level (a stop can slip past it in a fast market)
Result of placing itfilled — a position existsworking — no position yet
Can be cancelledNo — close the position insteadYes, until it triggers
Where it waitsNowhere; it executesAt the broker's trade server
fxapis endpointPOST /v1/accounts/{id}/orders/marketPOST /v1/accounts/{id}/orders/pending

The three pending kinds

KindA buy waitsA sell waitsUse it to
limitBelow the marketAbove the marketGet a better price
stopAbove the marketBelow the marketTrade a breakout
stop_limitA stop triggers, then places a limitThe sameTrade a breakout with a price cap

The side is the usual mistake: a buy limit above the market is not a limit. fxapis refuses the wrong side before anything is sent, with a message naming the order you probably meant.

In the API

A market order needs no price:

cURL
curl -X POST https://api.fxapis.com/v1/accounts/$ACCOUNT_ID/orders/market \
  -H "Authorization: Bearer $FXAPIS_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "symbol": "EURUSD", "side": "buy", "volume": "0.10" }'

A pending order names its kind and its price:

cURL
curl -X POST https://api.fxapis.com/v1/accounts/$ACCOUNT_ID/orders/pending \
  -H "Authorization: Bearer $FXAPIS_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "symbol": "EURUSD", "side": "buy", "kind": "limit", "volume": "0.10", "price": "1.0950" }'

Both take a stop loss and take profit as absolute prices, and both should carry an idempotency key.

Working is not filled

A placed pending order comes back working. That means it is waiting at the broker — no position exists. Some brokers answer a pending placement with the same return code as a fill; fxapis reads it as working, not filled, so your code does not report a trade that has not happened.

When it triggers, a position appears in GET /v1/accounts/{id}/positions. To call it off first, POST /v1/orders/{id}/cancel. If it has already triggered, the cancel is refused — there is a position now, and what you want is a close.

Which to use

  • Signals and copy trading usually want market orders: the point is to act on the signal now, on every account.
  • Entries at a level — a pullback, a breakout — want pending orders, which wait at the broker even while your own systems are offline.

Pending orders are included on fxapis's Starter, Scale and Enterprise plans; Free has market orders only. See pricing.

Next steps

FAQ

Questions people also ask

What is the difference between a market order and a pending order in MT5?

A market order is executed immediately at the current price. A pending order is an instruction stored at the broker to buy or sell when the price reaches a level you choose; until then no position exists.

Does a pending order need my terminal to be running?

No. Pending orders are held by the broker's trade server and trigger there, whether or not a terminal is connected.

What is a buy stop limit?

An order that waits for the price to rise to a stop level, then places a buy limit at a second price. It is used to enter a breakout without paying any price after the break.

Which fxapis plans include pending orders?

Starter, Scale and Enterprise. The Free plan includes market orders only.

All articles
> Connect. Execute. Scale.

Trade MT5 from your own code.

Connect accounts by login, password and server, and place orders over HTTPS. We run MetaTrader 5; you install nothing.