CPlugin

MT4 hub (v2)

MT4 · 20 calls · 8 events · address https://cloud.mywebapi.com/hubs/mt4/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, OnMT4ConnectionStatus, 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 tick of symbol on the bound trade platform. Call it once per symbol; several symbols can be subscribed on the same connection. For the stream model use StreamTicks.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string — Symbol name, matched case-insensitively.

Example

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

UnsubscribeFromTicks

UnsubscribeFromTicks(symbol)

Unsubscribe from the tick updates of one 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 — Symbol name given to SubscribeToTicks.

Example

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

SubscribeToTicksBatch

SubscribeToTicksBatch(symbol, intervalMs, maxBatchSize)

Subscribe to the ticks of one symbol as batches

The caller receives OnTicksBatch and no per-tick OnTick for the symbol. A batch is sent when its oldest tick has waited intervalMs milliseconds, or at once when maxBatchSize ticks have been collected; the timer checks about every 50 ms, so a shorter interval behaves as 50 ms. A value outside the accepted range is refused with an error. Repeating the call for the same symbol replaces the previous subscription, so the new interval and size take effect.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string — Symbol name, matched case-insensitively.
intervalMs integer 200 Longest time a tick may wait for its batch, in milliseconds; 20 to 60000. Send 200 for the default.
maxBatchSize integer 200 Largest number of ticks in one event; 1 to 10000. Send 200 for the default.

Example

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

UnsubscribeFromTicksBatch

UnsubscribeFromTicksBatch(symbol)

Unsubscribe from the batched tick updates of one symbol

Stops OnTicksBatch events for symbol. Ticks of other symbols and the per-tick subscriptions are not affected.

Permission: Request (read) on symbols

Arguments

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

Example

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

SubscribeToAllTicks

SubscribeToAllTicks()

Subscribe to the aggregated ticks of every symbol

The server sends the ticks of all symbols of the bound trade platform as one OnTicks event every 200 ms. Repeating the call replaces the previous subscription.

Permission: Request (read) on symbols

Example

await connection.invoke("SubscribeToAllTicks");

UnsubscribeFromAllTicks

UnsubscribeFromAllTicks()

Unsubscribe from the aggregated ticks of every symbol

Stops the OnTicks events started by SubscribeToAllTicks.

Permission: Request (read) on symbols

Example

await connection.invoke("UnsubscribeFromAllTicks");

SubscribeToTicksOHLC

SubscribeToTicksOHLC(periodSeconds)

Subscribe to OHLC candles of every symbol

The server builds candles from the ticks of each period and sends one OnTicksOHLC event per period with a candle for every symbol that ticked. Repeating the call replaces the previous subscription, so a new period takes effect. A period above 60 seconds is refused with an error rather than shortened.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
periodSeconds integer 60 Candle length in seconds; 1 to 60. Send 60 for the default.

Example

await connection.invoke("SubscribeToTicksOHLC", 60);

UnsubscribeFromTicksOHLC

UnsubscribeFromTicksOHLC()

Unsubscribe from the OHLC candles

Stops the OnTicksOHLC events of this connection.

Permission: Request (read) on symbols

Example

await connection.invoke("UnsubscribeFromTicksOHLC");

SubscribeToMarginUpdates

SubscribeToMarginUpdates()

Subscribe to the margin levels of every account

The server sends margin-level snapshots of the accounts of the bound trade platform as one OnMarginUpdate event per second. Repeating the call replaces the previous subscription. For the stream model use StreamMarginCallUpdates.

Permission: Request (read) on accounts

Example

await connection.invoke("SubscribeToMarginUpdates");

UnsubscribeFromMarginUpdates

UnsubscribeFromMarginUpdates()

Unsubscribe from the margin levels

Stops the OnMarginUpdate events of this connection.

Permission: Request (read) on accounts

Example

await connection.invoke("UnsubscribeFromMarginUpdates");

SubscribeToSymbols

SubscribeToSymbols()

Subscribe to symbol-configuration changes

The server sends one OnSymbolUpdate event for every symbol of the bound trade platform that is added, changed or removed. For the stream model use StreamSymbolUpdates.

Permission: Request (read) on symbols

Example

await connection.invoke("SubscribeToSymbols");

UnsubscribeFromSymbols

UnsubscribeFromSymbols()

Unsubscribe from symbol-configuration changes

Stops the OnSymbolUpdate events of this connection.

Permission: Request (read) on symbols

Example

await connection.invoke("UnsubscribeFromSymbols");

SubscribeToOnlineUpdates

SubscribeToOnlineUpdates()

Subscribe to accounts going online and offline

The server sends one OnOnlineUpdate event whenever an account of the bound trade platform connects or disconnects.

Permission: Request (read) on accounts

Example

await connection.invoke("SubscribeToOnlineUpdates");

UnsubscribeFromOnlineUpdates

UnsubscribeFromOnlineUpdates()

Unsubscribe from accounts going online and offline

Stops the OnOnlineUpdate events of this connection.

Permission: Request (read) on accounts

Example

await connection.invoke("UnsubscribeFromOnlineUpdates");

Streams

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

StreamTicks

StreamTicks(symbol) → stream of TickPayload

Stream the ticks of the bound trade platform

Returns a server-to-client stream of ticks. With a null symbol the stream carries every symbol 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. A client that reads too slowly loses its oldest ticks.

Permission: Request (read) on symbols

Arguments

NameTypeFor the default, sendDescription
symbol string or null null Symbol to stream; send null for all symbols.

Example

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

StreamAllTicks

StreamAllTicks() → stream of TickPayload

Stream every tick of the bound trade platform

The same feed as StreamTicks with a null symbol: every symbol of the bound trade platform, until the client cancels the stream or disconnects.

Permission: Request (read) on symbols

Example

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

StreamMarginCallUpdates

StreamMarginCallUpdates() → stream of MarginCallPayload

Stream the margin levels of every account

Returns a server-to-client stream of margin-level updates for every account of the bound trade platform, until the client cancels it or disconnects.

Permission: Request (read) on accounts

Example

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

StreamTrades

StreamTrades() → stream of TradeUpdatePayload

Stream trade updates

Returns a server-to-client stream of order updates (opened, modified, closed or deleted) for the bound trade platform, until the client cancels it or disconnects.

Permission: Request (read) on orders and deals

Example

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

StreamUserUpdates

StreamUserUpdates() → stream of UserUpdatePayload

Stream account updates

Returns a server-to-client stream of account-record updates (created, modified or deleted, including a change of group) for the bound trade platform, until the client cancels it or disconnects. The payload is slim by design: passwords and other credentials are never sent.

Permission: Request (read) on accounts

Example

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

StreamSymbolUpdates

StreamSymbolUpdates() → stream of SymbolUpdatePayload

Stream symbol-configuration updates

Returns a server-to-client stream of symbol-configuration updates (added, changed or removed) for the bound trade platform, until the client cancels it or disconnects.

Permission: Request (read) on symbols

Example

connection.stream("StreamSymbolUpdates").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.

OnMT4ConnectionStatus

Payload: ConnectionStatusPayload

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("OnMT4ConnectionStatus", data => console.log(data));

OnTick

Payload: TickPayload

New tick of a symbol subscribed with SubscribeToTicks. For the stream model use StreamTicks.

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

OnTicksBatch

Payload: MT4TicksBatchPayload

Ticks of one subscribed symbol arrived as a batch — sent to subscribers of SubscribeToTicksBatch instead of one OnTick message per tick.

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

OnTicks

Payload: TicksPayload

Aggregated ticks of the bound trade platform — sent to subscribers of SubscribeToAllTicks instead of one OnTick message per tick.

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

OnTicksOHLC

Payload: TicksOhlcPayload

OHLC candles aggregated over the period passed to SubscribeToTicksOHLC. Contains one candle per symbol that ticked during the period.

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

OnMarginUpdate

Payload: MarginUpdatesPayload

Margin-level snapshots of accounts, sent once per second — delivered to subscribers of SubscribeToMarginUpdates.

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

OnSymbolUpdate

Payload: SymbolUpdatePayload

Symbol configuration added, changed or removed — delivered to subscribers of SubscribeToSymbols.

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

OnOnlineUpdate

Payload: OnlineUpdatePayload

Account went online or offline — delivered to subscribers of SubscribeToOnlineUpdates.

connection.on("OnOnlineUpdate", 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.

TickPayload

Market tick of one symbol on the bound trade platform.

PropertyTypeDescription
symbol string Symbol name as reported by the trade server.
bid number Bid price of the tick.
ask number Ask price of the tick.
lastTime string (date-time) or null Time of the tick in the trade server's time zone; null when the server reports none.

MarginCallPayload

Margin-level snapshot of one account.

PropertyTypeDescription
login integer Account login.
group string or null Group the account belongs to; null when the server reports none.
leverage integer Account leverage.
updated integer Time of the last update, as Unix time in seconds.
balance number Account balance in the deposit currency.
equity number Account equity in the deposit currency.
volumeLots number Volume of the open positions, in lots.
margin number Margin in use.
free number Free margin.
level number Margin level.
controllingType MarginControllingType Whether the margin level is controlled as a percentage or as a currency amount.
levelType MarginLevelType The state of the account: within limits, margin call or stop out.

MarginControllingType

Sent as one of these names:

ValueMeaning
Percent
Currency

MarginLevelType

Sent as one of these names:

ValueMeaning
Ok
MarginCall
StopOut

TradeUpdatePayload

An order changing state on the trade server.

PropertyTypeDescription
kind TradeUpdateKind What happened to the order.
order integer Order ticket number.
login integer Login of the account that owns the order.
symbol string Symbol of the order.
cmd TradeCommand Order type: a market or pending order, or a balance or credit operation.
volumeLots number Volume in lots.
openPrice number Open price.
openTime string (date-time) Open time in the trade server's time zone.
sl number Stop-loss price; 0 when none is set.
tp number Take-profit price; 0 when none is set.
closePrice number Close price.
closeTime string (date-time) Close time in the trade server's time zone; meaningful once the order is closed.
commission number Commission charged.
storage number Swap accrued by the order.
profit number Profit of the order.
taxes number Taxes charged.
comment string Comment of the order.

TradeUpdateKind

Lifecycle marker for a trade record event.

Sent as one of these names:

ValueMeaning
AddedNew order opened on the server.
UpdatedOrder modified (sl/tp/comment/etc.) or partially closed.
DeletedOrder fully closed or deleted.

TradeCommand

Sent as one of these names:

ValueMeaning
Buy
Sell
BuyLimit
SellLimit
BuyStop
SellStop
Balance
Credit

UserUpdatePayload

An account record changing state. Slim by design: passwords and other credentials are never sent.

PropertyTypeDescription
kind UserUpdateKind What happened to the account.
login integer Account login.
group string Group the account belongs to.
name string Name of the account holder.
country string Country of residence.
leverage integer Account leverage.
balance number Account balance in the deposit currency.
credit number Credit granted to the account.
enabled boolean Whether the account is enabled.
readOnly boolean Whether the account is read-only: it may log in but not trade.
regDate string (date-time) When the account was registered.
lastDate string (date-time) When the account last connected.
email string E-mail address of the account holder.
phone string Phone number of the account holder.
comment string Free-form comment of the account record.

UserUpdateKind

Kind of an account-record change.

Sent as one of these names:

ValueMeaning
AddedThe account was created.
UpdatedThe account was modified, including a change of group.
DeletedThe account was deleted.

SymbolUpdatePayload

A symbol configuration changing state. Only the trading-relevant settings are sent; the rest of the configuration (session calendars, swap settings) is available over REST.

PropertyTypeDescription
kind SymbolUpdateKind What happened to the symbol.
symbol string Symbol name.
description string Description of the instrument.
currency string Currency of the symbol.
digits integer Number of digits after the decimal point in prices.
tradeMode TradeMode Which trading is allowed on the symbol.
spread integer Spread in points.
stopsLevel integer Smallest distance, in points, between the price and a stop order or a stop level.
freezeLevel integer Distance, in points, within which an order cannot be modified.
contractSize number Size of one lot in units of the instrument.
tickValue number Value of one tick.
tickSize number Size of one tick.
marginInitial number Initial margin requirement.
marginMaintenance number Maintenance margin requirement.

SymbolUpdateKind

Kind of a symbol-configuration change.

Sent as one of these names:

ValueMeaning
AddedThe symbol was added.
UpdatedThe symbol's settings were changed.
DeletedThe symbol was removed.

TradeMode

Sent as one of these names:

ValueMeaning
No
Close
Full

ConnectionStatusPayload

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.

MT4TicksBatchPayload

Batch of ticks of one symbol, sent instead of one OnTick message per tick. The tick list is ordered oldest first and is never empty.

PropertyTypeDescription
symbol string Symbol the ticks belong to.
ticks TickPayload[] Ticks collected since the previous batch, oldest first.

TicksPayload

Aggregated ticks of one or more symbols, sent on a fixed interval instead of one message per tick. The list is ordered oldest first and is never empty.

PropertyTypeDescription
ticks TickPayload[] Ticks of the interval, oldest first.

TicksOhlcPayload

OHLC candles of every symbol that ticked during the sampling period. Never empty.

PropertyTypeDescription
ticks OhlcPayload[] One candle for each symbol that ticked.

OhlcPayload

One OHLC candle of a symbol, aggregated from the ticks of one sampling period.

PropertyTypeDescription
symbol string Symbol the candle belongs to.
open BidAskPayload First tick of the period.
maximum BidAskPayload Highest bid and highest ask of the period, taken separately.
minimum BidAskPayload Lowest bid and lowest ask of the period, taken separately.
close BidAskPayload Last tick of the period.
lastTime string (date-time) or null Time of the last tick of the period.
volume integer Number of ticks the candle was built from.

BidAskPayload

Bid and ask price of one OHLC corner. Bid and ask are aggregated separately, so the pair may not come from the same tick.

PropertyTypeDescription
bid number Bid price.
ask number Ask price.

MarginUpdatesPayload

Margin-level snapshots of several accounts, sent once per sampling period.

PropertyTypeDescription
margins MarginCallPayload[] One snapshot for each account in the update.

OnlineUpdatePayload

Account went online (Add) or offline (Delete).

PropertyTypeDescription
type TransactionType Add when the account went online, Delete when it went offline; no other value is sent.
login integer Account login.

TransactionType

Sent as one of these names:

ValueMeaning
Add
Delete
Update
ChangeGrp