コード例 #1
0
        /// <summary>
        /// Argument Constructor
        /// </summary>
        /// <param name="orderReportManager">Provides Order Reporting Data</param>
        /// <param name="profitLossReportManager">Provides Profit Loss Reprot Data</param>
        /// <param name="communicator">Handles incoming requests and outgoing data</param>
        public ApplicationController(OrderReportManager orderReportManager, ProfitLossReportManager profitLossReportManager, ICommunicator communicator)
        {
            // Save References
            _communicator            = communicator;
            _orderReportManager      = orderReportManager;
            _profitLossReportManager = profitLossReportManager;

            // Register Communicator Events
            RegisterCommunicatorEvents();

            // Register Report Manager Events
            RegisterReportManagerEvents();
        }
コード例 #2
0
        public void RequestProfitLossReportSymbol_AddTradesToDatabaseForTheIntendedReport_RetrieveResults_Successful_DeleteAddedEntries()
        {
            ITradeRepository tradeRespository = ContextRegistry.GetContext()["TradeRepository"] as ITradeRepository;
            var profitLossReportManager       = new ProfitLossReportManager(tradeRespository);

            var dataEventReceived = false;
            var manualDataEvent   = new ManualResetEvent(false);

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

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

            #region Add Trades to DB

            // 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, "FilterTestCaseZero", "C02",
                                        new Security()
                {
                    Symbol = "AAPL"
                }, 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, "FilterTestCaseOne", "C04",
                                        new Security()
                {
                    Symbol = "IBM"
                }, 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);

            #endregion

            // Add Filter Parameters
            arguments.Add(TradeParameters.Symbol, "GOOG,AAPL");

            // Hook Data Event
            profitLossReportManager.DataReceived += delegate(ProfitLossStats obj)
            {
                report            = obj;
                dataEventReceived = true;
                manualDataEvent.Set();
            };

            // Request Report Data
            profitLossReportManager.RequestReport(arguments);

            manualDataEvent.WaitOne(10000);

            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);
            }
        }
コード例 #3
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;
            var profitLossReportManager       = new ProfitLossReportManager(tradeRespository);

            // 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 (_communicator != null)
            {
                var manualReportEvent = new ManualResetEvent(false);

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

                // Request Profit Loss Report
                _communicator.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);
            }
        }