Ejemplo n.º 1
0
        public void AggregationTest()
        {
            var d      = new DateTime(1, 1, 1);
            var trades = new List <Trade>();
            var trade1 = Trade.Create(d, 3);

            trade1.Periods[0].Volume = 10.110001010102;
            trade1.Periods[1].Volume = 15;
            trade1.Periods[2].Volume = 10000000001;
            trades.Add(trade1);
            var trade2 = Trade.Create(d, 3);

            trade2.Periods[0].Volume = 3;
            trade2.Periods[1].Volume = 10.1100010101071;
            trade2.Periods[2].Volume = 10.110001010102;
            trades.Add(trade2);

            var extractor = new Extractor();
            SortedDictionary <int, double> aggr = null;

            try
            {
                aggr = extractor.AggregateTrades(trades);
            }
            catch (Exception ex)
            {
                Assert.Fail("AggregateTrades exception:" + ex.Message);
            }

            var delta = 0.000000000001; //trades come with 11 decimals

            Assert.IsNotNull(aggr, "Aggregations are empty");
            Assert.AreEqual(3, aggr.Count, "Aggregations size is invalid");
            Assert.AreEqual(13.110001010102, aggr[1], delta, "Aggregation volume is incorrect, period 1");
            Assert.AreEqual(25.1100010101071, aggr[2], delta, "Aggregation volume is incorrect, period 2");
            Assert.AreEqual(10000000011.110001010102, aggr[3], delta, "Aggregation volume is incorrect, period 3");
            extractor.Stop();
        }