Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Brief

SignalR makes possible to have two side connectivity with web server to get/send (streaming) data in real-time. For example, you can get quotes, margin updates of your MT4 clients, online users list, open orders at real time as it happen in MT4. Once you get subscribed to whatever you need you would get updates, no need to ask web server about new portion of data every time.

Quick examples

Here you can get working examples. Simply open source code of any page below and get client side code which demonstrates basic while negotiating with SignalR endpoint.

...

Widget Connector
width560
urlhttps://www.youtube.com/watch?v=NEuuyzY2r08
height315

How to use

Add links to required libraries within your page's header:

...

Then create connection to SignalR endpoint:

Code Block
languagejs
titleInitialization (JavaScript )
// access token obtained after authentication should be saved here
var access_token = '';

// create connection
const connection = new signalR.HubConnectionBuilder()
    .withUrl('@Context.Request.Scheme://@Context.Request.Host/hubs/mt4/v1',
        {
            accessTokenFactory: () => {
                //show("AccessTokenProvider()");
                return access_token;
            },
            // let's skip negotiation and start right with websockets
            transport: (signalR.HttpTransportType.WebSockets),
            skipNegotiation: true
        })
    .configureLogging(signalR.LogLevel.Debug)
    .build();

To connect just call:

Code Block
languagejs
titleConnect (JavaScript )
await connection.start();

...

You need an authentication token obtained from authentication server (auth.cplugin.net). Once you get a token, provide it to SignalR client through accessTokenFactory() function

Features

There are few hubs available to work with. Test and MT4. More details about each one you can find in corresponding section.