GreeksFeedHandlerExample - SpiderRock/SRDataFeed GitHub Wiki

Below is an example of a Greeks feed handler that subscribes to the create and update events of the following message types: LiveSurfaceAtm, OptionImpliedQuote, OptionCloseMark, OptionCloseQuote, OptionSettlementMark, OptionOpenMark. Create events will only fire once for each key and the update events will fire on every change. The args argument in the update event handlers has a Current and Previous properties that have the respective states of the object. The Previous property is null for the initial instance of the object.

using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net;
using SpiderRock.DataFeed;
using SpiderRock.DataFeed.Diagnostics;
 
namespace GreeksFeedHandlerExample
{
    internal class Program
    {
        private static void Main()
        {
            SRDataFeedEngine engine = null;
 
            try
            {
                engine = new SRDataFeedEngine
                {
                    SysEnvironment = SysEnvironment.Stable,
                    IFAddress = IPAddress.Parse("local.adapter.interface.address"),
                    CacheHost = "198.102.4.145",
                    CachePort = 3340,
                    Channels = new[] {UdpChannel.ImpliedQuoteNms}
                };
                SRTrace.GlobalSwitch = new SourceSwitch("SRTraceSource (All)") {Level = SourceLevels.All};
                SRTrace.AddGlobalTraceListener(new SRFileTraceListener());
                SRTrace.AddGlobalTraceListener(new SRConsoleTraceListener());
 
                var handler = new Handler();
 
                engine.LiveSurfaceAtmCreated += handler.OnCreate;
                engine.LiveSurfaceAtmUpdated += handler.OnUpdate;
 
                engine.OptionImpliedQuoteCreated += handler.OnCreate;
                engine.OptionImpliedQuoteUpdated += handler.OnUpdate;
 
                engine.OptionCloseMarkCreated += handler.OnCreate;
                engine.OptionCloseMarkUpdated += handler.OnUpdate;
 
                engine.OptionCloseQuoteCreated += handler.OnCreate;
                engine.OptionCloseQuoteUpdated += handler.OnUpdate;
 
                engine.OptionSettlementMarkCreated += handler.OnCreate;
                engine.OptionSettlementMarkUpdated += handler.OnUpdate;
 
                engine.OptionOpenMarkCreated += handler.OnCreate;
                engine.OptionOpenMarkUpdated += handler.OnUpdate;
 
                engine.Start();
 
                TimeSpan timeout = TimeSpan.FromMinutes(1);
 
                MessageType[] messageTypesToRequest =
                {
                    MessageType.LiveSurfaceAtm,
                    MessageType.OptionImpliedQuote,
                    MessageType.OptionCloseMark,
                    MessageType.OptionCloseQuote,
                    MessageType.OptionSettlementMark,
                    MessageType.OptionOpenMark
                };
 
                if (!engine.GetCachedMessages(timeout, messageTypesToRequest))
                {
                    throw new TimeoutException("Cache request timed out");
                }
 
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Cache request error: {0}", e);
                Console.ReadLine();
            }
            finally
            {
                if (engine != null)
                {
                    engine.Dispose();
                }
            }
        }
    }
 
    public class Handler
    {
        #region OptionImpliedQuote handling
 
        public void OnCreate(object sender, CreatedEventArgs<OptionImpliedQuote> args)
        {
        }
 
        public void OnUpdate(object sender, UpdatedEventArgs<OptionImpliedQuote> args)
        {
        }
 
        #endregion
 
        #region LiveSurfaceAtm handling
 
        public void OnCreate(object sender, CreatedEventArgs<LiveSurfaceAtm> args)
        {
        }
 
        public void OnUpdate(object sender, UpdatedEventArgs<LiveSurfaceAtm> args)
        {
        }
 
        #endregion
 
        #region OptionCloseMark handling
 
        public void OnCreate(object sender, CreatedEventArgs<OptionCloseMark> args)
        {
        }
 
        public void OnUpdate(object sender, UpdatedEventArgs<OptionCloseMark> args)
        {
        }
 
        #endregion
 
        #region OptionCloseQuote handling
 
        public void OnCreate(object sender, CreatedEventArgs<OptionCloseQuote> args)
        {
        }
 
        public void OnUpdate(object sender, UpdatedEventArgs<OptionCloseQuote> args)
        {
        }
 
        #endregion
 
        #region OptionSettlementMark handling
 
        public void OnCreate(object sender, CreatedEventArgs<OptionSettlementMark> args)
        {
        }
 
        public void OnUpdate(object sender, UpdatedEventArgs<OptionSettlementMark> args)
        {
        }
 
        #endregion
 
        #region OptionOpenMark handling
 
        public void OnCreate(object sender, CreatedEventArgs<OptionOpenMark> args)
        {
        }
 
        public void OnUpdate(object sender, UpdatedEventArgs<OptionOpenMark> args)
        {
        }
 
        #endregion
    }
}