Page tree
Skip to end of metadata
Go to start of metadata

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.

This example shows data coming from server every second - current server time. No authentication needed.
https://MyWebAPI.com/DemoSignalR/Test
- This example shows how you can get real-time date from WebAPI host server. 
https://
MyWebAPI.com/DemoSignalR/MT4 - Be aware, you need to adjust page source code (to make it work) to whatever you have for your installation (client_id, client_secret, tradeplatform_id, etc). Get page source, adjust settings and run the page.

How to use

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

Within page header
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/aspnet-signalr/1.1.0/signalr.js"></script>

Then create connection to SignalR endpoint:

Initialization (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:

Connect (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.

  • No labels