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

Contains interfaces, classes, and enums related to the Record SubjectType. Defines the key interfaces concerning record subscriptions (IRecordSubscription and IRecordSubscriptionListener), the interface that provides access to the parameters used to request records (IRecordSubscriptionParameters), and all record event interfaces.

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 type 1 data (simple fieldname+data pairs) in a record (SubjectType Record).

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

IRecordSubscriptionListener
The IRecordSubscriptionListener interface allows applications to receive events raised for a record subscription.

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

IRecordType2Event
Provides information about a change to type 2 data in a record (SubjectType Record).

IRecordType3Event
Provides information about a change to type 3 data in a record (SubjectType Record).

Remarks

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
            IStreamLink 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
    }
}

When creating a record subscription you can supply parameters defining the specific fields within the record that the application wishes to receive updates for. Parameters are created through the relevant factory methods of the ParametersFactory interface available through the ParametersFactory property of IStreamLinkProvider. The factory method returns an IRecordSubscriptionParameters object, which is passed to one of the CreateRecordSubscription methods of IStreamLinkProvider.

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
            IStreamLink 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 Caplin StreamLink Overview.

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()
        {
            IStreamLink 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