/// <summary>
 /// Called when a publisher has committed an event to the <see cref="T:Disruptor.RingBuffer`1"/>
 /// </summary>
 /// <param name="data">Data committed to the <see cref="T:Disruptor.RingBuffer`1"/></param><param name="sequence">Sequence number committed to the <see cref="T:Disruptor.RingBuffer`1"/></param><param name="endOfBatch">flag to indicate if this is the last event in a batch from the <see cref="T:Disruptor.RingBuffer`1"/></param>
 public void OnNext(Dictionary <TradeParameters, string> data, long sequence, bool endOfBatch)
 {
     // Send Request to Client
     _reportingEngineClient.RequestProfitLossReport(data);
 }
Ejemplo n.º 2
0
        public void RequestProfitLossReport_AddTradesToDatabaseForTheIntendedReport__RetrieveResults_Successful_DeleteAddedEntries()
        {
            var dataEventReceived = false;

            ProfitLossStats report    = null;
            var             arguments = new Dictionary <TradeParameters, string>();

            #region Insert Trade Data in DB

            ITradeRepository tradeRespository = ContextRegistry.GetContext()["TradeRepository"] as ITradeRepository;

            // Contains Trades which are created in the Test Case
            IList <Trade> localTradesList = new List <Trade>();

            // Save New Trade
            {
                Trade trade = new Trade(TradeSide.Buy, 20, 113, "FilterTestCase", "C00", new Security()
                {
                    Symbol = "GOOG"
                }, new DateTime(2015, 01, 21, 18, 20, 57));
                trade.CompletionTime = new DateTime(2015, 01, 21, 18, 20, 58);

                Dictionary <string, int> executionDetails = new Dictionary <string, int>();
                executionDetails.Add("C00", 20);
                executionDetails.Add("C01", -20);

                trade.ExecutionDetails = executionDetails;

                //add Trade to database
                tradeRespository.AddUpdate(trade);

                // Add to list
                localTradesList.Add(trade);
            }

            // Save New Trade
            {
                Trade trade = new Trade(TradeSide.Sell, 20, 113, "FilterTestCase", "C02", new Security()
                {
                    Symbol = "GOOG"
                }, new DateTime(2015, 01, 21, 18, 20, 58));
                trade.CompletionTime = new DateTime(2015, 01, 21, 18, 20, 59);

                Dictionary <string, int> executionDetails = new Dictionary <string, int>();
                executionDetails.Add("C02", -20);
                executionDetails.Add("C03", 20);

                trade.ExecutionDetails = executionDetails;

                //add Trade to database
                tradeRespository.AddUpdate(trade);

                // Add to list
                localTradesList.Add(trade);
            }

            // Save New Trade
            {
                Trade trade = new Trade(TradeSide.Buy, 20, 113, "FilterTestCase", "C04", new Security()
                {
                    Symbol = "GOOG"
                }, new DateTime(2015, 01, 21, 18, 20, 59));
                trade.CompletionTime = new DateTime(2015, 01, 21, 18, 21, 00);

                Dictionary <string, int> executionDetails = new Dictionary <string, int>();
                executionDetails.Add("C04", 20);
                executionDetails.Add("C05", -20);

                trade.ExecutionDetails = executionDetails;

                //add Trade to database
                tradeRespository.AddUpdate(trade);

                // Add to list
                localTradesList.Add(trade);
            }

            // Wait for Transactions to complete
            Thread.Sleep(1000);

            // Add Filter Parameters
            arguments.Add(TradeParameters.TradeSide, Convert.ChangeType(TradeSide.Buy, TradeSide.Buy.GetTypeCode()).ToString());
            arguments.Add(TradeParameters.TradeSize, "20");
            arguments.Add(TradeParameters.StartTime, "2015-01-21 18:20:57");
            arguments.Add(TradeParameters.CompletionTime, "2015-01-21 18:21:00");
            arguments.Add(TradeParameters.ExecutionProvider, "FilterTestCase");

            #endregion

            if (_reportingEngineClient != null)
            {
                var manualReportEvent = new ManualResetEvent(false);

                // Hook Event
                _reportingEngineClient.ProfitLossReportReceivedEvent += delegate(ProfitLossStats obj)
                {
                    report            = obj;
                    dataEventReceived = true;
                    manualReportEvent.Set();
                };

                // Request Profit Loss Report
                _reportingEngineClient.RequestProfitLossReport(arguments);

                manualReportEvent.WaitOne(3000, false);
            }

            Assert.IsNotNull(report);
            Assert.IsTrue(dataEventReceived, "Report Event");
            Assert.AreEqual(2, report.Trades.Count, "Return Count");

            // Delete Trades Generated for Test Case
            foreach (Trade trade in localTradesList)
            {
                tradeRespository.Delete(trade);
            }
        }