# CPlugin WebAPI > CPlugin WebAPI is a hosted REST JSON and SignalR (WebSocket) API over the MetaTrader 4 (MT4) and MetaTrader 5 (MT5) Manager API. A broker's application manages accounts, trades, groups and symbols on its MT4 and MT5 servers from any language that speaks HTTP, and receives quotes, margin and trade events in realtime. - Publisher: CPlugin (CPlugin Labs LP), https://cplugin.com — contact: info@cplugin.com - Website: https://mywebapi.com - Platforms: MetaTrader 4 and MetaTrader 5 trade servers. WebAPI connects to the trade server with a regular manager account, the same way the MetaTrader Manager terminal does; no server plugin is required. The server and the manager credentials are registered once in Toolbox. - Authentication: OAuth 2.0 client credentials. Exchange the client id and secret at https://auth.cplugin.net/connect/token (grant_type=client_credentials, scope=webapi) for a bearer token and send it as `Authorization: Bearer `. Realtime connections pass the same token in the `signalr_token` query parameter. The SDKs obtain, cache and refresh the token themselves. - Errors in v2: every call that reaches an operation answers HTTP 200 with the envelope `{ data, error, meta }` (except a reused `Idempotency-Key` with other parameters, which answers 422). On success `error` is null; on failure `data` is null and `error.code` says why (Validation, NoConnect, MT4Error, MT5Error, NotFound, Timeout, OutcomeUnknown, Busy, Internal), with the platform result code in `error.managerCode` on MT4 or in `error.message` on MT5. Transport failures use real codes: 401 for a missing, expired or foreign token, 403 when the API client lacks the permission, 404 for an unknown path, 400 when the request cannot be read, 422 when an `Idempotency-Key` is reused with a different query string or body, 500 for an unexpected failure, 502/503/504 from the proxy. A `Busy` refusal of an isolated platform carries a `Retry-After` header in seconds. - Errors in v1: HTTP codes instead. 504 with `X-Request-Outcome: timeout` (a read did not answer, safe to repeat) or `unknown` (a trade may still be applied); 503 with `not-started` (nothing was sent: too many calls wait for the platform, or the idempotency key could not be recorded) or when the platform is unavailable or isolated — an isolated platform answers at once with `Retry-After` in seconds; 409 with `in-progress` (the same Idempotency-Key is still running); 400 for an invalid X-Request-Timeout. - Permissions: granted to the API client in Toolbox per resource (accounts, orders and deals, symbols, groups, settings, sensitive settings) and action (Create, Request, Update, Delete); a call without the grant answers HTTP 403. Grants are written into the token at issue, so request a new token after changing them. - Production: REST base URL https://cloud.mywebapi.com, token server https://auth.cplugin.net, management portal https://toolbox.cplugin.com. Multi-region cloud. - Sandbox: REST base URL https://pre.mywebapi.com, token server https://pre.auth.cplugin.net, management portal https://pre.toolbox.cplugin.com. Same API surface and OAuth flow as Production, but its own API clients and its own tokens: a token issued by one environment is refused with 401 by the other. Free, no SLA, may be reset without notice — for integration testing. - API v2 (current): 442 operations — MT4 162, MT5 280. Paths `/api/v2/…`. - API v1 (legacy): 101 operations — General 4, MT4 42, MT5 55. Paths `/api/MT4/…, /api/MT5/…`. - Versions run side by side on the same hosts with the same token, so an integration can move from v1 to v2 one call at a time. Each platform connection keeps a cached copy of the trade server state that it refreshes continuously, so `…Get` calls are cached reads and `…Request` calls are live. v2 is the current version with the larger surface (442 operations on the main host and 13 on the companion host, against 101 in v1); v1 is legacy — still served, with its REST routes, parameters and response shapes unchanged and no deprecation date, while the deliberate changes to its realtime hubs (a connection ending with its token, subscription limits, case-insensitive symbol names, the 25-second `Connect` wait, per-subscription tick batches, MT5 enum values arriving as names and the removal of events the hub never sent) are listed in the changelog; every SDK is built on v2. - Realtime: SignalR hubs /hubs/mt4/v1, /hubs/mt4/v2, /hubs/mt5/v1 and /hubs/mt5/v2, all of them delivering live ticks. On the v2 hubs the trade platform is bound when you connect (`?tradePlatform=`); on the v1 hubs it is the argument of each call. On the MT5 v2 hub both tick models are available: `SubscribeToTicks(symbol)` with the `OnTick` event, and the `StreamTicks(symbol?)` stream. All four hubs also carry margin call updates. A connection may hold at most 500 symbol subscriptions; symbol names are matched case-insensitively and a name longer than 64 characters is refused. 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 server sends the ticks of one symbol as one array in the `OnTicksBatch` event — `{ tradePlatform, symbol, ticks }` on v1 and `{ symbol, ticks }` on v2. Each subscription follows its own interval and batch size; a batch goes out when its oldest tick has waited `intervalMs` (checked about every 50 ms), or at once at `maxBatchSize`, with 200 ms and 200 ticks as the defaults (accepted: 20 to 60000 ms and 1 to 10000 ticks); a batched subscriber gets no per-tick `OnTick`, and `UnsubscribeFromTicksBatch` takes the same arguments as the subscribe call on the v1 hubs and only the symbol on the v2 hubs. Batching is about traffic, not latency: the per-tick subscription remains the lowest-latency option. SignalR uses WebSockets and falls back to Server-Sent Events or long polling. - Deadlines and retries: every trade-platform request has a deadline, adjustable 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: on v2 the answer is `error.code` = OutcomeUnknown (on v1, HTTP 504 with the header `X-Request-Outcome`), and repeating it with the same `Idempotency-Key` returns its real result once the platform has answered, without executing it twice. - Pricing: 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. The customer's current rates are shown on the pricing page in Toolbox: https://toolbox.cplugin.com/webapi/pricing - Deployment: a hosted cloud service, with instances in several data centres and DNS routing to the nearest one. ## API reference - [HTML API reference](https://cloud.mywebapi.com/reference/): every operation by platform and tag, with parameters, schemas and curl examples; plain HTML, no JavaScript needed - [API v2 reference (current)](https://cloud.mywebapi.com/reference/v2/): 442 operations — MT4 162, MT5 280 - [API v1 reference (legacy)](https://cloud.mywebapi.com/reference/v1/): 101 operations — General 4, MT4 42, MT5 55 - [OpenAPI v2 specification (JSON)](https://cloud.mywebapi.com/swagger/v2/swagger.json): OpenAPI 3.0, 442 operations - [OpenAPI v1 specification (JSON)](https://cloud.mywebapi.com/swagger/v1/swagger.json): OpenAPI 3.0, 101 operations - [Complete operation list](https://cloud.mywebapi.com/llms-full.txt): every operation of both versions in one Markdown file ## SDKs Open source; each handles the OAuth token for you and works against Production or the Sandbox. - [TypeScript / JavaScript — npm `@mywebapi.com/sdk`](https://www.npmjs.com/package/@mywebapi.com/sdk): `npm i @mywebapi.com/sdk` - [Python — PyPI `mywebapi-sdk`](https://pypi.org/project/mywebapi-sdk/): `pip install mywebapi-sdk` - [.NET — NuGet `MyWebApi.Sdk`](https://www.nuget.org/packages/MyWebApi.Sdk): `dotnet add package MyWebApi.Sdk` - [PowerShell — PowerShell Gallery `MyWebApi`](https://www.powershellgallery.com/packages/MyWebApi): `Install-Module MyWebApi` ## Docs - [Guides](https://cplugin.com/docs/webapi): authentication, timeouts, idempotency, realtime - [Changelog](https://cloud.mywebapi.com/History): new endpoints and changes, newest first - [Interactive API v2 reference (Redoc)](https://cloud.mywebapi.com/redoc_v2/index.html): the same specification, rendered in the browser - [Interactive API v1 reference (Redoc)](https://cloud.mywebapi.com/redoc_v1/index.html): the same specification, rendered in the browser ## Optional - [MT4 v2 :: Account passwords (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-account-passwords/): 2 operations - [MT4 v2 :: Backup (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-backup/): 4 operations - [MT4 v2 :: Backup (destructive) (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-backup-destructive/): 2 operations - [MT4 v2 :: Common (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-common/): 4 operations - [MT4 v2 :: Config (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-config/): 51 operations - [MT4 v2 :: Dealer (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-dealer/): 10 operations - [MT4 v2 :: Groups (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-groups/): 9 operations - [MT4 v2 :: History (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-history/): 1 operation - [MT4 v2 :: Mail (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-mail/): 1 operation - [MT4 v2 :: Margins (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-margins/): 3 operations - [MT4 v2 :: News (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-news/): 5 operations - [MT4 v2 :: Online (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-online/): 2 operations - [MT4 v2 :: Plugins (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-plugins/): 1 operation - [MT4 v2 :: Prices (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-prices/): 8 operations - [MT4 v2 :: Reports (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-reports/): 6 operations - [MT4 v2 :: Server Admin (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-server-admin/): 4 operations - [MT4 v2 :: Server Admin (destructive) (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-server-admin-destructive/): 4 operations - [MT4 v2 :: Symbols (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-symbols/): 15 operations - [MT4 v2 :: Trades (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-trades/): 16 operations - [MT4 v2 :: Users (API v2)](https://cloud.mywebapi.com/reference/v2/mt4-users/): 14 operations - [MT5 v2 :: Clients (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-clients/): 42 operations - [MT5 v2 :: Common (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-common/): 2 operations - [MT5 v2 :: Communications (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-communications/): 26 operations - [MT5 v2 :: Config (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-config/): 2 operations - [MT5 v2 :: Configuration (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-configuration/): 11 operations - [MT5 v2 :: Dealer (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-dealer/): 3 operations - [MT5 v2 :: Groups (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-groups/): 3 operations - [MT5 v2 :: History Data (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-history-data/): 2 operations - [MT5 v2 :: Managers (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-managers/): 1 operation - [MT5 v2 :: Market Data (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-market-data/): 13 operations - [MT5 v2 :: Market Insight (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-market-insight/): 12 operations - [MT5 v2 :: Reports (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-reports/): 14 operations - [MT5 v2 :: Subscriptions (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-subscriptions/): 28 operations - [MT5 v2 :: Symbols (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-symbols/): 3 operations - [MT5 v2 :: Trade Operations (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-trade-operations/): 14 operations - [MT5 v2 :: Trades (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-trades/): 27 operations - [MT5 v2 :: Trading (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-trading/): 41 operations - [MT5 v2 :: Users (API v2)](https://cloud.mywebapi.com/reference/v2/mt5-users/): 36 operations - [Organizations (API v1)](https://cloud.mywebapi.com/reference/v1/organizations/): 1 operation - [TradePlatforms (API v1)](https://cloud.mywebapi.com/reference/v1/trade-platforms/): 3 operations - [MT4 :: Common (API v1)](https://cloud.mywebapi.com/reference/v1/mt4-common/): 4 operations - [MT4 :: Groups (API v1)](https://cloud.mywebapi.com/reference/v1/mt4-groups/): 5 operations - [MT4 :: Prices (API v1)](https://cloud.mywebapi.com/reference/v1/mt4-prices/): 6 operations - [MT4 :: Symbols (API v1)](https://cloud.mywebapi.com/reference/v1/mt4-symbols/): 7 operations - [MT4 :: Trades (API v1)](https://cloud.mywebapi.com/reference/v1/mt4-trades/): 8 operations - [MT4 :: Users (API v1)](https://cloud.mywebapi.com/reference/v1/mt4-users/): 12 operations - [MT5 :: Clients (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-clients/): 5 operations - [MT5 :: Configuration Databases :: Groups (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-configuration-databases-groups/): 3 operations - [MT5 :: Configuration Databases :: Managers (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-configuration-databases-managers/): 1 operation - [MT5 :: Configuration Databases :: Symbols (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-configuration-databases-symbols/): 3 operations - [MT5 :: Configuration Databases :: Time (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-configuration-databases-time/): 2 operations - [MT5 :: History Data (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-history-data/): 1 operation - [MT5 :: Trade Activity :: Dealing (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-trade-activity-dealing/): 3 operations - [MT5 :: Trade Databases :: Deals (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-trade-databases-deals/): 9 operations - [MT5 :: Trade Databases :: Orders (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-trade-databases-orders/): 12 operations - [MT5 :: Trade Databases :: Positions (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-trade-databases-positions/): 6 operations - [MT5 :: Users (API v1)](https://cloud.mywebapi.com/reference/v1/mt5-users/): 10 operations MetaTrader, MT4, MT5 and MetaQuotes are trademarks or registered trademarks of MetaQuotes Ltd. CPlugin is not affiliated with, endorsed by, or sponsored by MetaQuotes Ltd.