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

To step further, first of all, you have to be Connected to WebSockets endpoint. Then you can subscribe/unsubscribe to/form events and receive updates.

This hub expose connectivity with MT4 server features. For example:

  • get prices at real-time on your web page
  • get clients' margin updates
  • etc

Assumed you are already authenticated, it needs so to call any function mentioned here.

Also assumed you have already connected to SignalR endpoint.

To get prices at real-time you can subscribe on interested symbols:

Example of subscribing to ticks stream (JavaScript)
connection
    .invoke("SubscribeToTicks", tradePlatform, "EURUSD")
    .then((res) => { console.log("Subscribed to ticks (" + this + ") : " + res); })
    .catch(err => console.error(err));

To determine with what server you are going to work you have to specify its identifier explicitly.

To unsubscribe there is opposite function:

Example of unsubscribing from ticks stream (JavaScript)
connection
    .invoke("UnsubscribeFromTicks", tradePlatform, "EURUSD")
    .then((res) => { console.log("Unsubscribed from ticks (EURUSD) : " + res); })
    .catch(err => console.error(err));

Once you get subscribed you start getting quotes immediately to your client side code:

Example of hook called, when new price arrived (JavaScript)
connection.on("onTick", function(tradePlatform, tick) { your code here } )

Tick structure:

class Tick
{
	string Symbol;
	double Bid;
	double Ask;
}
Server and client interfaces (C# example)
// Hub methods available to get called from remote client

public interface IMT4Hub
{
    /// <summary>
    /// Init connection with MT4
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <returns>true, if pumping is UP by moment of call</returns>
    bool Connect(Guid tradePlatform);

    /// <summary>
    /// Ping MT4 server
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <returns></returns>
    ResultCode Ping(Guid tradePlatform);

    /// <summary>
    /// Subscribe to all symbols to receive its prices
    /// </summary>
    /// <param name="tradePlatform"></param>
    void SubscribeToAllTicks(Guid tradePlatform);

    /// <summary>
    /// Unsubscribe from all symbols and stop receiving prices
    /// </summary>
    /// <param name="tradePlatform"></param>
    void UnsubscribeFromAllTicks(Guid tradePlatform);

    /// <summary>
    /// Subscribe to specified symbol to start receiving prices
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <param name="symbol"></param>
    /// <returns></returns>
    ResultCode SubscribeToTicks(Guid tradePlatform, string symbol);

    /// <summary>
    /// Unsubscribe from specified symbol and stop receiving prices
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <param name="symbol"></param>
    /// <returns></returns>
    ResultCode UnsubscribeFromTicks(Guid tradePlatform, string symbol);

    /// <summary>
    /// subscribe to get changes of clients margin
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <param name="logins"></param>
    void SubscribeToMarginUpdates(Guid tradePlatform, int[] logins);

    /// <summary>
    /// Unsubscribe from specified list of logins margin updates
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <param name="logins"></param>
    void UnsubscribeFromMarginUpdates(Guid tradePlatform, int[] logins);

    /// <summary>
    /// Subscribe to all accounts margin updates
    /// </summary>
    /// <param name="tradePlatform"></param>
    void SubscribeToAllMarginUpdates(Guid     tradePlatform);

    /// <summary>
    /// Unsubscribe from all accounts margin updates
    /// </summary>
    /// <param name="tradePlatform"></param>
    void UnsubscribeFromAllMarginUpdates(Guid tradePlatform);

    /// <summary>
    /// Subscribe to all symbols updates
    /// </summary>
    /// <param name="tradePlatform"></param>
    void SubscribeToSymbols(Guid     tradePlatform);

    /// <summary>
    /// Unsubscribe from all symbols updates
    /// </summary>
    /// <param name="tradePlatform"></param>
    void UnsubscribeFromSymbols(Guid tradePlatform);
}

// Callbacks on client that can be overriden and catched
public interface IMT4HubClient
{
    /// <summary>
    /// When status of pumping connection updated, it will report here.
    /// Plus, WebAPI will send this event right after connection being made to Hub.
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <returns></returns>
    Task OnMT4ConnectionStatus(Guid tradePlatform, bool connected);

    /// <summary>
    /// New price arrived by subscribed symbol
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <param name="tick"></param>
    /// <returns></returns>
    Task OnTick(Guid tradePlatform, Tick tick);

    /// <summary>
    /// Margin updated by list of accounts. Updates - once per second.
    /// </summary>
    /// <param name="tradePlatform"></param>
    /// <param name="margin"></param>
    /// <returns></returns>
    Task OnMarginUpdate(Guid tradePlatform, MarginLevel[] margin);

    /// <summary>
    /// Symbol settings updated
    /// </summary>
    /// <param name="tpConnectionKey"></param>
    /// <param name="transactionType"></param>
    /// <param name="conSymbol"></param>
    /// <returns></returns>
    Task OnSymbolUpdate(Guid tpConnectionKey, TransactionType transactionType, ConSymbol conSymbol);
}
  • No labels