Skip to main content
Developers

Orders & positions

How to open, change and close trades, what each answer means, and how to read the account back.

The calls

WhatCall
Place a market or pending orderPOST /accounts/{account}/orders
Change the stop loss or take profit of a positionPATCH /accounts/{account}/positions/{ticket}
Close a position, wholly or partlyPOST /accounts/{account}/positions/{ticket}/close
Change a pending orderPATCH /accounts/{account}/orders/{ticket}
Cancel a pending orderDELETE /accounts/{account}/orders/{ticket}
See where an order request standsGET /accounts/{account}/requests/{request_id}
Account summary, positions, pending ordersGET /accounts/{account}, …/positions, …/orders
Closed trades and balance operationsGET /accounts/{account}/trades, …/transactions
A position's or closed trade's share pictureGET /accounts/{account}/positions/{ticket}/share-image, …/trades/{ticket}/share-image

Every write needs an Idempotency-Key header (see Idempotency), and a key with the trade or trade:propose scope.

Before an order: the instrument, its hours and candles

GET /symbols/{symbol}, in any case (USOil or usoil), says what an order on the instrument must respect and when it trades:

GET /symbols/EURUSD on a Saturday (abridged)
{
  "symbol": "EURUSD", "digits": 5, "contract_size": 100000, "tick_size": 0.00001, "volume_min": "0.01", "volume_step": "0.01",
  "trade_mode": "full", "tick_value": 1, "profit_currency": "USD", "stops_level": 0,
  "trading_hours": {
    "open_now": false,
    "next_open": "2026-11-15T22:05:00.000Z",
    "next_close": "2026-11-16T21:58:00.000Z",
    "sessions": [
      { "open": "2026-11-15T22:05:00.000Z", "close": "2026-11-16T21:58:00.000Z" },
      { "open": "2026-11-16T22:05:00.000Z", "close": "2026-11-17T21:58:00.000Z" }
    ]
  }
}
  • Size: volume is in lots, and a lot is contract_size units of the instrument, which differs by instrument (see Numbers). tick_value is what one tick (tick_size) moves the profit of one lot, in profit_currency.
  • stops_level is the least distance, in points (1 point is 10^-digits), from the price to a stop loss, a take profit or a pending order's price. It is 0 on JAFX's servers today: no minimum. A stop must still be on the correct side of the price the position would close at, or the order answers 422 invalid_stops; leave a margin, since the price moves while your order travels.
  • trading_hours are your account's own server's, in UTC: open_now, next_open, next_close and the sessions of the next 7 days. Currency pairs, for example, close for the weekend and for a few minutes each evening; most crypto trades every day. An order outside them answers 422 market_closed with details.opens_at: nothing was traded, and the order goes again with a new Idempotency-Key once the market opens. Holidays and early closes aren't in the weekly hours, so handle market_closed even when open_now is true. trading_hours is null while your server's hours aren't known.

Candles

GET /candles/{symbol}?timeframe=M5&limit=40 gives the instrument's bars, oldest first: M1, M5, M15, M30, H1, H4, D1 or W1 (default M1), up to 2,000 bars (default 500), optionally between from and to (ISO-8601 or epoch milliseconds). Each bar has time (when it opened, UTC), open, high, low, close, tick_volume and complete. The last bar is still forming (complete: false) and changes until its period ends, so a strategy that acts on closed bars uses only complete ones, as the example bots do. Daily bars follow the broker day (midnight Europe/Athens). For bars as they form, subscribe to candles:EURUSD:M5 on the stream.

How far back. Candles reach back as far as JAFX's price history goes, not only the latest bars: M1, M5, M15 and M30 from about March 2, 2026 (shares from early February 2026), H1 and H4 from about November 2025 (shares from January 2025), D1 and W1 from 2018 (cryptocurrencies from 2020), as the history holds each instrument. A request gives the newest limit bars between from and to; to read further back, ask again with to just before the oldest bar you got, until a page comes back empty:

GET /candles/EURUSD?timeframe=M1&limit=2000&to=2026-03-10T00:00:00Z
GET /candles/EURUSD?timeframe=M1&limit=2000&to=<the first bar's time minus 1 ms>
…until "data": []

A bar is only ever its timeframe's own: where the history is coarser there are no bars, so an empty page means no history that far back. Pages never repeat a bar and have no gap the market didn't have. A from or to that is neither an ISO-8601 time nor epoch milliseconds answers 422 invalid_request. MCP's get_candles takes from and to the same way, up to 500 bars a call. The read limit (20 requests a second) leaves room to page back a year of one-minute bars in under a minute.

Placing an order

FieldRequiredMeaning
symbolyesInstrument, for example EURUSD.
sideyesbuy or sell.
volumeyesLots, as a decimal string: "0.10".
typenomarket (default), limit or stop.
pricelimit, stopTrigger price of a pending order.
stop_loss, take_profitnoPrices. On the correct side of the price the position would close at (the bid for a buy, the ask for a sell), at least the instrument's stops_level points away.
expires_atnoPending orders only: a future time (ISO-8601 or epoch ms) after which the order is removed.
commentnoUp to 200 characters, stored with the trade.
client_tagnoYour label for the trade (see Tags).

A limit order buys below or sells above the current price; a stop order buys above or sells below it. Pending orders come back typed as buy_limit, sell_limit, buy_stop or sell_stop.

curl
curl -X POST https://terminal.jafx.com/trading-api/v1/accounts/$ACCOUNT/orders \
  -H "Authorization: Bearer $JAFX_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"symbol":"EURUSD","side":"buy","type":"market","volume":"0.02","stop_loss":1.1100,"client_tag":"breakout-v2"}'

A buy limit order with a stop, a target and an expiry:

JSON
{"symbol":"EURUSD","side":"buy","type":"limit","volume":"0.10","price":1.1080,
 "stop_loss":1.1040,"take_profit":1.1180,"expires_at":"2026-10-20T00:00:00Z","client_tag":"breakout-v2"}

What each answer means

HTTPstatusMeaningWhat to do
201filledMarket order executed. ticket and position describe the new position.Done.
201placedPending order placed. order describes it.Done.
200filled / placedA close executed, or a change or cancel was applied.Done.
202pendingThe broker is still deciding, for example while covering the trade with a liquidity provider.Watch request.decided on the orders stream, or poll the request. Do not resend.
202outcome_unknownThe broker connection failed while the request was in flight. It may or may not have executed.Poll the request until it resolves. Never resend it under a new key.
202awaiting_confirmationA proposal was created. Nothing was sent to the broker.The account owner confirms it in the web terminal.
422problemThe broker refused the order. code says why: rejected_by_broker, rejected, invalid_volume, invalid_stops, market_closed…Fix the order, or wait for the market to open, then send it with a new key.
4xxproblemJAFX's checks refused it before it reached the broker (see below).See the code.

The result object:

Response 201
{
  "request_id": "01JQ8Z6M3S4X7T2N9CKV5W0HRB",
  "kind": "market",
  "status": "filled",
  "ticket": 5001,
  "broker_status": "dc-answered",
  "failure": null,
  "client_tag": "breakout-v2",
  "position": {
    "ticket": 5001, "symbol": "EURUSD", "side": "buy", "volume": "0.02",
    "open_price": 1.11555, "open_time": "2026-10-13T09:29:47.512Z",
    "stop_loss": 1.11, "take_profit": null, "profit": "-0.02",
    "origin": "api", "client_tag": "breakout-v2", "from_ticket": null
  }
}
  • request_id identifies this order request; use it with GET /accounts/{account}/requests/{request_id}.
  • kind: market, pending, modify_position, modify_order, close or cancel.
  • broker_status is the broker's own decision code, useful when you contact support. Branch on status, not on it.
  • failure explains, in the broker's words, why a request it decided against was refused ("status": "rejected"). A refusal answered at once comes as a problem instead, with the reason in detail and a code such as invalid_stops or market_closed.

Following a request

GET /accounts/{account}/requests/{request_id} shows where any order request stands. When the request is still open it checks with the broker before answering.

statusMeaning
received, sentRecorded, then sent to the broker; the decision is on its way.
pendingThe broker is holding it.
filledA market open or a close executed.
placedA pending order was placed, or a change or cancel was applied.
rejectedThe broker decided against it.
refused_by_brokerThe broker refused the request itself, for example because of invalid stops.
refusedJAFX's checks refused it; it never reached the broker.
not_sentThe broker connection was unavailable; nothing happened.
outcome_unknownThe connection failed mid-flight; JAFX keeps checking until it knows.
proposedIt became a proposal (confirm mode).

Stops and targets

Send only what changes. A field you omit is kept; null removes it.

Shell
# Move the stop loss; the take profit stays as it is
curl -X PATCH https://terminal.jafx.com/trading-api/v1/accounts/$ACCOUNT/positions/5001 \
  -H "Authorization: Bearer $JAFX_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" -d '{"stop_loss":1.1105}'

# Remove the take profit
curl -X PATCH https://terminal.jafx.com/trading-api/v1/accounts/$ACCOUNT/positions/5001 \
  -H "Authorization: Bearer $JAFX_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" -d '{"take_profit":null}'

Stop and target changes count against the key's modifications_per_minute, not its order budget. A trailing stop is your bot's own (see Not offered): move the stop only when the price has moved meaningfully, rather than on every quote.

Pending orders

PATCH /accounts/{account}/orders/{ticket} changes price, stop_loss, take_profit or expires_at; omitted fields are kept and null removes a stop or the expiry. DELETE /accounts/{account}/orders/{ticket} cancels the order. When a pending order fills, the orders stream sends order.triggered followed by position.opened.

Closing

An empty body closes the whole position at market. {"volume": "0.01"} closes part of it.

After a partial close, the part that stays open is a new position with a new ticket: the answer's ticket is that new ticket, and its position.from_ticket names the original. The remainder keeps the original's client_tag. In the history, the closed part appears with "state": "closed_partial".

Partial close, response 200
{
  "request_id": "01JQ8ZD9R2K6W4T8NB1XQ5VH3M",
  "kind": "close",
  "status": "filled",
  "ticket": 5002,
  "position": { "ticket": 5002, "volume": "0.01", "client_tag": "breakout-v2", "from_ticket": 5001 }
}

Tags (client_tag)

  • Optional, up to 32 characters from A–Z a–z 0–9 . _ : -, set when you place the order.
  • Returned on positions, pending orders, closed trades and stream events, and filterable: GET …/positions?client_tag=breakout-v2.
  • Kept by the remainder of a partial close.
  • Use it to tell strategies apart, like the magic number some platforms give each strategy: "magic:20231105".

Trades placed outside the API have no tag. Their origin says where they came from: api, web, mobile, dealer, expert, signal, client or other.

Reading the account

  • Summary (GET /accounts/{account}): balance, credit, equity, margin, free_margin, floating_profit in the account currency, and margin_level in percent (null with no margin in use).
  • Positions include the floating profit, swap, commission and taxes.
  • Closed trades (GET …/trades) are ordered by close time, newest first, in windows of up to 90 days, with next_cursor for more. state is closed, closed_partial, closed_by, cancelled or expired; cancelled and expired pending orders appear here too. close_reason says what closed a position: stop_loss, take_profit, stop_out (the margin level fell to the stop-out level) or client (an order closed it, from JAFX Terminal or the API); it is null for pending orders. A position a stop out closed has stop_out: the account's margin_level (percent), equity and margin at that moment, as the platform recorded them ({"margin_level": 68.78, "equity": "6583.82", "margin": "9572.30"}); it is null for every other close and where the platform recorded no figures. The platform's [sl], [tp] or [so: …] at the end of comment stays as it writes it.
  • Balance operations (GET …/transactions): deposits, withdrawals and credit, as balance or credit rows.

For live updates, subscribe to the account and orders channels on the stream instead of polling.

Share pictures

The JAFX picture of a trade's result that JAFX Terminal's Share button makes, as a PNG your bot can post or your assistant can show you: the market, long or short with the leverage its margin was charged at, the return on that margin (ROI), the entry and the close or market price, the date, and DEMO on a demo account, beside the market's real candles while the trade was open. Never your name, account number or balance; the P&L amount only when you ask for it.

Your last closed trade as a story
curl "https://terminal.jafx.com/trading-api/v1/accounts/$ACCOUNT/trades/$TICKET/share-image?size=story" \
  -H "Authorization: Bearer $JAFX_API_KEY" -o jafx-trade.png
  • Which trade: an open position by its ticket from GET …/positions (…/positions/{ticket}/share-image), or a closed trade by its ticket from GET …/trades (…/trades/{ticket}/share-image). You send only the ticket: every figure is read from your account, as the terminal reads it, so no picture can show a trade that didn't happen. An open position is valued at your account's own price now.
  • Options: size portrait (1080 × 1350, a post; the default), story (1080 × 1920) or landscape (1200 × 675); show_amount=true adds the P&L in your account's currency under the ROI; utc_offset, the minutes east of UTC its date is written in (120 for UTC+2; default UTC).
  • ROI is the trade's P&L after swap, commission and taxes as a percentage of the margin it took when it opened. Where that margin can't be worked out (a futures market, no rate into your account's currency) the picture shows the price move instead, labelled so.
  • The chart is the market's own candles from JAFX's price history, never drawn from the trade's prices. Their size follows how long the trade was open, counting only the hours its market traded: about 15 of them, one-minute candles for a trade of about 20 minutes, 15-minute ones for about 4 hours, up to weekly ones. It ends with the candle the trade closed in (an open position's: the one forming now), with the entry and the close or market price marked; a trade longer than 15 candles shows all of them, up to 30. A trade of about a minute shows the market's last 15 one-minute candles without marks. A trade older than the history kept for its length (2,000 candles of each size: one-minute ones reach back about a day and a half of trading, 15-minute ones three to four weeks, hourly ones three to four months) shows coarser candles while they still hold a few of it, else no chart. Over MCP, the text line says which.
  • The answer: 200 with the PNG (image/png, Cache-Control: no-store, the terminal's file name in Content-Disposition: jafx-EURUSD-2026-11-14.png). A ticket your account doesn't have is 404 order_not_found for a position and 404 trade_not_found for a closed trade, whoever's it is.
  • Limit: 10 pictures a minute per key, 5 at once, REST and MCP together; then 429 rate_limited with Retry-After. A refusal doesn't count. Over MCP, get_share_image gives the same picture as an image, with a line saying what it shows.

What can refuse an order

JAFX checks these before anything reaches the broker, in this order. A refusal never costs you a trade, and the idempotency key is released so you can retry once the cause is fixed.

CheckRefusal
The key has trade or trade:propose403 insufficient_scope
Trading is not halted for the key, the account or everyone423 trading_halted
The key matches the account: a demo key cannot trade a live account (and live trading is switched on)403 live_trading_disabled
The ticket exists and is a position (or a pending order) of this account404 order_not_found
The instrument is on the key's allow-list and not excluded from API trading403 symbol_not_allowed
The volume is within max_volume_per_order422 volume_limit_exceeded
Open positions and orders stay within max_open_positions422 position_limit_exceeded
The per-minute budgets of the key and the account429 order_rate_limited, 429 modification_rate_limited
Today's loss is below daily_loss_limit (new positions only)403 daily_loss_limit_reached
The account has an active trading session: a sign-in to JAFX Terminal in the last 24 hours, or around-the-clock trading on409 sign_in_required

Then the order goes to the broker through your account's own session, and the broker validates it against your account: the instrument (symbol_not_available), volume steps (422 invalid_volume), stops (422 invalid_stops), margin, and market hours (422 market_closed, with when it opens again: see Before an order).

Not offered

The trading platform your account is on has no trailing stops, OCO pairs (one order cancelling another), maximum slippage on market orders or stop-limit orders, and JAFX doesn't run them on its own servers for you, so the API has no field for them: an order that sends one anyway is refused with 422 invalid_request, over MCP too. Here is what your bot can do on its side instead:

Not offeredWhat your bot can do
Trailing stopMove the stop itself with PATCH …/positions/{ticket}, in steps once the price has moved meaningfully (changes use modifications_per_minute). The platform holds the last stop you set and closes the position there even while your bot is offline; it only stops trailing.
OCO pairFor a stop and a target on one position, give it both stop_loss and take_profit: whichever is reached first closes the position. For two pending orders, cancel the other with DELETE …/orders/{ticket} when the orders stream sends order.triggered for one; until then, both can fill.
Maximum slippageA market order fills at the broker's price when it arrives, however far that is from the price you read. Read your account's own price just before sending (GET /quotes?price_basis=account), and the answer's position.open_price says what you got. When the price matters more than filling now, use a limit order, which waits for its price.
Stop-limit orderPlace the limit order yourself once your trigger price trades, or use a stop order, which fills at market once its price is reached.

Porting a bot from another platform

In your botWith the JAFX API
A strategy's magic numberclient_tag, for example "magic:20231105", and ?client_tag= filters.
Retrying an order that may have gone throughOne Idempotency-Key per intended order, reused for every retry. A retry never opens a second position.
Looping over the open ordersGET …/positions?client_tag=…, or keep state from the orders stream.
Reading the account's equityGET /accounts/{account} or the account stream channel.
Trailing stop on every tickThe platform has no trailing stop of its own (see Not offered): move the stop only when it has moved by a meaningful step; changes use modifications_per_minute.
Server timeUTC everywhere; the broker day starts at midnight Europe/Athens.

Most orders are acknowledged well within a second. When the broker covers a trade with a liquidity provider it can take a few seconds: that is the 202 pending case.

Automated and AI-driven trading can lose money quickly; nothing in these docs is investment advice.

JAFX (PTY) LTD · FSCA FSP No. 52058 · Trading leveraged derivatives with JAFX carries a high risk of losing money rapidly. It is not suitable for everyone.