예제 #1
0
        public void TradeCruld()
        {
            bool   saved = false;
            string id    = DateTime.Now.ToString();
            Trade  trade = new Trade(TradeSide.Buy, 20, 113, OrderExecutionProvider.Simulated, "A00", new Security()
            {
                Symbol = "GOOG"
            }, new DateTime(2015, 01, 21, 18, 20, 57));

            Dictionary <string, int> executionDetails = new Dictionary <string, int>();

            executionDetails.Add("A00", 20);
            executionDetails.Add("A01", -20);

            trade.ExecutionDetails = executionDetails;

            var tradeSaved = new ManualResetEvent(false);

            //get Trades
            IList <Trade> getTrade          = _tradeRespository.ListAll();
            int           initialTradeCount = getTrade.Count;

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

            Thread.Sleep(2000);

            //get Trades
            getTrade = _tradeRespository.ListAll();
            if (getTrade.Count.Equals(initialTradeCount + 1))
            {
                saved = true;
                tradeSaved.Set();
            }

            Assert.IsTrue(getTrade.Last().ExecutionDetails["A00"].Equals(20), "Matching Trade");
            Assert.IsTrue(getTrade.Last().Security.Symbol.Equals("GOOG"), "Matching Trade Symbol");

            tradeSaved.WaitOne(30000);
            //delete the order
            _tradeRespository.Delete(getTrade.Last());

            //get ther order again to verify its deleted or not
            getTrade = _tradeRespository.ListAll();
            Assert.AreEqual(getTrade.Count, initialTradeCount, "Trade Count after Delete");
        }
예제 #2
0
        public IActionResult Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var trade = Repo.Delete(id);

            if (trade == null)
            {
                return(NotFound());
            }
            return(Ok(trade));
        }
예제 #3
0
 public void Delete(int id)
 {
     _tradeRepo.Delete(id);
     _tradeRepo.SaveChanges();
 }
        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);
            }
        }
예제 #5
0
 public void Delete(int Id)
 {
     _tradeRepository.Delete(Id);
 }
        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 (_reportingEngineService != null)
            {
                var manualReportEvent = new ManualResetEvent(false);

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

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