StreamLink.NET
Caplin.StreamLink.Subscription.Record Namespace
StreamLink.NETCaplin.StreamLink.Subscription.Record

Contains interfaces, classes and enums related to records. Defines the key interfaces IRecordSubscription and IRecordSubscriptionListener in addition to all record event interfaces and the IRecordSubscriptionParameters interface.

Declaration Syntax
C#Visual BasicVisual C++
namespace Caplin.StreamLink.Subscription.Record
Namespace Caplin.StreamLink.Subscription.Record
namespace Caplin.StreamLink.Subscription.Record
Types
All TypesInterfaces
IconTypeDescription
IRecordEvent
Provides information about a change to a record (data of SubjectType Record).

IRecordSubscription
Represents a subscription to a record subject on the Liberator.

IRecordSubscriptionListener
Callback interface to be called when information regarding a record subject updates.

IRecordSubscriptionParameters
Provides access to parameters to be used when requesting a record from the Liberator.

IRecordType2Event
A Record update event object containing type 2 data.

IRecordType3Event
Record type 3 update.

Remarks

Records

Record subscriptions are created through the IStreamLinkProvider interface using one of the IStreamLinkProvider.CreateRecordSubscription methods. In all cases an IRecordSubscriptionListener must be passed along with the subject of the record being subscribed to.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;
using Caplin.StreamLink.Subscription.Record;

namespace StreamLinkExamples.Record
{
    /// <summary>
    /// Example of how to create an IRecordSubscription using the
    /// IStreamLinkProvider interface.
    /// </summary>
    public class CreateRecordSubscriptionBasic
    {
        /// <summary>
        /// Creates a simple record subscription with no parameters.
        /// </summary>
        public static void CreateRecordSubscriptionBasicExample()
        {
            // Set up StreamLink and login credentials
            StreamLink myStreamLink = new StreamLink();
            myStreamLink.CredentialsProvider =
                new PasswordCredentialsProvider("admin", "admin");

            // Set up listener and created the subscription for /DEMO/MSFT
            IRecordSubscriptionListener listener =
                new ExampleRecordSubscriptionListener();
            IRecordSubscription subscription =
                myStreamLink.StreamLinkProvider.CreateRecordSubscription(listener, "/DEMO/MSFT");

            // Subscribe the subscription, this will be queued until we
            // login to the Liberator
            subscription.Subscribe();

            // Finally, connect to the Liberator
            myStreamLink.StreamLinkProvider.Connect();                
        }
    }
}

The object implementing the IRecordSubscriptionListener listener interface will then be informed of all subscription status, error and record data events (Also see ISubscription).

CopyC#
using System;
using System.Collections.Generic;
using System.Text;

using Caplin.StreamLink.Subscription.Record;
using Caplin.StreamLink.Subscription;
using Caplin.StreamLink;

namespace StreamLinkExamples.Record
{
    /// <summary>
    /// A simple example of logging all record messages to the Console.
    /// </summary>
    public class ExampleRecordSubscriptionListener: IRecordSubscriptionListener
    {
        #region IRecordSubscriptionListener Members

        /// <summary>
        /// Called when an update occurs for a record subject.
        /// </summary>
        public void RecordUpdated(ISubscription subscription,
                                  IRecordEvent ev)
        {
            Console.WriteLine("RecordUpdate received for \"" +
                              ev.Subject + "\"");

            Console.WriteLine("Fields: ");
            foreach (IField field in ev.Fields.Values)
            {
                Console.WriteLine("Name: " + field.Name +
                                  ", Value: " + field.Value);
            }
        }

        /// <summary>
        /// Called when an update to a type2 record is received from the
        /// Liberator.
        /// </summary>
        public void RecordType2Updated(ISubscription subscription,
                                       IRecordType2Event ev)
        {
            Console.WriteLine("RecordType2Update received for \"" +
                              ev.Subject + "\"");

            Console.WriteLine("Type 2 Index: Name: " +
                              ev.Type2IndexField.Name +
                              ", Value: " + ev.Type2IndexField.Value);

            Console.WriteLine("Fields: ");
            foreach (IField field in ev.Fields.Values)
            {
                Console.WriteLine("Name: " + field.Name +
                                  ", Value: " + field.Value);
            }
        }

        /// <summary>
        /// Called when an update of type3 data is received from the Liberator.
        /// </summary>
        public void RecordType3Updated(ISubscription subscription,
                                       IRecordType3Event ev)
        {
            Console.WriteLine("RecordType3Update received for \"" +
                              ev.Subject + "\"");

            Console.WriteLine("Fields: ");
            foreach (IField field in ev.Fields.Values)
            {
                Console.WriteLine("Name: " + field.Name +
                                  ", Value: " + field.Value);
            }
        }

        #endregion

        #region ISubscriptionListener Members

        /// <summary>
        /// Subscription Ended Callback. For 'not found', 'read denied' etc.
        /// </summary>
        public void SubscriptionErrorReceived(ISubscription subscription,
                                              ISubscriptionErrorEvent ev)
        {
            Console.WriteLine( "Subscription Status Update " + ev.Subject +
                               " Error: " + ev.Error.ToString());
        }

        /// <summary>
        /// Status Callback
        /// </summary>
        public void SubscriptionStatusUpdated(ISubscription subscription,
                                              ISubscriptionStatusEvent ev)
        {
            Console.WriteLine("Subscription Status Update " + ev.Subject +
                              " Status: " + ev.Status.ToString() +
                              " " + ev.Message);
        }

        #endregion
    }
}

It is also possible to create a IRecordSubscriptionParameters. Parameters can be used to define the specific fields that the user wishes to subscribe to within the record. They are created through the factory methods available on the ParametersFactory property which returns an object implementing the IParametersFactory interface.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;
using Caplin.StreamLink.Subscription.Record;

namespace StreamLinkExamples.Record
{
    /// <summary>
    /// Various examples of how to create an IRecordSubscription using the
    /// IStreamLinkProvider interface.
    /// </summary>
    public class CreateRecordSubscriptionWithFields
    {
        /// <summary>
        /// Creates a simple record subscription with no parameters.
        /// </summary>
        public static void CreateRecordSubscriptionWithFieldsExample()
        {
            // Set up StreamLink and login credentials
            StreamLink myStreamLink = new StreamLink();
            myStreamLink.CredentialsProvider =
                new PasswordCredentialsProvider("admin", "admin");

            // Set up listener and created the subscription for /DEMO/MSFT
            IRecordSubscriptionListener listener =
                new ExampleRecordSubscriptionListener();

            string[] fields = new string[] { "Bid", "Ask" };
            IRecordSubscriptionParameters parameters = myStreamLink.StreamLinkProvider.ParametersFactory.CreateRecordSubscriptionParameters(fields);

            // Create subscription, specifying fields Bid and Ask
            IRecordSubscription subscription =
                myStreamLink.StreamLinkProvider.CreateRecordSubscription(listener, "/DEMO/MSFT", parameters);

            // Subscribe the subscription, this will be queued until we
            // login to the Liberator
            subscription.Subscribe();

            // Finally, connect to the Liberator
            myStreamLink.StreamLinkProvider.Connect();
        }
    }
}

Parameters can also define field filters so that updates only occur when the filter criteria for the record and field are met. For further information on the filtering syntax see the StreamLink Overview document.

The following example shows how to filter on a field.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;
using Caplin.StreamLink.Subscription.Record;

namespace StreamLinkExamples.Record
{
    /// <summary>
    /// Various examples of how to create an IRecordSubscription using the
    /// IStreamLinkProvider interface.
    /// </summary>
    public class CreateRecordSubscriptionWithFiltering
    {
        /// <summary>
        /// Subscribe to a record and all fields (specify no fields) and filter on a field.
        /// </summary>
        public static void CreateRecordSubscriptionWithFilteringExample()
        {
            StreamLink myStreamLink = new StreamLink();
            myStreamLink.CredentialsProvider = new PasswordCredentialsProvider("admin", "admin");

            IRecordSubscriptionListener subscriptionListener = new ExampleRecordSubscriptionListener();

            // All fields and filter
            string filter = "Bid>10";
            IRecordSubscriptionParameters recordParameters =
                myStreamLink.StreamLinkProvider.ParametersFactory.CreateRecordSubscriptionParameters(filter);

            IRecordSubscription subscription =
                myStreamLink.StreamLinkProvider.CreateRecordSubscription(subscriptionListener,
                                                                         "/DEMO/MSFT");

            subscription.Subscribe();

            myStreamLink.StreamLinkProvider.Connect();
        }
    }
}
See Also