Besides the REST calls, WebAPI pushes live data over SignalR — a protocol on top of WebSockets (with fallbacks to Server-Sent Events and long polling) that has official clients for JavaScript, .NET and Java. There is one hub for each trading platform; the pages below list every call a client can make, every event the server sends and every field of the data.
https://cloud.mywebapi.com/hubs/mt4/v2 · 20 calls · 8 eventshttps://cloud.mywebapi.com/hubs/mt5/v2 · 18 calls · 14 eventsThe open-source SDKs for TypeScript, Python, .NET and PowerShell wrap the REST calls and these hubs; use a SignalR client directly when your language has no SDK, or to see exactly what goes over the wire.
https://cloud.mywebapi.com/hubs/mt4/v2?tradePlatform=<id> for Production, or the same path on
https://pre.mywebapi.com for the Sandbox. tradePlatform is the id (GUID) of a trade platform
registered in Toolbox. It is required and fixed for the whole connection: the platform is not an argument of any call
and is not repeated in any event. To work with several platforms, open one connection for each.
webapi, from the
token server of the environment you connect to). Give it to the SignalR client through its access-token option
(accessTokenFactory in JavaScript), which the client calls for every connection attempt. A client that
cannot do that can append signalr_token=<token> to the address.
import * as signalR from "@microsoft/signalr";
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://cloud.mywebapi.com/hubs/mt4/v2?tradePlatform=<trade platform id>", {
accessTokenFactory: () => getToken(), // return a current token
})
.withAutomaticReconnect()
.build();
connection.on("OnMT4ConnectionStatus", ({ connected }) => console.log("trade platform connected:", connected));
connection.on("OnTick", tick => console.log(tick.symbol, tick.bid, tick.ask));
// after every reconnect: nothing is replayed and the subscriptions are gone (see below)
connection.onreconnected(async () => {
await connection.invoke("SubscribeToTicks", "EURUSD");
// ...subscribe to everything else you use, then read the current state over REST
});
await connection.start();
await connection.invoke("SubscribeToTicks", "EURUSD");
The event OnMT4ConnectionStatus carries { connected: boolean }: whether WebAPI is connected to the
trade platform behind this hub. It is the only event that needs no subscribing call. The server sends it once right after the
client connects — so opening a connection can take up to 25 seconds, as the server waits for its own connection to the trade
platform to come up first — and again whenever the state changes.
connected: true status, or a reconnect), treat everything you hold as possibly stale and read the current
state over REST — quotes, accounts, orders — before relying on events again.
connection.on stay in place on the client.
A subscription (SubscribeTo…) is a call that returns at once; from then on the server pushes
events to the connection, each delivered to the handler registered with connection.on(eventName, …).
Stop it with the matching UnsubscribeFrom…. A stream (Stream…) is a call that
returns a sequence of items over connection.stream(…), which ends when the client cancels it or disconnects.
Both deliver the same kind of data; use whichever fits your client. Events are one argument each — the payload object —
and every payload is listed on the hub's page with its JSON property names exactly as sent (camelCase).
Batched ticks. A tick subscription sends one event per tick. SubscribeToTicksBatch sends the ticks of
one symbol collected over a short interval as one event instead, which costs far less traffic at high tick rates; a batched
subscriber gets no per-tick event for that symbol. Batching is about traffic, not latency — the per-tick subscription remains
the lowest-latency option.
SignalR does not apply default values declared on the server. A raw SignalR client must pass every
argument of a call: a call with one missing fails with an error from the server. Where a parameter has a default, its
description says which value to send for it (for example 200), and where it accepts null, send
null to get the default behaviour (for example, null as the symbol of a tick stream means all
symbols). The examples on the hub pages already show complete calls.