Introduction
This API gives Trade Academy read-only access to your users' MetaTrader 4 and MetaTrader 5 accounts. You add an account with its login, password and server. We connect it, keep it connected around the clock, and from then on report every change on it: positions opened, modified, partially closed and closed, balance and equity. Your users install nothing.
Changes reach you as webhooks, sent as soon as we receive them. The endpoints give you the current state at any time, for every account in a single call if you want it, so you can rebuild your view whenever you need to.
How it works
- Every account stands alone. There are no master or follower roles and nothing is copied between accounts. A user may have one account or twenty; each is its own record.
- Investor or master password. Both are accepted. With an investor password, MetaTrader itself gives read-only access: the broker's trade server rejects any trade request made with it. With a master password the account could trade in principle, but this API has no endpoint that opens, modifies or closes a trade, and we never send a trade request on an account connected through it.
- Connected 24/7. After broker maintenance, a broker outage or a restart on our side, the account reconnects by itself. You are told when an account is down for real, not on every short interruption — see Account status.
- Separate hosting. From go-live, your accounts run on hosts reserved for Trade Academy, separate from our standard plans, so load from other customers does not slow them down. During the test phase they share hosts with other customers.
- Your identifiers travel with the account. Store your own
account id in
referenceand your user id inuser_ref. Both come back on every response and every webhook, so you never need a mapping table.
Base URL and versioning
https://tradeacademy.copysync.net/api/v2/
HTTPS only, TLS 1.2 or newer. Plain HTTP requests are redirected, and you should not rely on the redirect.
Within v2 we only make additive changes: new endpoints, new response
fields, new event types and new values in enumerations. Nothing you rely on is
renamed or removed. Build your client to ignore fields and values it does not know.
Authentication
Every request carries your platform key in the X-API-Key header. There
are no cookies, sessions or OAuth flows.
curl "https://tradeacademy.copysync.net/api/v2/accounts" \ -H "X-API-Key: cs_org_7f3a…"
- One key for the whole platform. It reaches every account you have created and nothing else. It is meant for your backend only; never ship it to a browser or a mobile app.
- Shown once. We store only a hash of the key and hand it to you exactly once. If it is lost, we issue a new one.
- Rotation without downtime. On request we issue a second key. Both work side by side until you confirm the switch, then we revoke the old one.
- IP allowlist. Send us the addresses your backend calls from and
we bind the key to them. Requests from anywhere else are refused with
403 ip_not_allowed, even with a valid key. - Foreign ids look missing. An id that is not yours returns
404, never403, so ids cannot be probed.
Rate limits
Limits apply per key, per one-minute window. They are part of our agreement with you and are raised as your account count grows.
| Class | Limit | Applies to |
|---|---|---|
| read | 600 / min | All GET requests |
| write | 120 / min | PATCH, PUT and every POST except creating an account |
| provisioning | 60 / min | POST /accounts and every DELETE |
Every response carries the current state of your budget:
RateLimit-Limit: 600 RateLimit-Remaining: 583 RateLimit-Reset: 41 # seconds until the window refills Retry-After: 41 # on 429 only
On 429 the request was not processed; wait for
Retry-After and send it again. Webhooks do not count against your
limits, and neither does anything we send you.
Conventions
- Content type. Requests with a body send
Content-Type: application/json. Responses are alwaysapplication/json; charset=utf-8. - Timestamps are ISO 8601 in UTC, e.g.
2026-11-26T08:14:22Z. Date-only parameters areYYYY-MM-DD, also UTC. - Broker time. MetaTrader shows times in the broker's server
time, which is usually not UTC. Every account carries
broker_utc_offsetin seconds; add it to a UTC timestamp to get the time your user sees in MetaTrader. - Numbers are JSON numbers, not strings. Money has two decimals, volumes two, prices as many as the symbol has at the broker. Decode money into a decimal type if your language has one.
- Nulls mean “not known”. An account that has not connected yet
has
balance: null, not0. Do not treat the two the same. - Ids are integers, unique, and never reused after deletion. Tickets are the broker's own position numbers.
- Unknown fields are refused on input with
422, so a misspelt name does not pass unnoticed. On output, new fields may appear at any time. - Field selection. Add
?fields=id,reference,equitytoGET /accountsorGET /accounts/{id}/tradesto trim the response. Only top-level fields can be selected.
Response envelope
A single object is returned as it is. A collection comes under data
with pagination fields next to it, never as a bare array.
{
"id": 5120,
"reference": "acc_20931"
}
{
"data": [ … ],
"has_more": true,
"next_cursor": "eyJpZCI6NTEyMH0"
}
Idempotency
GET, PUT, PATCH and DELETE can be
repeated safely. POST cannot, so every POST accepts an
Idempotency-Key header: any unique string up to 255 characters,
typically a UUID or your own account id.
curl -X POST "https://tradeacademy.copysync.net/api/v2/accounts" \ -H "X-API-Key: $CS_KEY" \ -H "Idempotency-Key: acc_20931" \ -H "Content-Type: application/json" \ -d @account.json
We keep the result of the first request under that key for 24 hours.
A repeat with the same key returns the original response with
Idempotent-Replay: true, without acting again. The same key with a
different body is refused with 409 idempotency_key_reused.
Errors are kept like successes, except 5xx: after a
500 the key is free again, so the retry really runs. A repeat that
arrives while the first request is still running gets
409 idempotency_key_in_progress; retry it a few seconds later.
Pagination
List endpoints are cursor-paginated. Pass limit (1–500, default 100)
and, for every page after the first, the next_cursor of the previous
one. When has_more is false you are done.
cursor = null loop: url = "/api/v2/accounts/5120/trades?limit=500" if cursor: url += "&cursor=" + cursor page = GET(url) process(page.data) if not page.has_more: break cursor = page.next_cursor
Cursors are opaque; do not parse or store them. Unlike offsets, they stay correct while new trades are being written.
The account object
One object is one MetaTrader account. It holds your identifiers, what the broker reports about the account, its live figures and its connection status.
{
"id": 5120,
"reference": "acc_20931",
"user_ref": "user_8812",
"name": "Challenge 100k",
"platform": "MT5",
"broker": "Example Markets Ltd",
"broker_server": "ExampleMarkets-Live",
"login": "51203399",
"account_type": "real",
"currency": "USD",
"leverage": 100,
"trade_allowed": false,
"broker_utc_offset": 7200,
"balance": 100000.00,
"equity": 101245.30,
"credit": 0.00,
"margin": 1530.00,
"free_margin": 99715.30,
"margin_level": 6617.34,
"floating_pl": 1245.30,
"open_positions": 2,
"last_data_at": "2026-11-26T08:14:22Z",
"status": {
"state": "connected",
"reason": null,
"message": null,
"since": "2026-11-20T09:02:11Z"
},
"history": {
"mode": "full",
"state": "complete"
},
"created_at": "2026-11-20T08:58:40Z",
"updated_at": "2026-11-26T08:14:22Z"
}
Field reference
| Field | Type | Description |
|---|---|---|
| id | integer | Our identifier. Stable, never reused. |
| reference | string · null | Your identifier for this account, up to 128 characters, returned untouched. |
| user_ref | string · null | Your identifier for the user who owns the account, up to 128 characters. Filter on it to get one user's accounts. |
| name | string | Display name, 1–100 characters. Defaults to platform and login. |
| platform | enum | MT4 or MT5. |
| broker | string · null | Broker company name as MetaTrader reports it. Filled on first connect. |
| broker_server | string | The broker's server name, exactly as entered at creation. |
| login | string | The account number. The password is never returned. |
| account_type | enum · null | real, demo or contest. |
| currency | string · null | Deposit currency, ISO 4217. All money on this account is in it. |
| leverage | integer · null | e.g. 100 for 1:100. |
| trade_allowed | boolean · null | Whether the broker would accept trades on this login. false on an investor password, and on an account on which the broker has switched trading off. Such an account stays connected and keeps reporting. |
| broker_utc_offset | integer · null | Broker server time minus UTC, in seconds. Changes with the broker's daylight saving time. |
| balance | number · null | Balance from closed trades and balance operations. |
| equity | number · null | Balance plus floating profit and loss. |
| credit | number · null | Broker credit or bonus, if any. |
| margin | number · null | Margin in use. |
| free_margin | number · null | Margin available for new positions. |
| margin_level | number · null | Equity ÷ margin, in percent. null with no open position. |
| floating_pl | number · null | Unrealised profit and loss across open positions. |
| open_positions | integer | Number of open positions. |
| last_data_at | timestamp · null | When we last received figures for this account. Show it next to the numbers when the account is not connected. |
| status | object | Connection state and reason. See Account status. |
| history | object | mode is full or from_activation, chosen at creation. state is importing while a full history is being loaded, then complete. |
| created_at | timestamp | When the account was created. |
| updated_at | timestamp | Last change to any field, live figures included. Not useful for change detection; use webhooks. |
Account status
status.state says whether data is flowing for an account. Drive your
interface from it, and treat any value you do not know as “not connected”.
| State | Meaning |
|---|---|
| pending | Accepted and queued. Normally a few seconds. |
| connecting | Logging in at the broker and loading the account. Typically one to three minutes for a new account. |
| connected | Live. Positions, balance and equity are current. |
| disconnected | No data for at least three minutes. We keep reconnecting by ourselves; reason says why it is down. Returns to connected without action from you. |
| error | Cannot connect until you or your user change something. reason says what. |
| deleting | Deletion accepted and in progress. |
pending → connecting → connected ⇄ disconnected
↓
error → PUT …/credentials → connecting
any state → deleting → gone
Brokers drop connections for a few seconds all the time, especially around their
daily maintenance. An account only moves to disconnected after three
minutes without data. Shorter interruptions produce no state change and no
webhook, so you can alert your users on disconnected directly,
without filtering of your own.
Reasons
status.reason is a stable code; status.message is readable
text whose wording may change. Branch on the code.
| Reason | State | Meaning and next step |
|---|---|---|
| invalid_password | error | The broker rejected the password, or stopped accepting a login that worked before, typically because the password was changed. Ask your user for the correct one and send it with PUT …/credentials. |
| invalid_login | error | The account number does not exist on this broker server. |
| server_not_found | error | broker_server is not known. Server names are case-sensitive; check the exact spelling in your user's MetaTrader. |
| account_disabled | error | The broker has disabled, archived or closed the account, so it can no longer log in. Only the broker can undo it. An account on which the broker has only switched trading off, as often happens after a failed or expired challenge, is not an error: it stays connected and keeps reporting, with trade_allowed: false. |
| broker_unreachable | disconnected | The broker's servers are not answering, e.g. during maintenance. Resolves by itself. |
| connection_lost | disconnected | The link between the account and us is interrupted. We reconnect automatically; nothing is needed from you. |
| setup_failed | error | On our side. We are alerted automatically and take care of it; nothing is needed from you. |
A wrong password, login or server is not checked when you create the account: the
broker tells us when we log in. Expect it as an
account.status_changed event to error, typically within one
to three minutes of creation.
There is no separate reason for the wrong platform. Each platform has its own
servers and accounts, so an MT4 account created as MT5, or the reverse, ends in
server_not_found or invalid_login. If your user is not
sure, ask which MetaTrader they log in with; to fix it, delete the account and
create it again with the right platform.
Account endpoints
| Query parameter | Type | Description |
|---|---|---|
| user_ref | string | Only this user's accounts. |
| reference | string | Exact match on your account identifier. |
| state | enum | Filter on status.state, e.g. error for everything that needs attention. |
| platform | enum | MT4 or MT5. |
| fields | string | Comma-separated list of fields to return. |
| limit | integer | 1–500, default 100. |
| cursor | string | From the previous page. |
curl "https://tradeacademy.copysync.net/api/v2/accounts?user_ref=user_8812&fields=id,reference,equity,status" \ -H "X-API-Key: $CS_KEY"
{
"data": [{
"id": 5120,
"reference": "acc_20931",
"equity": 101245.30,
"status": {
"state": "connected",
"reason": null,
"message": null,
"since": "2026-11-20T09:02:11Z"
}
}],
"has_more": false,
"next_cursor": null
}
404 if the id does not exist or is not yours.
Idempotency-Key.
| Body field | Type | Description |
|---|---|---|
| platform | enum, required | MT4 or MT5. |
| broker_server | string, required | The server name exactly as shown in your user's MetaTrader login window, e.g. ExampleMarkets-Live. Case-sensitive. |
| login | string, required | The account number, 3 to 20 digits. A JSON number is accepted too and stored as a string. |
| password | string, required | Investor or master password, 4 to 200 characters. Write-only; no endpoint ever returns it. |
| reference | string | Your identifier for this account, up to 128 characters. |
| user_ref | string | Your identifier for the user, up to 128 characters. |
| name | string | Display name, 1 to 100 characters. Defaults to platform and login. |
| history | enum | from_activation (default): trades start from the moment the account connects. full: the account's existing broker history is imported as well. |
POST /api/v2/accounts
X-API-Key: $CS_KEY
Idempotency-Key: acc_20931
Content-Type: application/json
{
"platform": "MT5",
"broker_server": "ExampleMarkets-Live",
"login": "51203399",
"password": "…",
"reference": "acc_20931",
"user_ref": "user_8812",
"name": "Challenge 100k",
"history": "full"
}
{
"id": 5120,
"reference": "acc_20931",
"user_ref": "user_8812",
"name": "Challenge 100k",
"platform": "MT5",
"broker": null,
"broker_server": "ExampleMarkets-Live",
"login": "51203399",
"account_type": null,
"currency": null,
"leverage": null,
"trade_allowed": null,
"broker_utc_offset": null,
"balance": null,
"equity": null,
"credit": null,
"margin": null,
"free_margin": null,
"margin_level": null,
"floating_pl": null,
"open_positions": 0,
"last_data_at": null,
"status": {
"state": "pending",
"reason": null,
"message": null,
"since": "2026-11-26T08:58:40Z"
},
"history": {
"mode": "full",
"state": "importing"
},
"created_at": "2026-11-26T08:58:40Z",
"updated_at": "2026-11-26T08:58:40Z"
}
201 means the account exists and is being connected, not that the
login worked. Broker fields stay null until the first connect. Wait
for account.status_changed to connected before you show
the account as live.
The same login on the same server can exist only once under your key; a second
create returns 409 duplicate_account with the id of the existing
account. The same login number on a different broker server is a different
account and is accepted.
A reference can likewise be on only one of your accounts
(409 duplicate_reference). An account that is being deleted no
longer counts for either rule, so delete and create again works straight away,
with the same login, server and reference.
Your key holds up to an agreed number of accounts (10 during the test phase);
beyond it, a create returns 403 account_limit_reached. Fields we
do not know are refused with 422, so a misspelt field name does
not pass unnoticed.
With history: "full" the import runs after the account has
connected. Live events start straight away; the imported trades follow. On
accounts with tens of thousands of deals the import can take a while.
account.history_imported fires when it is complete.
Updatable: name, reference, user_ref. Not
updatable: platform and history, which are fixed at
creation. Login, password and server go through
their own endpoint.
Answers 200 with the updated account. Send null to
clear reference or user_ref, or to set
name back to its default. None of these touch the connection.
PATCH /api/v2/accounts/5120
Content-Type: application/json
{ "name": "Challenge 100k — Phase 2" }
invalid_password, invalid_login and
server_not_found, and what you call when your user changes their
password at the broker.
PUT /api/v2/accounts/5120/credentials
Content-Type: application/json
{
"login": "51203399",
"password": "…",
"broker_server": "ExampleMarkets-Live"
}
All three fields are required, even if only the password changed. Answers
200 with the account. It goes back to pending, then
connecting, and you receive the outcome as
account.status_changed. Trade history already collected is kept.
If the login changes, it is a different broker account. Positions of the old login
are then not reported as closed, the open positions of the new one arrive as
position.opened, and its first balance is taken as the starting
point without an account.balance_changed.
While a setup is running (connecting after a create or an earlier
change), new credentials are refused with 409 invalid_state; send
them again a minute later.
Passwords are stored encrypted (AES-256-GCM) and used only to log in. No endpoint returns them, and our support cannot read them.
Answers 202 Accepted. The account shows deleting for a
short time, then disappears, and account.deleted fires. Deletion does
nothing at the broker: the account and its positions stay exactly as they are; we
simply stop reading it. If you need its data, read it before you delete.
{ "id": 5120, "status": { "state": "deleting", "reason": null } }
Repeating the request while the deletion runs returns the same
202; once the account is gone, 404.
Trading data
{
"account_id": 5120,
"reference": "acc_20931",
"currency": "USD",
"broker_utc_offset": 7200,
"as_of": "2026-11-26T08:14:22Z",
"data": [{
"ticket": 88213344,
"symbol": "EURUSD",
"type": "buy",
"volume": 0.50,
"open_time": "2026-11-26T06:31:02Z",
"open_price": 1.08442,
"current_price": 1.08661,
"sl": 1.08100,
"tp": 1.09200,
"profit": 109.50,
"commission": -3.50,
"swap": -1.20
}]
}
| Field | Type | Description |
|---|---|---|
| ticket | integer | The broker's position number. A partial close keeps it: on MT5 the broker does, and on MT4, where the remaining volume gets a new ticket at the broker, we keep reporting the original one. A position therefore has one ticket for its whole life, the same as its trade in /trades. One exception on MT4: if the account restarts between a partial close and the final close, the remaining part continues under its new ticket. |
| type | enum | buy or sell. |
| volume | number | Open volume in lots, after any partial closes. |
| open_time | timestamp · null | When the position was opened, in UTC. null in the rare case it cannot be determined. |
| current_price | number · null | The price the position is valued at right now. |
| sl | number · null | Stop loss. null when none is set. |
| tp | number · null | Take profit. null when none is set. |
| profit | number | Floating profit, excluding commission and swap. |
| commission | number · null | Commission charged so far. Some brokers charge it only on closing; then it is 0 until the position closes. |
| swap | number · null | Accumulated swap. |
as_of is when we last received data. On an account that is not
connected it can be old; show it rather than presenting the figures
as current. commission can be null for a short time
after a position opens; here as everywhere, null means “not known
yet”, not zero.
| Query parameter | Type | Description |
|---|---|---|
| user_ref | string | Only this user's accounts. |
| state | enum | Only accounts in this state. |
| limit | integer | Accounts per page, 1–500, default 100. |
| cursor | string | From the previous page. |
{
"data": [
{
"account_id": 5120,
"reference": "acc_20931",
"user_ref": "user_8812",
"state": "connected",
"as_of": "2026-11-26T08:14:22Z",
"positions": [ /* as in GET /accounts/{id}/positions */ ]
},
{
"account_id": 5121,
"reference": "acc_20932",
"user_ref": "user_8812",
"state": "connected",
"as_of": "2026-11-26T08:14:21Z",
"positions": []
}
],
"has_more": false,
"next_cursor": null
}
Every account is listed, including those without open positions, so an empty
positions array reliably means “nothing open”.
| Query parameter | Type | Description |
|---|---|---|
| from | YYYY-MM-DD | Closed on or after this day, UTC. |
| to | YYYY-MM-DD | Closed on or before this day, UTC. |
| symbol | string | Exact symbol. |
| limit | integer | 1–500, default 100. |
| cursor | string | From the previous page. |
{
"data": [{
"ticket": 88213344,
"symbol": "EURUSD",
"type": "buy",
"volume": 1.00,
"open_time": "2026-11-26T06:31:02Z",
"open_price": 1.08442,
"close_time": "2026-11-26T09:02:44Z",
"close_price": 1.08661,
"sl": 1.08100,
"tp": 1.09200,
"profit": 203.50,
"commission": -7.00,
"swap": 0.00,
"net_profit": 196.50,
"closes": [
{ "volume": 0.50, "price": 1.08626, "profit": 92.00, "time": "2026-11-26T08:10:05Z" },
{ "volume": 0.50, "price": 1.08665, "profit": 111.50, "time": "2026-11-26T09:02:44Z" }
],
"source": "live"
}],
"has_more": true,
"next_cursor": "eyJ0IjoiODgyMTMzNDQifQ"
}
| Field | Type | Description |
|---|---|---|
| volume | number | Volume at opening, in lots. |
| close_time | timestamp | When the last part was closed. |
| close_price | number | Volume-weighted average of all close prices. |
| sl, tp | number · null | Stop loss and take profit at the time of closing. |
| profit | number | Gross result, excluding commission and swap. |
| net_profit | number | profit + commission + swap. Use it for performance figures. |
| closes | array | Each closing step. One entry for a trade closed at once, several after partial closes. On MT4 the steps are joined across the tickets a partial close creates, so one trade here is one trade as your user thinks of it. |
| source | enum | live if we saw it happen, import if it came from a full-history import. |
GET /api/v2/accounts/5120/equity-history
?days=90&interval=hour
{
"account_id": 5120,
"currency": "USD",
"interval": "hour",
"data": [{
"at": "2026-11-26T08:00:00Z",
"balance": 100000.00,
"equity": 101102.70,
"equity_low": 99640.10,
"equity_high": 101390.00,
"floating_pl": 1102.70
}]
}
days is 1–365, default 30. interval is hour
(default) or day. equity_low and equity_high are the
lowest and highest equity within the interval. Use equity_low for
drawdown rules; the value at the full hour misses a dip in between.
limit, cursor).
{
"data": [
{ "id": 5613, "type": "withdrawal", "amount": -750.00, "time": "2026-11-24T14:05:11Z" },
{ "id": 5512, "type": "deposit", "amount": 100000.00, "time": "2026-11-20T09:05:00Z" }
],
"has_more": false,
"next_cursor": null
}
type is deposit or withdrawal; build your
client to accept further values. Withdrawals are negative. Subtract
these from balance changes before you compute a return; otherwise a deposit shows
up as profit.
Webhooks
Register an HTTPS endpoint and we send you every change as it happens: no polling. Each event has a unique id, failed deliveries are retried, and missed events can be replayed.
Registering
{
"url": "https://api.tradeacademy.example/hooks/copysync",
"events": ["*"],
"equity_interval": 5
}
{
"id": 7,
"url": "https://api.tradeacademy.example/hooks/copysync",
"secret": "whsec_9f2c4a…",
"events": ["*"],
"equity_interval": 5,
"active": true,
"failing_since": null,
"disabled_at": null,
"created_at": "2026-11-26T08:50:12Z"
}
url is required. events lists the types you want;
["*"] means all, including types added later, and is the default.
equity_interval is how often, in seconds,
account.equity_updated is sent: 5 to 60, default 5.
failing_since is set while deliveries to the endpoint keep failing and
cleared by the next success; disabled_at is set when we switch it off
(see Auto-disable). Watch both if you
monitor your integration.
The secret is returned once; store it before you close the response.
GET /webhooks lists your endpoints under data, without
the secret, PATCH /webhooks/{id}
changes url, events, equity_interval or
active, and DELETE /webhooks/{id} removes one
(204). Up to five endpoints per key; a sixth is refused with
409 webhook_limit_reached.
The url must be https and reach a public address. Local,
private and reserved addresses are refused, both when you register and on every
delivery, and redirects are not followed.
Events
| Event | Fires when |
|---|---|
| account.created | An account was created and is being connected. Carries the account object under account. |
| account.status_changed | status.state changed. Carries from, to, reason and message. This covers connected, confirmed disconnects, errors such as a wrong password, and reconnects. It also fires when an account stays in error but the reason changes. The first one for a new account always has from: "pending", even if the account was already further along when we first looked. |
| account.history_imported | A full-history import finished. Carries imported_trades. |
| account.deleted | Deletion is complete. Carries account_id, reference and user_ref. |
| position.opened | A position was opened, by any means: by hand, by an Expert Advisor, or a pending order that filled. Positions already open when an account connects are announced this way too, with their original open_time. |
| position.modified | Stop loss or take profit changed, or volume was added (netting accounts). Carries sl, tp, volume, their previous_ values, and the position. |
| position.partially_closed | Part of a position was closed. Carries the closed volume, price and profit, and the volume left open. The position keeps its ticket on both platforms: on MT4 the broker gives the remainder a new ticket, and we keep reporting the original one. If the close details do not reach us within a minute, the event carries the volumes and null for price, profit, commission and swap; the final position.closed has the complete trade. |
| position.closed | A position was closed completely, by hand, by SL, TP or stop out. Carries the full trade as in Trade history. In the rare case that the close details do not reach us within ten minutes, the event carries what we know and null for the rest. |
| account.balance_changed | The balance changed. Carries balance, previous_balance, change, currency and cause: trade, deposit, withdrawal or correction (anything else the broker booked). Accept further values. When the cause is not known straight away, the event waits for it up to two minutes. |
| account.equity_updated | Sent every equity_interval seconds, carrying all accounts whose balance, equity, margin or floating profit changed since the last one. One request, many accounts: up to 1,000 per request, more are split across several. An account appears once it has sent its first figures. |
Payloads
Every event has the same envelope. id identifies the event and stays the
same on every retry and replay. occurred_at is when the change happened
on the account, as far as we can tell from the broker's data.
{
"id": "evt_01JDQ8M4K7Z2X9R3B6V0N5H8TC",
"type": "position.opened",
"occurred_at": "2026-11-26T06:31:02Z",
"data": {
"account_id": 5120,
"reference": "acc_20931",
"user_ref": "user_8812",
"broker_utc_offset": 7200,
"position": {
"ticket": 88213344,
"symbol": "EURUSD",
"type": "buy",
"volume": 1.00,
"open_time": "2026-11-26T06:31:02Z",
"open_price": 1.08442,
"current_price": 1.08442,
"sl": 1.08100,
"tp": 1.09200,
"profit": 0.00,
"commission": -3.50,
"swap": 0.00
}
}
}
{
"id": "evt_01JDQCV2…",
"type": "position.partially_closed",
"occurred_at": "2026-11-26T08:10:05Z",
"data": {
"account_id": 5120,
"reference": "acc_20931",
"user_ref": "user_8812",
"broker_utc_offset": 7200,
"ticket": 88213344,
"symbol": "EURUSD",
"closed_volume": 0.50,
"remaining_volume": 0.50,
"close_price": 1.08626,
"profit": 92.00,
"commission": -3.50,
"swap": 0.00
}
}
{
"id": "evt_01JDQ9A7…",
"type": "account.status_changed",
"occurred_at": "2026-11-26T09:00:41Z",
"data": {
"account_id": 5122,
"reference": "acc_20933",
"user_ref": "user_9054",
"from": "connecting",
"to": "error",
"reason": "invalid_password",
"message": "The broker rejected the password."
}
}
{
"id": "evt_01JDQD0B…",
"type": "account.equity_updated",
"occurred_at": "2026-11-26T08:14:25Z",
"data": {
"accounts": [
{ "account_id": 5120, "reference": "acc_20931", "balance": 100000.00, "equity": 101245.30,
"margin": 1530.00, "free_margin": 99715.30, "floating_pl": 1245.30,
"equity_low": 101190.10, "at": "2026-11-26T08:14:24Z" },
{ "account_id": 5131, "reference": "acc_21007", "balance": 25000.00, "equity": 24712.85,
"margin": 880.00, "free_margin": 23832.85, "floating_pl": -287.15,
"equity_low": 24655.40, "at": "2026-11-26T08:14:25Z" }
]
}
}
equity_low is the lowest equity since the previous delivery for that
account, so a short dip between two deliveries is not lost. Equity is sampled
four times a second on every account.
Equity updates are not retried: an old figure delivered late helps nobody, and the next delivery carries the current ones. Accounts that did not reach you are included again in the next delivery.
Delivery and verification
POST /hooks/copysync HTTP/1.1
Content-Type: application/json
User-Agent: CopySync-Webhooks/1
X-CopySync-Event: position.opened
X-CopySync-Event-Id: evt_01JDQ8M4K7Z2X9R3B6V0N5H8TC
X-CopySync-Delivery: 9f2c4a10-3e77-4a1b-b0d2-5c8e1f7a9b40
X-CopySync-Timestamp: 1795681862
X-CopySync-Signature: sha256=4f8c2e…
{ …event as above… }
X-CopySync-Signature is sha256= followed by the hex
HMAC-SHA256 of timestamp + "." + raw_body, keyed with your webhook
secret. X-CopySync-Event-Id equals the event's id and is
the same on every attempt; X-CopySync-Delivery is new on every attempt.
const crypto = require('crypto'); app.post('/hooks/copysync', express.raw({ type: 'application/json' }), // raw, not json() (req, res) => { const ts = req.get('X-CopySync-Timestamp'); const sig = req.get('X-CopySync-Signature') || ''; // Reject anything older than five minutes — stops replayed requests. if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) { return res.sendStatus(400); } const expected = 'sha256=' + crypto .createHmac('sha256', process.env.CS_WEBHOOK_SECRET) .update(ts + '.' + req.body) // req.body is a Buffer .digest('hex'); // Constant-time comparison; lengths must match first. const a = Buffer.from(sig), b = Buffer.from(expected); if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) { return res.sendStatus(401); } res.sendStatus(200); // acknowledge first… enqueue(JSON.parse(req.body)); // …then do the work });
Verify against the raw bytes: parsing and re-serialising the JSON changes them and the signature will not match. Compare in constant time. Acknowledge before working, because we time out.
| Property | Behaviour |
|---|---|
| Speed | Events are sent within a few seconds of the change reaching us, one request per event — except account.equity_updated, which is sent on its interval. |
| Timeout | 10 seconds for your response headers. |
| Success | Any 2xx. The response body is ignored. |
| Retries | Six retries with growing delays, about 21 hours in total: after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours. After that, use replay. |
| Duplicates | Delivery is at least once. Deduplicate on the event id. |
| Ordering | Events for one account are sent in the order they occurred, but a retry can arrive after a later event. Order by occurred_at, and treat a position.closed as final even if a position.modified for the same ticket arrives afterwards. |
| Auto-disable | An endpoint failing continuously for 72 hours is disabled and we notify your technical contact by email. Events keep being stored for replay. Switch it back on with PATCH /webhooks/{id} and {"active": true}, then fill the gap with replay or GET /events: nothing from the time it was failing or off is sent by itself. If you switch an endpoint off yourself, deliveries already queued wait and go out once it is on again, but events that occur while it is off are not queued for it. |
Replay
Every event except account.equity_updated is stored for
7 days. If your endpoint was down, or you want to rebuild from a
point in time, you can fetch the events yourself or have us send them again. Equity
updates are not stored as events; use
equity history to fill those gaps.
Times here (since, until) refer to when we
recorded an event, which is when it went out to your endpoints.
occurred_at can be earlier: a position opened while the account was
disconnected is recorded when it reconnects. So a window starting when your endpoint
went down catches everything it missed.
| Query parameter | Type | Description |
|---|---|---|
| after | string | An event id. Returns only events recorded after it: pass the last id you processed. An id older than 7 days is refused with 422; use since then. |
| since | timestamp | Alternative to after: events recorded at or after this time. Send one or the other, not both. |
| types | string | Comma-separated event types. |
| account_id | integer | Only events of this account, also after it was deleted. |
| limit | integer | 1–500, default 100. |
| cursor | string | From the previous page. |
{
"data": [
{
"id": "evt_01JDQ8M4K7Z2X9R3B6V0N5H8TC",
"type": "position.closed",
"occurred_at": "2026-11-26T02:14:09Z",
"data": { … }
}
],
"has_more": false,
"next_cursor": null
}
When has_more is false you have everything up to now.
To keep reading later, continue with after set to the last
id you received.
{
"since": "2026-11-26T02:00:00Z",
"until": "2026-11-26T06:30:00Z",
"types": ["position.closed", "account.status_changed"]
}
{
"replay_id": "rpl_31",
"events": 1842
}
since is required. until defaults to now and
types to every type the endpoint subscribes to; types it does not
subscribe to are refused. events is the number of events queued.
Because replayed events keep their ids, the deduplication you already do makes a
generous time window safe.
- A replay runs alongside live deliveries and never holds them up, so replayed events can arrive between new ones. Failed deliveries are retried like any other.
- One replay per endpoint at a time: starting a new one stops the replay still running and sends the new window instead.
- Up to 50,000 events per replay; a larger window is refused
with
422. For more, read them withGET /events, which is also faster. - A window without events answers
"events": 0and sends nothing. - The endpoint has to be switched on; a disabled one returns
409 invalid_state.
Errors
Every error is one object with a stable code. Branch on the code, never
on message.
{
"error": {
"code": "validation_failed",
"message": "platform must be MT4 or MT5",
"field": "platform",
"request_id": "req_8f21c4a9"
}
}
request_id is on every error and in the X-Request-Id header
of every response. Log it; quoting it to us turns a report into a quick lookup.
| HTTP | code | Meaning | Retry? |
|---|---|---|---|
| 400 | malformed_request | Body is not valid JSON, or a header is unusable. | no |
| 401 | unauthorized | Missing, unknown or revoked key. | no |
| 403 | ip_not_allowed | The request came from an address not on the key's allowlist. | no |
| 403 | account_limit_reached | Your key holds the agreed maximum number of accounts; details.limit names it. Contact us to raise it. | no |
| 404 | not_found | No such resource under your key. | no |
| 409 | duplicate_account | This login on this server already exists; details.account_id names it. | no |
| 409 | duplicate_reference | Another of your accounts already carries this reference; details.account_id names it. | no |
| 409 | invalid_state | Not possible in the current state, e.g. new credentials while the account is being set up or deleted, or a replay to a disabled endpoint. | later |
| 409 | idempotency_key_reused | Same idempotency key, different body. | no |
| 409 | webhook_limit_reached | Five webhook endpoints are registered already. Delete one first. | no |
| 409 | idempotency_key_in_progress | The first request with this key is still running. | yes |
| 422 | validation_failed | A field is missing, malformed or out of range; field names it. | no |
| 429 | rate_limited | Rate limit reached. See Retry-After. | yes |
| 500 | internal_error | On our side. Safe to retry with the same idempotency key. | yes |
| 503 | service_unavailable | Maintenance or overload. Retry-After is set. | yes |
Retry the ones marked yes with growing delays and some randomness. A
500 on a POST leaves it unclear whether the write
happened; repeating it with the same idempotency
key settles that without creating a duplicate.
Integration recipe
- Register your webhook first. Events for an account start the moment it is created; an endpoint registered afterwards misses them.
- Create the account with your
referenceanduser_ref, thehistorymode your user chose, and anIdempotency-Key. - Show “connecting” until
account.status_changedarrives. Onconnectedthe account is live. Onerror, show the reason in plain words and, for a wrong password, login or server, let your user correct it; send the correction withPUT …/credentials. - Keep your view current from events.
position.*for trades,account.balance_changedfor balance,account.equity_updatedfor equity, margin and floating profit. - Reconcile. On startup, and every few minutes, call
GET /positionsandGET /accountsand correct your state. After downtime on your side, fetchGET /events?after=<last id>first. - Alert on state, not on silence. A quiet account is usually an
account without trades.
disconnectedanderrorare already confirmed and can go straight to your users. - Delete accounts your users remove, so they stop counting towards your account total.
Before you go live
- Run the whole flow on demo accounts first, on both MT4 and MT5. Every endpoint behaves the same; only the money is not real.
- Create an account with a wrong password and one with a misspelled server, and check that your interface shows both as something your user can fix.
- Connect one account with an investor password and one with a master password, and compare what you receive.
- Partially close a position on MT4 and on MT5. On MT4 the broker gives the remainder a new ticket; we keep reporting the original one, so check that your interface shows one trade with two closes.
- Stop your webhook endpoint for an hour, bring it back, and recover with
GET /eventsor a replay. - Create one account with full history on an account with a long
trading record, and check how your interface looks while it is
importing.
Support
Your technical contact is reachable at
support@copysync.net. Include
the request_id or event id when you report something
specific. If a field or event does not fit your product, tell us; this API is built
for you and can be extended.
Base URL https://tradeacademy.copysync.net/api/v2/ · Last updated 3 December 2026