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.

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

Request body object required

Responses

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

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.

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

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-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",
        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",
  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.

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

Request body object required

Responses

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

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).

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

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-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",
        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",
  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.