CPlugin

MT5 hub (v2)

MT5 · 18 calls · 14 events · address https://cloud.mywebapi.com/hubs/mt5/v2?tradePlatform=<id>

How to connect, authenticate and reconnect is on the realtime overview. The trade platform is fixed by the connection, so no call takes it as an argument. Send every argument of a call: SignalR does not apply defaults declared on the server, so where a parameter has a default the table names the value to send, and null stands for "all" or "default" where a parameter accepts it. The first event, OnMT5ConnectionStatus, arrives without subscribing.

Contents

Subscriptions

Calls that start or stop a push of events to this connection.

SubscribeToTicks

SubscribeToTicks(symbol)

Subscribe to tick updates of one symbol

After this call the server pushes OnTick to the calling connection for every new tick of symbol on the bound trade platform. Call it once per instrument; several symbols can be subscribed on the same connection.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string — Instrument name as reported by the trade server.

Example

await connection.invoke("SubscribeToTicks", symbol);

UnsubscribeFromTicks

UnsubscribeFromTicks(symbol)

Unsubscribe from a previously subscribed symbol

Stops OnTick pushes for symbol on the calling connection. Subscriptions to other symbols stay in place.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string — Instrument name given to SubscribeToTicks.

Example

await connection.invoke("UnsubscribeFromTicks", symbol);

SubscribeToAllTicks

SubscribeToAllTicks()

Subscribe to tick updates of every symbol on the bound trade platform

After this call the server pushes OnTick to the calling connection for every tick of every instrument on the bound trade platform — the same event and payload as SubscribeToTicks, without a symbol filter. Repeating the call replaces the previous all-symbol subscription; per-symbol subscriptions stay in place and an instrument subscribed both ways is pushed once per subscription. Use UnsubscribeFromAllTicks to stop it.

Permission: Request (read) on symbols

Example

await connection.invoke("SubscribeToAllTicks");

UnsubscribeFromAllTicks

UnsubscribeFromAllTicks()

Unsubscribe from tick updates of all symbols

Stops the all-symbol OnTick pushes started by SubscribeToAllTicks. Per-symbol subscriptions stay in place; calling it with no active all-symbol subscription does nothing.

Permission: Request (read) on symbols

Example

await connection.invoke("UnsubscribeFromAllTicks");

SubscribeToTicksBatch

SubscribeToTicksBatch(symbol, intervalMs, maxBatchSize)

Subscribe to tick updates of one symbol as batches

The server accumulates the ticks of symbol and sends them as one OnTicksBatch event once the oldest buffered tick has waited intervalMs milliseconds, or as soon as maxBatchSize ticks are buffered. The timer checks about every 50 ms, so a shorter interval behaves as 50 ms. Each batch is sent to the calling connection only, so it receives no per-tick OnTick events for the symbol; SubscribeToTicks remains the lowest-latency option. Subscribing twice to the same symbol replaces the previous subscription, so a new interval and batch size take effect.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string — Instrument name as reported by the trade server.
intervalMs integer 200 Upper bound on how long a tick waits for its batch, in milliseconds; 20 to 60000. Send 200 for the default.
maxBatchSize integer 200 Upper bound on ticks per event; 1 to 10000. Send 200 for the default. Reaching it sends the batch at once.

Example

await connection.invoke("SubscribeToTicksBatch", symbol, 200, 200);

UnsubscribeFromTicksBatch

UnsubscribeFromTicksBatch(symbol)

Unsubscribe from batched tick updates of one symbol

Stops OnTicksBatch events for symbol and releases its buffer. Unsubscribing a symbol that is not subscribed does nothing.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string — Instrument name given to SubscribeToTicksBatch.

Example

await connection.invoke("UnsubscribeFromTicksBatch", symbol);

SubscribeToUsers

SubscribeToUsers()

Subscribe to account-record updates of the bound trade platform

After this call the server pushes OnUser to the calling connection for every account added, changed, deleted, archived or restored on the platform. The payload is slim by design: passwords, OTP secrets and the MQID are never sent over the hub.

Permission: Request (read) on accounts

Example

await connection.invoke("SubscribeToUsers");

UnsubscribeFromUsers

UnsubscribeFromUsers()

Unsubscribe from account-record updates

Stops OnUser pushes for the calling connection. Subscriptions to other record types stay in place.

Permission: Request (read) on accounts

Example

await connection.invoke("UnsubscribeFromUsers");

SubscribeToDeals

SubscribeToDeals()

Subscribe to deal-record updates of the bound trade platform

After this call the server pushes OnDeal for every deal added, changed or deleted on the platform, and OnDealClean when all cached deals of one account are dropped.

Permission: Request (read) on orders and deals

Example

await connection.invoke("SubscribeToDeals");

UnsubscribeFromDeals

UnsubscribeFromDeals()

Unsubscribe from deal-record updates

Stops OnDeal and OnDealClean pushes for the calling connection. Other subscriptions stay in place.

Permission: Request (read) on orders and deals

Example

await connection.invoke("UnsubscribeFromDeals");

SubscribeToOrders

SubscribeToOrders()

Subscribe to order-record updates of the bound trade platform

After this call the server pushes OnOrder for every order added, changed or deleted on the platform, OnOrderClean when all cached orders of one account are dropped, and OnOrderSync once the full snapshot has been delivered.

Permission: Request (read) on orders and deals

Example

await connection.invoke("SubscribeToOrders");

UnsubscribeFromOrders

UnsubscribeFromOrders()

Unsubscribe from order-record updates

Stops the order-record events of the calling connection. Other subscriptions stay in place.

Permission: Request (read) on orders and deals

Example

await connection.invoke("UnsubscribeFromOrders");

SubscribeToPositions

SubscribeToPositions()

Subscribe to position-record updates of the bound trade platform

After this call the server pushes OnPosition for every position opened, changed or closed on the platform, OnPositionClean when all cached positions of one account are dropped, and OnPositionSync once the full snapshot has been delivered. A closed position arrives as a delete with zeroed volume and open price.

Permission: Request (read) on orders and deals

Example

await connection.invoke("SubscribeToPositions");

UnsubscribeFromPositions

UnsubscribeFromPositions()

Unsubscribe from position-record updates

Stops the position-record events of the calling connection. Other subscriptions stay in place.

Permission: Request (read) on orders and deals

Example

await connection.invoke("UnsubscribeFromPositions");

SubscribeToSymbols

SubscribeToSymbols()

Subscribe to symbol-configuration updates of the bound trade platform

After this call the server pushes OnSymbol for every symbol added, changed or deleted on the platform and OnSymbolSync once the full symbol snapshot has been delivered. Only the trading-relevant configuration fields are pushed; session calendars, tick filters and instant-execution internals stay on the REST surface. For live prices of one instrument use SubscribeToTicks instead.

Permission: Request (read) on symbols

Example

await connection.invoke("SubscribeToSymbols");

UnsubscribeFromSymbols

UnsubscribeFromSymbols()

Unsubscribe from symbol-configuration updates

Stops the symbol-configuration events of the calling connection. Real-time price subscriptions are unaffected.

Permission: Request (read) on symbols

Example

await connection.invoke("UnsubscribeFromSymbols");

Streams

Calls that return a sequence of items for as long as the client keeps the stream open.

StreamTicks

StreamTicks(symbol) → stream of MT5TickPayload

Stream ticks of the bound trade platform

Returns a server-to-client async stream of ticks. With no symbol the stream carries every instrument of the bound trade platform; with a symbol it carries that symbol only, matched case-insensitively. The stream stays open until the client cancels it or disconnects.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string or null null Instrument name; send null for all instruments.

Example

connection.stream("StreamTicks", null).subscribe({
  next: item => console.log(item),
  error: err => console.error(err),
  complete: () => {},
});

StreamMarginCallUpdates

StreamMarginCallUpdates() → stream of MT5MarginCallPayload

Stream margin-call and stop-out events

Returns a server-to-client async stream of margin-call and stop-out events for all accounts on the connected trade platform. Each item carries the account login, event type, and update direction.

Permission: Request (read) on accounts

Example

connection.stream("StreamMarginCallUpdates").subscribe({
  next: item => console.log(item),
  error: err => console.error(err),
  complete: () => {},
});

Events

Pushed by the server to the connection; register a handler with connection.on(name, handler). The handler receives one argument, the payload.

OnMT5ConnectionStatus

Payload: MT5ConnectionStatusPayload

Whether WebAPI is connected to the trade platform behind the hub. Sent once right after the client connects (with the current state) and again at every change; needs no subscribing call.

connection.on("OnMT5ConnectionStatus", data => console.log(data));

OnTick

Payload: MT5TickPayload

New tick of a subscribed symbol. Emitted for subscriptions made with SubscribeToTicks and, for every symbol of the platform, with SubscribeToAllTicks (callback model); use StreamTicks for the stream model.

connection.on("OnTick", data => console.log(data));

OnTicksBatch

Payload: MT5TicksBatchPayload

Accrued ticks of a symbol subscribed with SubscribeToTicksBatch. Sent at the subscriber's interval or as soon as its batch size is reached, instead of one event per tick. Batched subscriptions receive this event only, never OnTick.

connection.on("OnTicksBatch", data => console.log(data));

OnUser

Payload: MT5UserUpdatePayload

Account record added, changed, deleted, archived or restored, for subscriptions made with SubscribeToUsers. The payload is slim by design — no passwords, OTP secrets or MQID are ever pushed.

connection.on("OnUser", data => console.log(data));

OnDeal

Payload: MT5DealUpdatePayload

Deal record added, changed or deleted, for subscriptions made with SubscribeToDeals.

connection.on("OnDeal", data => console.log(data));

OnDealClean

Payload: MT5CleanPayload

All cached deals of one account were dropped, so the client should forget what it holds for that login until fresh OnDeal events arrive.

connection.on("OnDealClean", data => console.log(data));

OnOrder

Payload: MT5OrderUpdatePayload

Order record added, changed or deleted, for subscriptions made with SubscribeToOrders.

connection.on("OnOrder", data => console.log(data));

OnOrderClean

Payload: MT5CleanPayload

All cached orders of one account were dropped, so the client should forget what it holds for that login until fresh OnOrder events arrive.

connection.on("OnOrderClean", data => console.log(data));

OnOrderSync

Payload: MT5SyncPayload

The trade server finished pushing the full order snapshot; the client's view of the orders is complete from this point on.

connection.on("OnOrderSync", data => console.log(data));

OnPosition

Payload: MT5PositionUpdatePayload

Position record opened, changed or closed, for subscriptions made with SubscribeToPositions. A closed position arrives as a delete with zeroed volume and open price.

connection.on("OnPosition", data => console.log(data));

OnPositionClean

Payload: MT5CleanPayload

All cached positions of one account were dropped, so the client should forget what it holds for that login until fresh OnPosition events arrive.

connection.on("OnPositionClean", data => console.log(data));

OnPositionSync

Payload: MT5SyncPayload

The trade server finished pushing the full position snapshot; the client's view of the positions is complete from this point on.

connection.on("OnPositionSync", data => console.log(data));

OnSymbol

Payload: MT5SymbolUpdatePayload

Symbol configuration added, changed or deleted, for subscriptions made with SubscribeToSymbols. Only the trading-relevant fields are pushed; session calendars and tick filters stay on the REST surface.

connection.on("OnSymbol", data => console.log(data));

OnSymbolSync

Payload: MT5SyncPayload

The trade server finished pushing the full symbol snapshot; the client's view of the symbol list is complete from this point on.

connection.on("OnSymbolSync", data => console.log(data));

Payloads

The data the events and streams carry, with JSON property names as sent. A type marked or null may be null; every other field is always present. A value of a list type is an array.

MT5TickPayload

Market tick of one symbol on the bound trade platform.

PropertyTypeDescription
symbol string Instrument name as reported by the trade server.
bid number Best bid price of the tick.
ask number Best ask price of the tick.
last number Price of the last committed transaction; zero when the price feed carries none.
lastTime string (date-time) Tick time in the trade server's time zone.
volumeExt integer Tick volume with extended precision, as supplied by the data provider.
flags string Names of the set tick flags, for example Bid, Ask.

MT5MarginCallPayload

Margin-call or stop-out event for an account.

PropertyTypeDescription
login integer Account login.
type string Which level the event is about: MarginCall or StopOut.
direction string Enter when the account reached that level, Leave when it left it.

MT5ConnectionStatusPayload

Whether WebAPI is connected to the trade platform behind the hub, sent once right after the client connects and again at every change.

PropertyTypeDescription
connected boolean true while the connection to the trade platform is up.

MT5TicksBatchPayload

Accrued ticks of one symbol, sent instead of one event per tick.

PropertyTypeDescription
symbol string Instrument the ticks belong to, as reported by the trade server.
ticks MT5TickPayload[] Ticks accumulated since the previous batch, in arrival order. Never empty.

MT5UserUpdatePayload

Trading-account state transition. Slim by design: passwords, OTP secrets, the MQID and reserved blobs are deliberately NOT surfaced over the hub.

PropertyTypeDescription
kind MT5UserUpdateKind What happened to the record.
login integer or null Account login, unique within the trade server.
group string Group the account belongs to right now.
name string or null Full name as stored in the account record.
firstName string or null Given name, when the server holds it separately.
lastName string or null Family name, when the server holds it separately.
middleName string or null Middle name, when the server holds it separately.
company string or null Company name, when the account is corporate.
country string or null Country of residence, in the server's own naming.
city string or null City of residence.
state string or null State or region of residence.
zipCode string or null Postal code.
address string or null Street address.
phone string or null Contact phone number.
email string or null Contact e-mail address.
status string or null Free-form account status carried by the server.
comment string or null Free-form comment of the account record.
rights string or null Names of the set access rights, for example Trader, Manager.
leverage integer Account leverage, 1:1 is reported as 1.
balance number or null Account balance in the deposit currency.
credit number or null Credit granted to the account.
agent integer or null Login of the agent account, when the account is an agent's client.
clientId integer or null Identifier of the trading client record, when the server has one.
language integer or null Server-side language identifier of the account.
registration string (date-time) or null When the account was created, in the server's time zone.
lastAccess string (date-time) or null Last known connection time of the account.
lastPassChange string (date-time) or null When the password was last changed.

MT5UserUpdateKind

Kind of a user-record change, in the order the trade server reports it.

Sent as one of these names:

ValueMeaning
AddedThe account was created.
UpdatedThe account was modified.
DeletedThe account was deleted.
ArchivedThe account was moved to the archive.
RestoredThe account was restored from the archive.

MT5DealUpdatePayload

A completed trading operation. Fields follow the trade server's deal record: prices and volumes are in the server's units, volume is exact in VolumeExt.

PropertyTypeDescription
kind MT5DealUpdateKind What happened to the record.
deal integer Deal ticket, unique within the trade server.
externalId string or null Identifier assigned by an external system, when the deal came through a gateway.
login integer or null Account login the deal belongs to.
dealer integer or null Login of the dealer who executed the deal, when it was dealer-executed.
partyId integer or null Identifier of the party the deal was made with.
order integer or null Order ticket the deal was created from.
positionId integer or null Position identifier the deal belongs to.
action string or null Deal action (buy, sell, balance operation, …) as reported by the server.
entry string or null Entry direction of the deal (in, out, in/out, out by).
reason string or null Why the deal was created (client request, stop loss, take profit, …).
time string (date-time) or null Execution time in the trade server's time zone.
timeMsc string (date-time) or null Execution time with millisecond precision.
symbol string or null Instrument the deal was made on.
digits integer or null Price precision of the instrument at execution time.
digitsCurrency integer or null Precision of the deposit currency.
contractSize number or null Contract size of the instrument at execution time.
price number or null Execution price.
priceSl number or null Stop-loss price carried by the deal.
priceTp number or null Take-profit price carried by the deal.
pricePosition number or null Position price at the moment of the deal.
volume integer or null Deal volume in the server's units.
volumeExt integer or null Deal volume with extended precision.
volumeClosed integer or null Closed volume in the server's units.
volumeClosedExt integer or null Closed volume with extended precision.
profit number or null Profit of the deal in the deposit currency.
profitRaw number or null Profit computed from the raw (unconverted) prices.
value number or null Position value at the moment of the deal.
storage number or null Storage charge attributed to the deal.
commission number or null Commission charged for the deal.
fee number or null Additional fee charged for the deal.
rateProfit number or null Currency conversion rate applied to the profit.
rateMargin number or null Currency conversion rate applied to the margin.
tickValue number or null Tick value at execution time.
tickSize number or null Tick size at execution time.
expertId integer or null Identifier of the expert advisor that created the deal, when there was one.
comment string or null Free-form comment of the deal.
gateway string or null Gateway that delivered the deal, when it came from one.
flags integer or null Raw deal flags as reported by the server.

MT5DealUpdateKind

Kind of a deal change.

Sent as one of these names:

ValueMeaning
AddedThe deal was added.
UpdatedThe deal was modified.
DeletedThe deal was deleted.

MT5CleanPayload

All cached records of one account were dropped, so the client should forget everything it holds for that login until fresh events arrive.

PropertyTypeDescription
login integer Account login whose records were dropped.

MT5OrderUpdatePayload

A pending order and its state. Fields follow the trade server's order record.

PropertyTypeDescription
kind MT5OrderUpdateKind What happened to the record.
order integer or null Order ticket, unique within the trade server.
externalId string or null Identifier assigned by an external system, when the order came through a gateway.
login integer or null Account login the order belongs to.
dealer integer or null Login of the dealer who placed the order, when it was dealer-placed.
partyId integer or null Identifier of the party the order was placed with.
symbol string or null Instrument the order is placed on.
digits integer or null Price precision of the instrument at placement time.
digitsCurrency integer or null Precision of the deposit currency.
contractSize number or null Contract size of the instrument at placement time.
state string or null Order state (placed, partially filled, filled, cancelled, …).
reason string or null Why the order was placed (client request, stop loss, take profit, …).
type string or null Order type (market, limit, stop, stop limit, …).
typeFill string or null Execution mode declared by the order (fill or kill, immediate or cancel, …).
typeTime string or null Expiration mode of the order (good till cancelled, day, specified, …).
timeSetup string (date-time) or null When the order was placed, in the trade server's time zone.
timeExpiration string (date-time) or null When the order expires.
timeDone string (date-time) or null When the order reached its final state.
timeSetupMsc string (date-time) or null Placement time with millisecond precision.
timeDoneMsc string (date-time) or null Final-state time with millisecond precision.
priceOrder number or null Price specified in the order.
priceTrigger number or null Activation price of a stop-limit order.
priceCurrent number or null Current market price of the instrument.
priceSl number or null Stop-loss price carried by the order.
priceTp number or null Take-profit price carried by the order.
volumeInitial integer or null Requested volume in the server's units.
volumeCurrent integer or null Unfilled remainder in the server's units.
volumeInitialExt integer or null Requested volume with extended precision.
volumeCurrentExt integer or null Unfilled remainder with extended precision.
expertId integer or null Identifier of the expert advisor that placed the order, when there was one.
positionId integer or null Position identifier the order belongs to.
comment string or null Free-form comment of the order.
rateMargin number or null Currency conversion rate applied to the margin.

MT5OrderUpdateKind

Kind of an order change.

Sent as one of these names:

ValueMeaning
AddedThe order was placed.
UpdatedThe order was modified.
DeletedThe order was removed.

MT5SyncPayload

The trade server finished pushing a full snapshot, so the client's view is complete. The event carries no data: the platform is already known from the connection.

An empty object: the event is a marker, it carries no data.

MT5PositionUpdatePayload

An open position and its state. A deleted position arrives with zeroed volume and open price, which is how the trade server reports a closed position.

PropertyTypeDescription
kind MT5PositionUpdateKind What happened to the record.
position integer or null Position identifier, unique within the trade server.
externalId string or null Identifier assigned by an external system, when the position came through a gateway.
login integer or null Account login the position belongs to.
symbol string or null Instrument the position is open on.
action string or null Position direction (buy or sell).
reason string or null Why the position was opened (client request, …).
timeCreate string (date-time) or null When the position was opened, in the trade server's time zone.
timeUpdate string (date-time) or null When the position last changed.
timeCreateMsc string (date-time) or null Opening time with millisecond precision.
timeUpdateMsc string (date-time) or null Last-change time with millisecond precision.
priceOpen number or null Volume-weighted open price.
priceCurrent number or null Current market price of the instrument.
priceSl number or null Stop-loss price of the position.
priceTp number or null Take-profit price of the position.
volume integer or null Position volume in the server's units.
volumeExt integer or null Position volume with extended precision.
profit number or null Current profit in the deposit currency.
storage number or null Accrued storage charge.
rateProfit number or null Currency conversion rate applied to the profit.
rateMargin number or null Currency conversion rate applied to the margin.
expertId integer or null Identifier of the expert advisor that opened the position, when there was one.
expertPositionId integer or null Identifier the expert advisor assigned to the position.
comment string or null Free-form comment of the position.
dealer integer or null Login of the dealer who opened the position, when it was dealer-opened.
activationMode string or null How the position is activated (by price, by time, …).
activationTime string (date-time) or null Activation time, when the position is time-activated.
activationPrice number or null Activation price, when the position is price-activated.
modificationFlags string or null Names of the set modification flags of the position.

MT5PositionUpdateKind

Kind of a position change.

Sent as one of these names:

ValueMeaning
AddedThe position was opened.
UpdatedThe position was modified.
DeletedThe position was closed.

MT5SymbolUpdatePayload

Symbol-configuration state transition. Surfaces the trading-relevant fields only: session calendars, tick filters, instant-execution internals, splice and option settings are not pushed over the hub; subscribers that need them should use the REST surface.

PropertyTypeDescription
kind MT5SymbolUpdateKind What happened to the record.
symbol string or null Instrument name as reported by the trade server.
path string or null Hierarchy path of the instrument in the server's symbol tree.
description string or null Human-readable instrument description.
currencyBase string or null Base currency of the instrument.
currencyProfit string or null Currency the profit is calculated in.
currencyMargin string or null Currency the margin is calculated in.
digits integer or null Price precision.
tradeMode string or null Trading mode (disabled, long only, short only, close only, full access).
calcMode string or null Profit and margin calculation mode.
execMode string or null Order execution mode.
gtcMode string or null How good-till-cancelled orders are handled.
spread integer or null Spread in points.
spreadBalance integer or null Spread balance in points.
spreadDiff integer or null Difference between the current and the default spread.
spreadDiffBalance integer or null Balance of the spread difference.
tickValue number or null Value of one tick in the profit currency.
tickSize number or null Size of one tick in price units.
contractSize number or null Contract size of one lot.
stopsLevel integer or null Minimal distance of stop orders from the current price, in points.
freezeLevel integer or null Distance at which orders cannot be modified, in points.
volumeMin integer or null Minimal volume in the server's units.
volumeMax integer or null Maximal volume in the server's units.
volumeStep integer or null Volume change step in the server's units.
volumeLimit integer or null Maximal total volume of one position in the server's units.
volumeMinExt integer or null Minimal volume with extended precision.
volumeMaxExt integer or null Maximal volume with extended precision.
volumeStepExt integer or null Volume change step with extended precision.
volumeLimitExt integer or null Maximal total volume of one position with extended precision.
marginInitial number or null Initial margin rate.
marginMaintenance number or null Maintenance margin rate.
marginLong number or null Margin rate for long positions.
marginShort number or null Margin rate for short positions.
marginLimit number or null Margin rate applied to limit orders.
swapMode string or null How swaps are charged (in points, in percent, in money, …).
swapLong number or null Swap charged for long positions.
swapShort number or null Swap charged for short positions.
swap3Day string or null Weekday the triple swap is charged on.
timeStart string (date-time) or null Start of the instrument's quoting period.
timeExpiration string (date-time) or null End of the instrument's quoting period.

MT5SymbolUpdateKind

Kind of a symbol-configuration change.

Sent as one of these names:

ValueMeaning
AddedThe symbol was added.
UpdatedThe symbol was modified.
DeletedThe symbol was removed.