public void Should_Process_Update_Message_With_More_Fields()
        {
            // Arrange
            var level1MessageDynamicHandler = new Level1MessageDynamicHandler();

            // set more fields that are currently used in UpdateSummaryMessage
            level1MessageDynamicHandler.SetDynamicFields(
                DynamicFieldset.Symbol,
                DynamicFieldset.MostRecentTrade,
                DynamicFieldset.MostRecentTradeSize,
                DynamicFieldset.MostRecentTradeTime,
                DynamicFieldset.MostRecentTradeMarketCenter,
                DynamicFieldset.TotalVolume,
                DynamicFieldset.Bid,
                DynamicFieldset.BidSize,
                DynamicFieldset.Ask,
                DynamicFieldset.AskSize,
                DynamicFieldset.Open,
                DynamicFieldset.High,
                DynamicFieldset.Low,
                DynamicFieldset.Close,
                DynamicFieldset.MessageContents,
                DynamicFieldset.MostRecentTradeConditions,
                DynamicFieldset.MostRecentTradeDate,
                DynamicFieldset.Volatility,
                DynamicFieldset.VWAP);
            var msg      = "Q,AAPL,123.0000,50,19:59:53.475143,11,0,123.0000,1700,123.0500,200,,,,123.0000,Cbacv,400142,04/01/2021,,0.0000,\r\n";
            var msgBytes = Encoding.ASCII.GetBytes(msg);
            var count    = msgBytes.Length;

            level1MessageDynamicHandler.Update += message => { };

            const int ExecutionsCount = 5;
            var       results         = new double[ExecutionsCount];

            for (int i = 0; i < ExecutionsCount; i++)
            {
                var sw = Stopwatch.StartNew();
                for (var j = 0; j < 1000000; j++)
                {
                    level1MessageDynamicHandler.ProcessMessages(msgBytes, count);
                }
                sw.Stop();

                results[i] = sw.Elapsed.TotalMilliseconds;
                Console.WriteLine(sw.Elapsed.TotalMilliseconds);
            }

            Console.WriteLine($"Min: {results.Min()}");
            Console.WriteLine($"Avg: {results.Average()}");
            Console.WriteLine($"Max: {results.Max()}");
        }
        public void Should_Throw_Exception_When_Dynamic_Field_Type_Requested()
        {
            // Arrange
            var level1DynamicHandler = new Level1MessageDynamicHandler();
            var fields = new[]
            {
                DynamicFieldset.Symbol,
                DynamicFieldset.Type
            };

            // Assert
            Assert.Throws <ArgumentException>(() => level1DynamicHandler.SetDynamicFields(fields));
        }
        public void Should_Process_Update_Message_With_Standard_Fields()
        {
            // Arrange
            var level1MessageDynamicHandler = new Level1MessageDynamicHandler();

            // set the exact fields that are currently used in good old UpdateSummaryMessage
            level1MessageDynamicHandler.SetDynamicFields(
                DynamicFieldset.Symbol,
                DynamicFieldset.MostRecentTrade,
                DynamicFieldset.MostRecentTradeSize,
                DynamicFieldset.MostRecentTradeTime,
                DynamicFieldset.MostRecentTradeMarketCenter,
                DynamicFieldset.TotalVolume,
                DynamicFieldset.Bid,
                DynamicFieldset.BidSize,
                DynamicFieldset.Ask,
                DynamicFieldset.AskSize,
                DynamicFieldset.Open,
                DynamicFieldset.High,
                DynamicFieldset.Low,
                DynamicFieldset.Close,
                DynamicFieldset.MessageContents,
                DynamicFieldset.MostRecentTradeConditions);
            var msg      = "Q,AAPL,322.7500,40,16:53:23.256494,11,37629453,322.6800,100,322.8700,100,312.6000,318.4000,312.1900,308.9500,ba,873D17,\r\n";
            var msgBytes = Encoding.ASCII.GetBytes(msg);
            var count    = msgBytes.Length;

            level1MessageDynamicHandler.Update += message => { };

            const int ExecutionsCount = 5;
            var       results         = new double[ExecutionsCount];

            for (int i = 0; i < ExecutionsCount; i++)
            {
                var sw = Stopwatch.StartNew();
                for (var j = 0; j < 1000000; j++)
                {
                    level1MessageDynamicHandler.ProcessMessages(msgBytes, count);
                }
                sw.Stop();

                results[i] = sw.Elapsed.TotalMilliseconds;
                Console.WriteLine(sw.Elapsed.TotalMilliseconds);
            }

            Console.WriteLine($"Min: {results.Min()}");
            Console.WriteLine($"Avg: {results.Average()}");
            Console.WriteLine($"Max: {results.Max()}");
        }
        public void Should_Process_Update_Message_With_Less_Fields()
        {
            // Arrange
            var level1MessageDynamicHandler = new Level1MessageDynamicHandler();

            // set less fields that are currently used in UpdateSummaryMessage
            level1MessageDynamicHandler.SetDynamicFields(
                DynamicFieldset.Symbol,
                DynamicFieldset.MostRecentTrade,
                DynamicFieldset.MostRecentTradeSize,
                DynamicFieldset.MostRecentTradeTime,
                DynamicFieldset.TotalVolume);
            var msg      = "Q,AAPL,123.0000,50,19:59:53.475143,0,\r\n";
            var msgBytes = Encoding.ASCII.GetBytes(msg);
            var count    = msgBytes.Length;

            level1MessageDynamicHandler.Update += message => { };

            const int ExecutionsCount = 5;
            var       results         = new double[ExecutionsCount];

            for (int i = 0; i < ExecutionsCount; i++)
            {
                var sw = Stopwatch.StartNew();
                for (var j = 0; j < 1000000; j++)
                {
                    level1MessageDynamicHandler.ProcessMessages(msgBytes, count);
                }
                sw.Stop();

                results[i] = sw.Elapsed.TotalMilliseconds;
                Console.WriteLine(sw.Elapsed.TotalMilliseconds);
            }

            Console.WriteLine($"Min: {results.Min()}");
            Console.WriteLine($"Avg: {results.Average()}");
            Console.WriteLine($"Max: {results.Max()}");
        }
 public void SetUp()
 {
     _level1MessageHandler = new Level1MessageDynamicHandler();
     _level1Client         = Level1ClientFactory.CreateNew(_level1MessageHandler);
     _level1Client.Connect();
 }