Create a Sandbox account
Register in the Sandbox Toolbox, then add an API client — a client id and secret. Free: no billing, no SLA.
Create an account →Register your trade server
You need your own MT4/MT5 server and a manager login with the rights you need. Allow the Sandbox address 88.99.65.181 in the server firewall, then add the server in Toolbox.
Open the Sandbox Toolbox ↗·Firewall settings ↗# The Sandbox — free, no billing. For Production comment out these two lines,
# uncomment the two below and use a client created in toolbox.cplugin.com.
$Api = 'https://pre.mywebapi.com'
$Auth = 'https://pre.auth.cplugin.net'
# $Api = 'https://cloud.mywebapi.com'
# $Auth = 'https://auth.cplugin.net'
# 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 "$Auth/connect/token" -Body $body).access_token
$headers = @{ Authorization = "Bearer $token" }
# 2. Take the first trade platform registered in your workspace
$ID = (Invoke-RestMethod -Headers $headers -Uri "$Api/api/TradePlatforms")[0].id
Write-Host "Platform id: $ID"
# 3. Ping it
Invoke-RestMethod -Headers $headers -Uri "$Api/api/TradePlatforms/$ID/Ping"# The Sandbox — free, no billing. For Production comment out these two lines,
# uncomment the two below and use a client created in toolbox.cplugin.com.
API=https://pre.mywebapi.com
AUTH=https://pre.auth.cplugin.net
# API=https://cloud.mywebapi.com
# AUTH=https://auth.cplugin.net
# 1. OAuth Client Credentials → Bearer JWT
TOKEN=$(curl -s -X POST "$AUTH/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. Take the first trade platform registered in your workspace
ID=$(curl -s -H "Authorization: Bearer $TOKEN" "$API/api/TradePlatforms" | jq -r '.[0].id')
echo "Platform id: $ID"
# 3. Ping it
curl -H "Authorization: Bearer $TOKEN" "$API/api/TradePlatforms/$ID/Ping"# The Sandbox — free, no billing. For Production comment out these two lines,
# uncomment the two below and use a client created in toolbox.cplugin.com.
API=https://pre.mywebapi.com
AUTH=https://pre.auth.cplugin.net
# API=https://cloud.mywebapi.com
# AUTH=https://auth.cplugin.net
# 1. OAuth Client Credentials → Bearer JWT
TOKEN=$(curl -s -X POST "$AUTH/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. Take the first trade platform registered in your workspace
ID=$(curl -s -H "Authorization: Bearer $TOKEN" "$API/api/TradePlatforms" | jq -r '.[0].id')
echo "Platform id: $ID"
# 3. Ping it
curl -H "Authorization: Bearer $TOKEN" "$API/api/TradePlatforms/$ID/Ping"import { CPluginWebApiClient } from '@mywebapi.com/sdk';
const client = new CPluginWebApiClient({
// The Sandbox (free). Production: env 'prod' and a client created in toolbox.cplugin.com
env: 'staging',
clientId: process.env.CPLUGIN_WEBAPI_CLIENT_ID!,
clientSecret: process.env.CPLUGIN_WEBAPI_CLIENT_SECRET!,
}); // the token is fetched, cached and refreshed for you
// The first trade platform registered in your workspace
const [platform] = await client.listTradePlatforms();
const time = platform.type === 'MT5'
? await client.mt5.getTimeServer(platform.id)
: await client.mt4.getServerTime(platform.id);
console.log(platform.name, 'server time:', time);using CPlugin.SaaSWebApi.Client;
// The Sandbox (free). Production: CPluginEnvironment.Prod and a client created in toolbox.cplugin.com.
// The token is fetched, cached and refreshed for you.
using var client = new CPluginWebApiClient(CPluginEnvironment.Staging,
Environment.GetEnvironmentVariable("CPLUGIN_WEBAPI_CLIENT_ID")!,
Environment.GetEnvironmentVariable("CPLUGIN_WEBAPI_CLIENT_SECRET")!);
// The first trade platform registered in your workspace
var platform = (await client.ListTradePlatformsAsync())[0]!;
var id = Guid.Parse(platform["id"]!.GetValue<string>());
var time = platform["type"]?.ToString() == "MT5"
? await client.MT5(id).TimeServerAsync()
: await client.MT4(id).ServerTimeAsync();
Console.WriteLine($"{platform["name"]} server time: {time}");# The Sandbox (free). Production: -Environment Production and a client created in toolbox.cplugin.com.
# The token is fetched, cached and refreshed for you.
$secret = ConvertTo-SecureString $env:CPLUGIN_WEBAPI_CLIENT_SECRET -AsPlainText -Force
$session = Connect-MyWebApi -Environment Staging `
-ClientId $env:CPLUGIN_WEBAPI_CLIENT_ID -ClientSecret $secret
# The first trade platform registered in your workspace
$platform = @(Get-MyWebApiTradePlatform -Connection $session)[0]
if ($platform.type -eq 'MT5') {
Get-MT5TimeServer -Connection $session -TradePlatform $platform.id
} else {
Get-MT4ServerTime -Connection $session -TradePlatform $platform.id
}import os
from cplugin_webapi_sdk import CPluginWebApiClient
# The Sandbox (free). Production: env="prod" and a client created in toolbox.cplugin.com.
# The token is fetched, cached and refreshed for you.
with CPluginWebApiClient(env="staging",
client_id=os.environ["CPLUGIN_WEBAPI_CLIENT_ID"],
client_secret=os.environ["CPLUGIN_WEBAPI_CLIENT_SECRET"]) as client:
# The first trade platform registered in your workspace
platform = client.list_trade_platforms()[0]
api = client.mt5 if platform["type"] == "MT5" else client.mt4
print(platform["name"], "server time:", api.get_server_time(platform["id"]))Live quotes in a few lines
Streaming has been part of WebAPI since API v1. With v2, the SDKs do the plumbing: one call opens the stream with the credentials you use for REST, and quotes, trades and margin calls arrive as a stream you simply loop over.
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!,
});
// client.realtime.mt5(…) for an MT5 platform
const rt = client.realtime.mt4('<paste the id of a platform here>');
await rt.start();
for await (const tick of rt.streamTicks('EURUSD')) {
console.log(tick.symbol, tick.bid, tick.ask);
}using CPlugin.SaaSWebApi.Client;
using var client = new CPluginWebApiClient(CPluginEnvironment.Prod,
Environment.GetEnvironmentVariable("CPLUGIN_WEBAPI_CLIENT_ID")!,
Environment.GetEnvironmentVariable("CPLUGIN_WEBAPI_CLIENT_SECRET")!);
// client.Realtime.MT5(…) for an MT5 platform
await using var hub = client.Realtime.MT4(Guid.Parse("<paste the id of a platform here>"));
await hub.StartAsync();
await hub.SubscribeToTicksAsync("EURUSD");
await foreach (var tick in hub.StreamTicksAsync("EURUSD"))
Console.WriteLine($"{tick.Symbol} bid={tick.Bid} ask={tick.Ask}");$secret = ConvertTo-SecureString $env:CPLUGIN_WEBAPI_CLIENT_SECRET -AsPlainText -Force
$session = Connect-MyWebApi -Environment Production `
-ClientId $env:CPLUGIN_WEBAPI_CLIENT_ID -ClientSecret $secret
$rt = Connect-MT4Realtime -TradePlatform '<paste the id of a platform here>' -Session $session
Register-MT4Realtime -Connection $rt -Category Ticks -Symbol 'EURUSD'
Receive-MT4Realtime -Connection $rt -TimeoutSeconds 10 |
Where-Object Method -eq 'OnTick' |
ForEach-Object { "{0} bid={1}" -f $_.Payload.symbol, $_.Payload.bid }import os
from cplugin_webapi_sdk import CPluginWebApiClient
with CPluginWebApiClient(env="prod",
client_id=os.environ["CPLUGIN_WEBAPI_CLIENT_ID"],
client_secret=os.environ["CPLUGIN_WEBAPI_CLIENT_SECRET"]) as client:
# client.realtime.mt5(…) for an MT5 platform
rt = client.realtime.mt4("<paste the id of a platform here>")
rt.start()
rt.stream_ticks("EURUSD").subscribe({
"next": lambda tick: print(tick),
"complete": lambda: print("done"),
"error": lambda err: print("error:", err),
})
input("Streaming — press Enter to stop\n")
rt.stop()The credentials you already have
The realtime client comes from the same client object as REST and uses its OAuth token — nothing extra to set up.
Streams you loop over
for await in TypeScript, await foreach in .NET, a pipeline in PowerShell. Stop the loop and the subscription ends.
Batched ticks
Ask for one array per symbol every 200 ms (20 ms to 60 s) instead of a message per tick — fewer messages on busy symbols.
Survives a dropped connection
Every SDK reconnects on its own with a fresh token, re-subscribes and keeps your stream loop running — and tells you when it did, so you can catch up on what you missed.
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 REST routes, parameters and response shapes are unchanged apart from a few accepted exceptions; the changes to its realtime hubs and those REST exceptions are listed in the changelog. No deprecation date is set. Paths /api/MT4/…, /api/MT5/…, hubs /hubs/mt4/v1, /hubs/mt5/v1.
API v2
currentThe current version and the larger surface, on the main host and the x86 companion host: 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 apart from a few listed exceptions, 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.
Quotes, margins and trade events stream straight into the SDKs — endpoints /hubs/mt4/v2 and /hubs/mt5/v2.
Four open-source SDKs — TypeScript, .NET, PowerShell, Python — are built on v2 and handle the OAuth token for you: see them run in Step 3 above, and live quotes in Realtime streaming. Full guide: cplugin.com/docs/webapi ↗.
Need the 32-bit MT4 methods?
A handful of MT4 calls need the 32-bit Manager API library, so they run on a separate companion host at the same /api/v2/MT4/{tradePlatform}/… path, with the same OAuth bearer token and the same tradePlatform id. Everything else — MT5, the rest of the MT4 surface, live streaming — stays on the main API.
- ·Messaging — NewsSend, MailSend, MailsRequest
- ·Plugins — PluginsGet, PluginParamGet, PluginUpdate, CfgRequestPlugin, CfgUpdatePlugin
- ·Batch snapshots — UsersSnapshot, UsersSyncRead, TradesSnapshot, TradesSyncRead
- ·Plugin commands — ExternalCommandBinary
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.
No SDK for your language?
Connect to the stream directly. It speaks SignalR, an open protocol over WebSockets — with an automatic fallback where WebSockets are blocked — and client libraries exist for most languages.
Endpoints: cloud.mywebapi.com/hubs/mt4/v2 and cloud.mywebapi.com/hubs/mt5/v2, with the trade platform id in ?tradePlatform= and your access token in signalr_token. API v1 has its own hubs (/hubs/mt4/v1, /hubs/mt5/v1) for existing integrations.
Runnable streaming examples
Complete programs from the open-source SDKs: set the client id and secret, run, and watch live quotes arrive.
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 a WebSocket stream.
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?
The easiest way is an SDK: one call opens a live stream with the credentials you already use for REST — client.realtime.mt4(platformId) in TypeScript, client.Realtime.MT4(platformId) in .NET, Connect-MT4Realtime in PowerShell, client.realtime.mt4(platform_id) in Python. You then loop over what arrives: ticks, batched ticks (one array per symbol, every 200 ms by default) and margin calls on both platforms, trades and account and symbol updates on MT4, deals, orders, positions, accounts and symbols on MT5. The SDKs reconnect on their own and re-subscribe; events during an outage are not replayed, so re-read what you need after a reconnect. Without an SDK, any language connects to the streaming endpoints directly — /hubs/mt4/v2 and /hubs/mt5/v2 (/hubs/mt4/v1 and /hubs/mt5/v1 for API v1). They use SignalR, an open protocol with client libraries for most languages: WebSockets, falling back to Server-Sent Events or long polling where WebSockets are blocked. Every method and event is listed in the realtime guide at cplugin.com/docs/webapi#realtime.
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. Until the platform answers, a repeat with that key is refused with X-Request-Outcome: in-progress (v1: HTTP 409) instead of being executed again. A request that timed out while the platform connection was still being established carries X-Request-Outcome: not-started (v1: HTTP 503) — nothing was sent, so it is safe to repeat.
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 — on the main host and on the x86 companion host — and every SDK is built on it. v1 is legacy — still served, with its REST routes, parameters and response shapes unchanged apart from a few accepted exceptions (the deliberate changes to its realtime hubs — including MT5 enum values that now arrive as names — and those REST exceptions are listed in the changelog) and no deprecation date, for integrations that were written against it. v2 is the larger surface on both platforms, MT4 and MT5; the API reference (mywebapi.com/reference/) counts the operations of each version and platform. 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. The update calls for accounts, groups, symbols, deals and orders, and the PATCH calls, carry only the fields you send; a field you leave out keeps its value on the trade server. Calls that replace a whole table or set of bars (for example a configuration matrix or chart bars) take the full content, as their descriptions state. 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 for integrations already on it (its REST routes, parameters and response shapes stay compatible apart from those listed exceptions).
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.