Table of Contents

Engagement Procedure

We describe the client-server dynamic after the MdClientSession instance has been created (as in MdClientSession Configuration).

Clients must make sure that all the necessary event handlers are implemented and defined for their use cases before connecting to the server. We provide some concrete examples.

1. Setting up event handlers

In this example, the client subscribes to connection and market data events, then proceeds to the connection.

Note: in the OSI model, the connection events relate to layer 4 and market data events to layer 7.

// Somewhere in the client code, after creating the MdClientSession instance:

// Layer 4 events
mdClientSession.Connecting += OnConnecting;
mdClientSession.Connected += OnConnected;
mdClientSession.Disconnecting += OnDisconnecting;
mdClientSession.Disconnected += OnDisconnected;
mdClientSession.ErrorDetected += OnErrorDetected;

// Layer 7 events
mdClientSession.TopOfBookEventDataReceived += OnTopOfBookEventDataReceived;
mdClientSession.InstrumentSnapshotEventDataReceived += OnInstrumentSnapshotEventDataReceived;
mdClientSession.TradeEventDataReceived += OnTradeEventDataReceived;

// Connection
mdClientSession.Connect();

Here the client implements handlers for only three market data events: TopOfBookEventDataReceived, InstrumentSnapshotEventDataReceived, TradeEventDataReceived.

For performance reasons, you should only subscribe to events that are crucial to your application.

2. Connecting and logging-in

After connecting to the feed handler instance, the server will wait for 30 seconds to receive the client's Login request.

If the Login request is not sent, the client will be forcibly disconnected by the server.

// In this example, mdConnector is an instance of a user-defined class that encapsulates the MdClientSession.
// You can check the MarketDataConnector class as a suggestion for your own wrapper implementation, if necessary.

logger.LogInformation("[Main] Initialization process");
    
mdConnector.Connect();

await mdConnector.ConnectionSignal.WaitAsync().ConfigureAwait(false); //here the MarketDataConnector implements a blocking mechanism to wait successful connection

if (!mdConnector.IsConnected)
{
    logger.LogError("[Main] Connection failed");
    goto end;
}

logger.LogInformation("[Main] Logging in");

var loginRequest = await mdConnector.Session.LoginRequest("", "0A5F536F-F06C-4130-8967-D77C9FB0CE2", TimeSpan.FromSeconds(10)).ConfigureAwait(false);

if (!loginRequest.IsAuthenticated)
{
    logger.LogError("[Main] Login failed. Reason: {0}", loginRequest.Status);
    goto end;
}

logger.LogInformation("[Main] Logged in");

Upon a successful login, the client can then proceed to issue new requests.

We suggest clients query the market data full security list with the GetSecurityListRequest, store the InstrumentId references and use them later for subscriptions or other requests.