Ejemplo n.º 1
0
        public void Delete_createAndDelete_emptyList()
        {
            IInstrumBL    instrumBL    = new InstrumBLMock();
            ITickSourceDA tickSourceDA = new TickSourceDAMock();
            ITickSourceBL tickSourceBL = new TickSourceBL(instrumBL, tickSourceDA, null, null);

            var ts = new TickSource(instrumBL, null, null);

            ts.Name      = "наименование";
            ts.StartDate = new DateTime(2010, 1, 1);
            ts.EndDate   = new DateTime(2010, 12, 31);
            ts.Timeframe = Timeframes.Hour;
            ts.AddInstrum(1);
            ts.AddInstrum(2);
            ts.AddInstrum(3);
            tickSourceBL.SaveTickSource(ts); // insert

            var list = tickSourceBL.GetTickSourceList().ToList();

            Assert.Single(list);

            tickSourceBL.DeleteTickSourceByID(ts.TickSourceID);

            var list1 = tickSourceBL.GetTickSourceList().ToList();

            Assert.Empty(list1);
        }
Ejemplo n.º 2
0
        public void SaveGet_insert_getEqualTickSource()
        {
            IInstrumBL    instrumBL    = new InstrumBLMock();
            ITickSourceDA tickSourceDA = new TickSourceDAMock();
            TickSourceBL  tickSourceBL = new TickSourceBL(instrumBL, tickSourceDA, null, null);

            var ts0 = new TickSource(instrumBL, null, null);

            ts0.Name      = "наименование";
            ts0.StartDate = new DateTime(2010, 1, 1);
            ts0.EndDate   = new DateTime(2010, 12, 31);
            ts0.Timeframe = Timeframes.Hour;
            ts0.AddInstrum(1);
            ts0.AddInstrum(2);
            ts0.AddInstrum(3);
            tickSourceBL.SaveTickSource(ts0);

            var ts = tickSourceBL.GetTickSourceByID(ts0.TickSourceID);

            Assert.Equal(ts0.TickSourceID, ts.TickSourceID);
            Assert.Equal(ts0.Name, ts.Name);
            Assert.Equal(ts0.StartDate, ts.StartDate);
            Assert.Equal(ts0.EndDate, ts.EndDate);
            Assert.Equal(ts0.Timeframe, ts.Timeframe);

            string ids0 = string.Join(',', ts0.GetInstrums().Select(r => r.InsID.ToString()).OrderBy(r => r));
            string ids  = string.Join(',', ts.GetInstrums().Select(r => r.InsID.ToString()).OrderBy(r => r));

            Assert.Equal(ids0, ids);
        }
Ejemplo n.º 3
0
        public PositionBLTest()
        {
            var insBL = new InstrumBLMock();
            var posDA = new PositionDAMock();

            _positionBL = new PositionBL(posDA, insBL);
        }
Ejemplo n.º 4
0
        public void SerializeInitialize_tsclone_equalCloned()
        {
            IInstrumBL instrumBL = new InstrumBLMock();
            TickSource ts        = new TickSource(instrumBL, null, null);

            ts.Name      = "наименование";
            ts.StartDate = new DateTime(2010, 1, 1);
            ts.EndDate   = new DateTime(2010, 12, 31);
            ts.Timeframe = Timeframes.Min;
            ts.AddInstrum(1);
            ts.AddInstrum(2);
            ts.AddInstrum(3);

            var xdoc = ts.Serialize();
            var ts1  = new TickSource(instrumBL, null, null);

            ts1.Initialize(xdoc);

            Assert.Equal(ts.StartDate, ts1.StartDate);
            Assert.Equal(ts.EndDate, ts1.EndDate);
            Assert.Equal(ts.Timeframe, ts1.Timeframe);
            var ts1_instrums = ts1.GetInstrums();

            Assert.Equal(3, ts1_instrums.Count());
            Assert.Contains(ts1_instrums, r => r.InsID == 1);
            Assert.Contains(ts1_instrums, r => r.InsID == 2);
            Assert.Contains(ts1_instrums, r => r.InsID == 3);
        }
Ejemplo n.º 5
0
        public void RefreshPositions_()
        {
            // обработка сделок в правильном порядке в соответствии с их временем
            // в тесте специально сделки идут не по порядку
            PosDAMock   posDAMock = new PosDAMock();
            var         insBL     = new InstrumBLMock();
            IPositionBL posBL     = new PositionBL(posDAMock, insBL);

            posBL.RefreshPositions(1);

            var pos = posBL.GetAllPositions(1).ElementAt(0);

            Assert.Equal(PosTypes.Long, pos.PosType);
            Assert.Equal(100, pos.OpenPrice);
            Assert.Equal(110, pos.ClosePrice);
        }
Ejemplo n.º 6
0
        public void ParseXml_attrCharCaseAndCommaDecSeparator_correctAttributes()
        {
            InstrumBLMock instrumBL    = new InstrumBLMock();
            TradesLoader  importTrades = new TradesLoader(instrumBL, null);

            IEnumerable <Trade> trades;
            XmlDocument         xd = new XmlDocument();

            xd.LoadXml("<Trades><Trade TiMe=\"01.02.2010 10:20:30\" TIckeR=\"ticker1\" pRice=\"100,00\" lotS=\"10\" bS=\"buy\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.NotEmpty(trades);
            Trade trade = trades.ElementAt(0);

            Assert.Equal(new DateTime(2010, 2, 1, 10, 20, 30), trade.Time);
            Assert.Equal(100.00m, trade.Price);
            Assert.Equal(10, trade.LotCount);
            Assert.Equal(BuySell.Buy, trade.BuySell);
            Assert.Equal(1, trade.InsID);
        }
Ejemplo n.º 7
0
        public void SerializeInitialize_tsWithEmptyInstrums_clonedWithEmptyInstrums()
        {
            IInstrumBL instrumBL = new InstrumBLMock();
            TickSource ts        = new TickSource(instrumBL, null, null);

            ts.Name      = "наименование";
            ts.StartDate = new DateTime(2010, 1, 1);
            ts.EndDate   = new DateTime(2010, 12, 31);
            ts.Timeframe = Timeframes.Min;

            var xdoc = ts.Serialize();
            var ts1  = new TickSource(instrumBL, null, null);

            ts1.Initialize(xdoc);

            var ts1_instrums = ts1.GetInstrums();

            Assert.Empty(ts1_instrums);
        }
Ejemplo n.º 8
0
        public void ParseXml_incorrectXml_emptyTradeList()
        {
            InstrumBLMock instrumBL    = new InstrumBLMock();
            TradesLoader  importTrades = new TradesLoader(instrumBL, null);

            IEnumerable <Trade> trades;

            // null argument
            Assert.Throws <ArgumentNullException>(() => { importTrades.ParseXml(null); });

            // empty xml
            XmlDocument xd = new XmlDocument();

            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // incorrect root element
            xd.LoadXml("<aaa />");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // empty trade list
            xd.LoadXml("<Trades />");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // no trade node
            xd.LoadXml("<Trades><aaa /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // empty trade node
            xd.LoadXml("<Trades><Trade /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);
        }
Ejemplo n.º 9
0
        public void ParseXml_incorrectTradeNode_emptyTradeList()
        {
            InstrumBLMock instrumBL    = new InstrumBLMock();
            TradesLoader  importTrades = new TradesLoader(instrumBL, null);

            IEnumerable <Trade> trades;
            XmlDocument         xd = new XmlDocument();

            // не все атрибуты есть
            xd.LoadXml("<Trades><Trade /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // Time есть, но он пустой
            xd.LoadXml("<Trades><Trade Time=\"\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // Time неверного формата
            xd.LoadXml("<Trades><Trade Time=\"qqqwwweee\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // Time неверного формата
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:90\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // Нет тикера
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // пустой тикер
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // неверный тикер
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"hello\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // нет цены
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // неверная цена
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // неверная цена
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"qqq.www\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // нет lots
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // пустой lots
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" Lots=\"\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // неверный lots
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" Lots=\"qqq\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // дробный lots
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" Lots=\"10.15\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // нет bs
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" Lots=\"10\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // пустой bs
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" Lots=\"10\" BS=\"\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // неверный bs
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" Lots=\"10\" BS=\"hello\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.Empty(trades);

            // все верно
            xd.LoadXml("<Trades><Trade Time=\"01.02.2010 10:20:30\" Ticker=\"ticker1\" Price=\"100.00\" Lots=\"10\" BS=\"buy\" /></Trades>");
            trades = importTrades.ParseXml(xd);
            Assert.NotEmpty(trades);
            Trade trade = trades.ElementAt(0);

            Assert.Equal(new DateTime(2010, 2, 1, 10, 20, 30), trade.Time);
            Assert.Equal(100.00m, trade.Price);
            Assert.Equal(10, trade.LotCount);
            Assert.Equal(BuySell.Buy, trade.BuySell);
            Assert.Equal(1, trade.InsID);
        }