# 1. OAuth Client Credentials → Bearer JWT
$body = @{
grant_type = 'client_credentials'
scope = 'webapi'
client_id = $env:CPLUGIN_WEBAPI_CLIENT_ID
client_secret = $env:CPLUGIN_WEBAPI_CLIENT_SECRET
}
$token = (Invoke-RestMethod -Method Post -Uri 'https://auth.cplugin.net/connect/token' -Body $body).access_token
# 2. List your trade platforms (one call for v1 and v2) and take an id
Invoke-RestMethod -Headers @{ Authorization = "Bearer $token" } `
-Uri 'https://cloud.mywebapi.com/api/TradePlatforms'
$ID = '<paste the id of a platform here>'
# 3. Ping it
Invoke-RestMethod -Headers @{ Authorization = "Bearer $token" } `
-Uri "https://cloud.mywebapi.com/api/TradePlatforms/$ID/Ping"
# 1. OAuth Client Credentials → Bearer JWT
TOKEN=$(curl -s -X POST https://auth.cplugin.net/connect/token \
-d 'grant_type=client_credentials&scope=webapi' \
-d "client_id=$CPLUGIN_WEBAPI_CLIENT_ID" \
-d "client_secret=$CPLUGIN_WEBAPI_CLIENT_SECRET" \
| jq -r .access_token)
# 2. List your trade platforms (one call for v1 and v2) and take an id
curl -H "Authorization: Bearer $TOKEN" \
https://cloud.mywebapi.com/api/TradePlatforms
ID='<paste the id of a platform here>'
# 3. Ping it
curl -H "Authorization: Bearer $TOKEN" \
https://cloud.mywebapi.com/api/TradePlatforms/$ID/Ping
# 1. OAuth Client Credentials → Bearer JWT
TOKEN=$(curl -s -X POST https://auth.cplugin.net/connect/token \
-d 'grant_type=client_credentials&scope=webapi' \
-d "client_id=$CPLUGIN_WEBAPI_CLIENT_ID" \
-d "client_secret=$CPLUGIN_WEBAPI_CLIENT_SECRET" \
| jq -r .access_token)
# 2. List your trade platforms (one call for v1 and v2) and take an id
curl -H "Authorization: Bearer $TOKEN" \
https://cloud.mywebapi.com/api/TradePlatforms
ID='<paste the id of a platform here>'
# 3. Ping it
curl -H "Authorization: Bearer $TOKEN" \
https://cloud.mywebapi.com/api/TradePlatforms/$ID/Ping
Two API versions, one reference each
Every operation served by the main host, for both versions, grouped by platform and tag: organizations and trade platforms first, then the platform calls. Both versions run side by side on the same hosts, with the same token; the same references apply to Production and Sandbox.
API v1
legacyThe previous version, still served for integrations written against it: its routes, parameters and response shapes are unchanged, and no deprecation date is set. Paths /api/MT4/…, /api/MT5/…, hubs /hubs/mt4/v1, /hubs/mt5/v1.
API v2
currentThe current version: 443 operations on the main host and 13 on the companion host, in the path, one answer format for each call, SDKs for TypeScript, .NET, PowerShell and Python. Paths /api/v2/…, hubs /hubs/mt4/v2, /hubs/mt5/v2.
Guides — authentication, timeouts, idempotency, realtime: cplugin.com/docs/webapi ↗ · What is new in v2
HTML API reference — every operation with parameters, schemas and curl examples · OpenAPI JSON: v1, v2 · llms.txt
Swagger UI stays available alongside the HTML reference and Redoc. · Connectivity test calls (API v0.1, no token needed) ↗
Meet the v2 API
A larger, cleaner endpoint surface, live in production and in the Sandbox. v2 puts the version in the path — call
/api/v2/…
directly, no query string — and answers every call in the same envelope, so one parser serves all of them. v1 stays
legacy: its routes, parameters and response shapes are unchanged, and no deprecation date is set; migrate at your own pace.
Call /api/v2/… directly — no api-version query parameter to remember.
Every call answers the same envelope: { data, error, meta }, with the error code in the body.
Hubs /hubs/mt4/v2 and /hubs/mt5/v2 stream ticks, margins and trade events.
Before you start: create an API client and register your trade server in Toolbox (the guide takes you through both). The examples read the client id and secret from CPLUGIN_WEBAPI_CLIENT_ID and CPLUGIN_WEBAPI_CLIENT_SECRET; tradePlatformId is the id from the list in step 2.
import { CPluginWebApiClient } from '@mywebapi.com/sdk';
const client = new CPluginWebApiClient({
env: 'prod', // or 'staging' for the Sandbox
clientId: process.env.CPLUGIN_WEBAPI_CLIENT_ID!,
clientSecret: process.env.CPLUGIN_WEBAPI_CLIENT_SECRET!,
});
const tradePlatformId = '<paste the id of a platform here>'; // from GET /api/TradePlatforms
const time = await client.mt4.getServerTime(tradePlatformId);
using CPlugin.SaaSWebApi.Client;
var clientId = Environment.GetEnvironmentVariable("CPLUGIN_WEBAPI_CLIENT_ID")!;
var clientSecret = Environment.GetEnvironmentVariable("CPLUGIN_WEBAPI_CLIENT_SECRET")!;
var tradePlatformId = Guid.Parse("<paste the id of a platform here>"); // from GET /api/TradePlatforms
using var client = new CPluginWebApiClient(CPluginEnvironment.Prod, clientId, clientSecret);
var mt4 = client.MT4(tradePlatformId);
var time = await mt4.ServerTimeAsync();
$secret = ConvertTo-SecureString $env:CPLUGIN_WEBAPI_CLIENT_SECRET -AsPlainText -Force
$session = Connect-MyWebApi -Environment Production `
-ClientId $env:CPLUGIN_WEBAPI_CLIENT_ID -ClientSecret $secret
$tradePlatformId = '<paste the id of a platform here>' # from GET /api/TradePlatforms
Get-MT4ServerTime -Connection $session -TradePlatform $tradePlatformId
import os
from cplugin_webapi_sdk import CPluginWebApiClient
client_id = os.environ["CPLUGIN_WEBAPI_CLIENT_ID"]
client_secret = os.environ["CPLUGIN_WEBAPI_CLIENT_SECRET"]
trade_platform_id = "<paste the id of a platform here>" # from GET /api/TradePlatforms
with CPluginWebApiClient(env="prod", client_id=client_id, client_secret=client_secret) as client:
time = client.mt4.get_server_time(trade_platform_id)
Two environments, one API
Same surface, same OAuth flow, just different hosts. Sandbox is fully separated — no billing, no SLA, safe to break.
- REST cloud.mywebapi.com
- Auth auth.cplugin.net
- Hub /hubs/mt4/v1 · /hubs/mt4/v2 · /hubs/mt5/v1 · /hubs/mt5/v2
- Manage toolbox.cplugin.com
Multi-region cloud — instances in several data centres, a DNS traffic manager routes to the nearest one. Your pricing in Toolbox ↗
- REST pre.mywebapi.com
- Auth pre.auth.cplugin.net
- Hub /hubs/mt4/v1 · /hubs/mt4/v2 · /hubs/mt5/v1 · /hubs/mt5/v2
- Manage pre.toolbox.cplugin.com
Fully separated environment with its own Toolbox for client and MT4 / MT5 connection management. No charges, no SLA, may be reset without notice. Use for integration testing before pointing at Production.
Realtime over SignalR
Hubs /hubs/mt4/v1, /hubs/mt5/v1 for API v1 and /hubs/mt4/v2, /hubs/mt5/v2 for API v2. Subscribe to ticks, margins and trade events on every hub: on v2 the trade platform is bound at connect (?tradePlatform), and MT5 ticks arrive as an OnTick subscription or a StreamTicks stream. Ticks can also be batched: subscribe with SubscribeToTicksBatch and receive them as one array in OnTicksBatch — 200 ms or 200 ticks by default. WebSockets / Long Polling / SSE — same code path. Auto-reconnect, bearer auth, typed contracts.
Working examples — SignalR, API v1 hubs
Full source for download. Plug in your credentials, run, ship.
Questions about the MT4 / MT5 API
What is CPlugin WebAPI?
A hosted REST JSON API over the MT4 and MT5 Manager API. Your application manages accounts, trades, groups and symbols on MetaTrader 4 and 5 servers from any language that speaks HTTP, and receives quotes, margin and trade events in realtime over SignalR.
Do I need to install anything on my MT4 or MT5 server?
No. WebAPI connects to your trade server with a regular manager account, the same way the MetaTrader Manager terminal does. You register the server address and the manager credentials once in Toolbox; no server plugin is required.
How do I authenticate?
With OAuth 2.0 client credentials: exchange your client id and secret at auth.cplugin.net for a bearer token and send it in the Authorization header. The SDKs discover, cache and refresh the token for you. Realtime connections pass the same token in the signalr_token query parameter.
Is there a free sandbox?
Yes. The Sandbox at pre.mywebapi.com has the same API surface and the same OAuth flow as Production, with its own Toolbox at pre.toolbox.cplugin.com and its own token server, pre.auth.cplugin.net. Clients and tokens of the two environments are separate: a token issued by one is refused with 401 by the other. It is free, has no SLA and may be reset without notice, so use it for integration testing.
How do I receive realtime quotes and trade events?
Connect to the SignalR hub that matches your platform and API version: /hubs/mt4/v1 and /hubs/mt4/v2, /hubs/mt5/v1 and /hubs/mt5/v2, and subscribe to the events you need. All four hubs deliver live ticks: on v2 you bind the trade platform when you connect (?tradePlatform=<guid>), on v1 you pass it in each call. On the MT5 v2 hub you either subscribe per symbol and receive OnTick, or consume the StreamTicks stream; all four hubs also carry margin call updates. Ticks can also be received in batches: subscribe with SubscribeToTicksBatch({ tradePlatform, symbol, intervalMs?, maxBatchSize? }) on the v1 hubs or SubscribeToTicksBatch(symbol, intervalMs?, maxBatchSize?) on the v2 hubs, and the ticks of one symbol arrive as one array in the OnTicksBatch event ({ tradePlatform, symbol, ticks } on v1, { symbol, ticks } on v2), every 200 ms or 200 ticks by default — intervalMs accepts 20 to 60000 ms and maxBatchSize 1 to 10000. A batched subscriber receives no per-tick OnTick; UnsubscribeFromTicksBatch takes the same arguments as the subscribe call on the v1 hubs and only the symbol on the v2 hubs, and batching trades latency for traffic. SignalR uses WebSockets and falls back to Server-Sent Events or long polling, with the same client code.
What happens if the trading platform does not answer in time?
Every trade-platform request has a deadline, which you can set per request with the X-Request-Timeout header (1 to 300 seconds). A read that timed out changed nothing and is safe to repeat. A trade that timed out may still be completed by the platform: you get error.code = OutcomeUnknown (v1: HTTP 504 with the header X-Request-Outcome: unknown), and repeating it with the same Idempotency-Key returns its real result once the platform has answered, without executing it twice.
Which SDKs are available?
Open-source SDKs for TypeScript (npm @mywebapi.com/sdk), .NET (NuGet MyWebApi.Sdk), PowerShell (module MyWebApi) and Python (pip mywebapi-sdk). Any other language works over plain HTTP, using the OpenAPI references.
Should I use API v1 or v2?
v2 is the current version: it carries the larger surface — 443 operations on the main host and 13 on the companion host — and every SDK is built on it. v1 is legacy — still served, with its routes, parameters and response shapes unchanged and no deprecation date, for integrations that were written against it. v2 is the larger surface on both platforms: 162 MT4 operations on the main host (plus 13 on the companion host) against 42 in v1, and 281 MT5 operations against 55 in v1. It includes far more than the calls v1 exposed: accounts, groups and symbols with their configurations, orders, deals and positions with their history, charts and ticks, subscriptions, reports, client documents and comments, mail and news, the dealer queue with profit and margin calculations, and writes into the price database. Most update requests (the <code>…Update</code> and <code>PATCH</code> calls) carry only the fields you send; <code>AdmTradeRecordModify</code> is the exception and takes all nine editable fields. Both versions run side by side on the same hosts with the same token, so you can migrate one call at a time, and v1 keeps working unchanged for integrations already on it.
How is WebAPI priced?
The Sandbox is free. Production: €49 per month for each trading platform you use in that month, which includes API and streaming usage up to that amount; usage above it is billed by volume, post-paid. A month with no calls on a platform costs nothing — no prepayment, no minimum commitment. Your current rates are shown on the pricing page in Toolbox.