Example #1
0
        public void AddTrade_noPos_twoPosTrades()
        {
            var      ins   = instrumBL.GetInstrumByID(1);
            PosTable table = new PosTable(instrumBL);

            Trade t1 = new Trade()
            {
                TradeID = 1, InsID = ins.InsID, OrderID = 2, Time = new DateTime(2012, 1, 1, 10, 30, 35), Price = 110m, LotCount = 25, BuySell = BuySell.Buy
            };

            table.AddTrade(t1);

            var positions1 = table.GetPositions().ToList();
            var posTrades1 = table.GetPosTrades().ToList();

            Assert.Single(positions1);
            Assert.Single(posTrades1);
            Assert.True(posTrades1[0].TradeID == t1.TradeID && posTrades1[0].PosID == positions1[0].PosID);

            Trade t2 = new Trade()
            {
                TradeID = 2, InsID = ins.InsID, OrderID = 3, Time = new DateTime(2012, 1, 1, 10, 30, 40), Price = 100m, LotCount = 25, BuySell = BuySell.Sell
            };

            table.AddTrade(t2);
            var positions2 = table.GetPositions().ToList();
            var posTrades2 = table.GetPosTrades().ToList();

            Assert.Single(positions2);
            Assert.True(posTrades2.Count == 2);
            Assert.Single(posTrades2.Where(r => r.TradeID == t1.TradeID && r.PosID == positions1[0].PosID));
            Assert.Single(posTrades2.Where(r => r.TradeID == t2.TradeID && r.PosID == positions1[0].PosID));
        }