View as Markdown

API reference / Account REST API (/users/current)

Trading

Account REST API (/users/current). Generated from the OpenAPI document the services export (/openapi.json).

Samples use the placeholders YOUR_API_KEY and YOUR_ACCOUNT_ID. Paste a sandbox key (twsk_…) to fill them in and to use Try it. It stays in this browser tab and is only sent to the sandbox, never to the live API.

Try it is off in this build: No sandbox URL is configured for this build of the docs.

POST /users/current/accounts/{account_id}/calculate-margin

Calculate Margin Auth: auth-token

Margin for an order: {margin}, or {} if not calculable. The order type is type; a body with actionType instead gets a 400 that says so.

Parameters of POST /users/current/accounts/{account_id}/calculate-margin
ParameterInTypeDescription
account_id requiredpathstring

Request body object required

Responses

  • 200 Successful Response
  • 400 Bad request. On the account API paths a body or query validation failure is a 400 ValidationError with details: [{parameter, message}]. · ErrorEnvelope
  • 401 No credential was sent, or it is not valid or has expired. · ErrorEnvelope
  • 403 The credential is valid but may not do this, for example a read-only key on a change, or a token without the needed role or account. · ErrorEnvelope
  • 404 The account does not exist or this credential cannot see it, or the position, order or symbol in the path was not found. · ErrorEnvelope
  • 422 The body is not valid JSON, or a typed query parameter is not valid. details lists each one. · ErrorEnvelope
  • 429 Too many requests. Wait the Retry-After seconds, then try again. · ErrorEnvelope
  • 503 The terminal is not connected or not synchronized yet. Wait the Retry-After seconds, then try again. · ErrorEnvelope

Errors (common for this kind of call; every error uses one envelope)

curl

curl -sS -X POST 'https://api.tickwire.io/users/current/accounts/YOUR_ACCOUNT_ID/calculate-margin' \
  -H 'auth-token: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"symbol":"EURUSD","type":"ORDER_TYPE_BUY","volume":0.01,"openPrice":1.1}'

Python

from tickwire import Tickwire

with Tickwire("https://api.tickwire.io", "YOUR_API_KEY") as tw:
    result = tw.request(
        "POST",
        "/users/current/accounts/YOUR_ACCOUNT_ID/calculate-margin",
        json={
            "symbol": "EURUSD",
            "type": "ORDER_TYPE_BUY",
            "volume": 0.01,
            "openPrice": 1.1,
        },
        idempotency_key="my-request-1",
        reason="why you are doing this",
    )
    print(result)

TypeScript

import { TickwireClient } from "@tickwire/sdk";

const tw = new TickwireClient({ baseUrl: "https://api.tickwire.io", token: "YOUR_API_KEY" });
const result = await tw.request("POST", "/users/current/accounts/YOUR_ACCOUNT_ID/calculate-margin", {
  body: {"symbol":"EURUSD","type":"ORDER_TYPE_BUY","volume":0.01,"openPrice":1.1},
  idempotencyKey: "my-request-1",
  reason: "why you are doing this",
});
console.log(result);
tw.close();
Try it in the sandbox

Try it is off in this build of the docs: no sandbox URL is configured. The samples above work against the sandbox with your sandbox key.

POST /users/current/accounts/{account_id}/trade

Execute a trade Idempotency-Key Auth: auth-token

Execute a trade (MT4 and MT5). Body: a MetatraderTrade. actionType is one of ORDER_TYPE_BUY|SELL, ORDER_TYPE_BUY_LIMIT|SELL_LIMIT|BUY_STOP|SELL_STOP, ORDER_TYPE_BUY_STOP_LIMIT|SELL_STOP_LIMIT (MT5 only), POSITION_MODIFY, POSITION_PARTIAL, POSITION_CLOSE_ID, POSITION_CLOSE_BY, POSITIONS_CLOSE_SYMBOL, ORDER_MODIFY or ORDER_CANCEL. Relative SL/TP units, fillingModes, expiration, slippage, magic, comment + clientId (30 characters together) and trailingStopLoss are supported. HTTP 200 even when the broker rejects the trade: {numericCode, stringCode, message, orderId?, positionId?}. Success codes are 0, 10008, 10009, 10010 and 10025. Tickwire adds outcome (applied|no_change|partial|rejected|unknown), isEffective, retcode (the terminal's own code), replayed and, for POSITIONS_CLOSE_SYMBOL, a per-position positions list. outcome=unknown means the order may have executed: check positions and orders before retrying. Tickwire never resends new exposure on its own. Idempotency: the Idempotency-Key header, else clientId. A replay returns the stored result with replayed: true; the same key with a different body is 409 ConflictError. X-Actor and X-Reason go to the audit trail. A malformed request is 400 ValidationError with details: [{parameter, message}]; what MT4 can't do (stop-limit, DAY expiry) answers numericCode -4 with error: not_supported_on_mt4. An Idempotency-Key over 255 characters or with anything but printable ASCII is 400 ValidationError with code: invalid_idempotency_key and sent: false; it is never truncated. X-Actor and X-Reason are printable ASCII too: send other text percent-encoded as UTF-8 (caf%C3%A9), which is decoded for the audit trail. A raw value outside printable ASCII is 400 ValidationError with code: invalid_audit_header and sent: false. Unknown body fields are refused (400 ValidationError, code: unknown_field, with a did-you-mean hint), so a misspelt stopLosss can't be silently dropped. volume on POSITION_CLOSE_ID, POSITION_CLOSE_BY or POSITIONS_CLOSE_SYMBOL is refused: those close the whole position; use POSITION_PARTIAL to close part of one. Stale quotes (BUG-063): ORDER_TYPE_BUY|SELL on a symbol whose quote is not moving (no Market Watch price moved for 30 s, this symbol not for 5 min, or a days-old cached quote) is refused before sending: 409 ConflictError, code: quote_stale, sent: false, with symbol, staleScope and quietSeconds. The key is freed, so the same request can be retried once prices move. allowStaleQuote: true (Tickwire extension) sends it anyway. Pending orders, closes, partial closes, close-by and modifies are never refused for a stale quote.

Parameters of POST /users/current/accounts/{account_id}/trade
ParameterInTypeDescription
account_id requiredpathstring
Idempotency-Keyheaderstring | null
X-Actorheaderstring
X-Reasonheaderstring

Request body object required

Responses

  • 200 The trade's result, also when the broker rejects it. · TradeResult
  • 400 Bad request. On the account API paths a body or query validation failure is a 400 ValidationError with details: [{parameter, message}]. · ErrorEnvelope
  • 401 No credential was sent, or it is not valid or has expired. · ErrorEnvelope
  • 403 The credential is valid but may not do this, for example a read-only key on a change, or a token without the needed role or account. · ErrorEnvelope
  • 404 The account does not exist or this credential cannot see it, or the position, order or symbol in the path was not found. · ErrorEnvelope
  • 422 The body is not valid JSON, or a typed query parameter is not valid. details lists each one. · ErrorEnvelope
  • 429 Too many requests. Wait the Retry-After seconds, then try again. · ErrorEnvelope
  • 503 The terminal is not connected or not synchronized yet. Wait the Retry-After seconds, then try again. · ErrorEnvelope

Errors (common for this kind of call; every error uses one envelope)

curl

curl -sS -X POST 'https://api.tickwire.io/users/current/accounts/YOUR_ACCOUNT_ID/trade' \
  -H 'auth-token: YOUR_API_KEY' \
  -H 'Idempotency-Key: my-request-1' \
  -H 'X-Actor: my-app' \
  -H 'X-Reason: why you are doing this' \
  -H 'Content-Type: application/json' \
  -d '{"actionType":"ORDER_TYPE_BUY","symbol":"EURUSD","volume":0.01}'

Python

from tickwire import Tickwire

with Tickwire("https://api.tickwire.io", "YOUR_API_KEY") as tw:
    result = tw.request(
        "POST",
        "/users/current/accounts/YOUR_ACCOUNT_ID/trade",
        json={"actionType": "ORDER_TYPE_BUY", "symbol": "EURUSD", "volume": 0.01},
        idempotency_key="my-request-1",
        actor="my-app",
        reason="why you are doing this",
    )
    print(result)

TypeScript

import { TickwireClient } from "@tickwire/sdk";

const tw = new TickwireClient({ baseUrl: "https://api.tickwire.io", token: "YOUR_API_KEY" });
const result = await tw.request("POST", "/users/current/accounts/YOUR_ACCOUNT_ID/trade", {
  body: {"actionType":"ORDER_TYPE_BUY","symbol":"EURUSD","volume":0.01},
  idempotencyKey: "my-request-1",
  actor: "my-app",
  reason: "why you are doing this",
});
console.log(result);
tw.close();
Try it in the sandbox

Try it is off in this build of the docs: no sandbox URL is configured. The samples above work against the sandbox with your sandbox key.

POST /users/current/accounts/{account_id}/trade/check

Trade Check Auth: auth-token

Dry-run a trade: the same body as /trade. Runs every pre-flight check (and, on MT5, the terminal's own order check) and returns the resolved request plus margin figures. Nothing is sent. A market order on a stale quote answers 409 code: quote_stale, as /trade would.

Parameters of POST /users/current/accounts/{account_id}/trade/check
ParameterInTypeDescription
account_id requiredpathstring

Request body object required

Responses

  • 200 Successful Response
  • 400 Bad request. On the account API paths a body or query validation failure is a 400 ValidationError with details: [{parameter, message}]. · ErrorEnvelope
  • 401 No credential was sent, or it is not valid or has expired. · ErrorEnvelope
  • 403 The credential is valid but may not do this, for example a read-only key on a change, or a token without the needed role or account. · ErrorEnvelope
  • 404 The account does not exist or this credential cannot see it, or the position, order or symbol in the path was not found. · ErrorEnvelope
  • 422 The body is not valid JSON, or a typed query parameter is not valid. details lists each one. · ErrorEnvelope
  • 429 Too many requests. Wait the Retry-After seconds, then try again. · ErrorEnvelope
  • 503 The terminal is not connected or not synchronized yet. Wait the Retry-After seconds, then try again. · ErrorEnvelope

Errors (common for this kind of call; every error uses one envelope)

curl

curl -sS -X POST 'https://api.tickwire.io/users/current/accounts/YOUR_ACCOUNT_ID/trade/check' \
  -H 'auth-token: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"actionType":"ORDER_TYPE_BUY","symbol":"EURUSD","volume":0.01}'

Python

from tickwire import Tickwire

with Tickwire("https://api.tickwire.io", "YOUR_API_KEY") as tw:
    result = tw.request(
        "POST",
        "/users/current/accounts/YOUR_ACCOUNT_ID/trade/check",
        json={"actionType": "ORDER_TYPE_BUY", "symbol": "EURUSD", "volume": 0.01},
        idempotency_key="my-request-1",
        reason="why you are doing this",
    )
    print(result)

TypeScript

import { TickwireClient } from "@tickwire/sdk";

const tw = new TickwireClient({ baseUrl: "https://api.tickwire.io", token: "YOUR_API_KEY" });
const result = await tw.request("POST", "/users/current/accounts/YOUR_ACCOUNT_ID/trade/check", {
  body: {"actionType":"ORDER_TYPE_BUY","symbol":"EURUSD","volume":0.01},
  idempotencyKey: "my-request-1",
  reason: "why you are doing this",
});
console.log(result);
tw.close();
Try it in the sandbox

Try it is off in this build of the docs: no sandbox URL is configured. The samples above work against the sandbox with your sandbox key.

GET /users/current/accounts/{account_id}/trailing-stop-losses

List Trailing Auth: auth-token

Trailing stop rules Tickwire runs for this account (state: active | pending; pending waits for its pending order to fill).

Parameters of GET /users/current/accounts/{account_id}/trailing-stop-losses
ParameterInTypeDescription
account_id requiredpathstring

Responses

  • 200 Successful Response
  • 400 Bad request. On the account API paths a body or query validation failure is a 400 ValidationError with details: [{parameter, message}]. · ErrorEnvelope
  • 401 No credential was sent, or it is not valid or has expired. · ErrorEnvelope
  • 403 The credential is valid but may not do this, for example a read-only key on a change, or a token without the needed role or account. · ErrorEnvelope
  • 404 The account does not exist or this credential cannot see it, or the position, order or symbol in the path was not found. · ErrorEnvelope
  • 429 Too many requests. Wait the Retry-After seconds, then try again. · ErrorEnvelope
  • 503 The terminal is not connected or not synchronized yet. Wait the Retry-After seconds, then try again. · ErrorEnvelope

Errors (common for this kind of call; every error uses one envelope)

curl

curl -sS -X GET 'https://api.tickwire.io/users/current/accounts/YOUR_ACCOUNT_ID/trailing-stop-losses' \
  -H 'auth-token: YOUR_API_KEY'

Python

from tickwire import Tickwire

with Tickwire("https://api.tickwire.io", "YOUR_API_KEY") as tw:
    result = tw.request(
        "GET",
        "/users/current/accounts/YOUR_ACCOUNT_ID/trailing-stop-losses",
    )
    print(result)

TypeScript

import { TickwireClient } from "@tickwire/sdk";

const tw = new TickwireClient({ baseUrl: "https://api.tickwire.io", token: "YOUR_API_KEY" });
const result = await tw.request("GET", "/users/current/accounts/YOUR_ACCOUNT_ID/trailing-stop-losses");
console.log(result);
tw.close();
Try it in the sandbox

Try it is off in this build of the docs: no sandbox URL is configured. The samples above work against the sandbox with your sandbox key.

DELETE /users/current/accounts/{account_id}/trailing-stop-losses/{position_id}

Delete Trailing Idempotency-Key Auth: auth-token

Stop trailing a position (the current SL stays where it is). A bad Idempotency-Key is 400 invalid_idempotency_key, as on /trade.

Parameters of DELETE /users/current/accounts/{account_id}/trailing-stop-losses/{position_id}
ParameterInTypeDescription
account_id requiredpathstring
position_id requiredpathstring
Idempotency-Keyheaderstring | null
X-Actorheaderstring
X-Reasonheaderstring

Responses

  • 200 Successful Response
  • 400 Bad request. On the account API paths a body or query validation failure is a 400 ValidationError with details: [{parameter, message}]. · ErrorEnvelope
  • 401 No credential was sent, or it is not valid or has expired. · ErrorEnvelope
  • 403 The credential is valid but may not do this, for example a read-only key on a change, or a token without the needed role or account. · ErrorEnvelope
  • 404 The account does not exist or this credential cannot see it, or the position, order or symbol in the path was not found. · ErrorEnvelope
  • 429 Too many requests. Wait the Retry-After seconds, then try again. · ErrorEnvelope
  • 503 The terminal is not connected or not synchronized yet. Wait the Retry-After seconds, then try again. · ErrorEnvelope

Errors (common for this kind of call; every error uses one envelope)

curl

curl -sS -X DELETE 'https://api.tickwire.io/users/current/accounts/YOUR_ACCOUNT_ID/trailing-stop-losses/POSITION_ID' \
  -H 'auth-token: YOUR_API_KEY' \
  -H 'Idempotency-Key: my-request-1' \
  -H 'X-Actor: my-app' \
  -H 'X-Reason: why you are doing this'

Python

from tickwire import Tickwire

with Tickwire("https://api.tickwire.io", "YOUR_API_KEY") as tw:
    result = tw.request(
        "DELETE",
        "/users/current/accounts/YOUR_ACCOUNT_ID/trailing-stop-losses/POSITION_ID",
        idempotency_key="my-request-1",
        actor="my-app",
        reason="why you are doing this",
    )
    print(result)

TypeScript

import { TickwireClient } from "@tickwire/sdk";

const tw = new TickwireClient({ baseUrl: "https://api.tickwire.io", token: "YOUR_API_KEY" });
const result = await tw.request("DELETE", "/users/current/accounts/YOUR_ACCOUNT_ID/trailing-stop-losses/POSITION_ID", {
  idempotencyKey: "my-request-1",
  actor: "my-app",
  reason: "why you are doing this",
});
console.log(result);
tw.close();
Try it in the sandbox

Try it is off in this build of the docs: no sandbox URL is configured. The samples above work against the sandbox with your sandbox key.