コード例 #1
0
        public void AddVolumeToDepthLevel_IfVolumeAddedSuccessfully_ReturnsTrueCountsAggregatedVolumeAndOrderCount()
        {
            DepthLevel depthLevel = new DepthLevel(new Price(491.32M));
            bool       addOrder1  = depthLevel.AddOrder(new Volume(2000));
            bool       addOrder2  = depthLevel.AddOrder(new Volume(1000));

            Assert.IsTrue(addOrder1);
            Assert.IsTrue(addOrder2);
            Assert.AreEqual(3000, depthLevel.AggregatedVolume.Value, "Aggregated Volume after addition");
            Assert.AreEqual(2, depthLevel.OrderCount, "Order Count after addition");
        }
コード例 #2
0
        public void IncreaseTheQuantity_IfIncreased_AggregatedVolumeIsAsExpected()
        {
            DepthLevel depthLevel = new DepthLevel(new Price(491.32M));
            bool       addOrder1  = depthLevel.AddOrder(new Volume(2000));
            bool       addOrder2  = depthLevel.AddOrder(new Volume(1000));

            Assert.IsTrue(addOrder1);
            Assert.IsTrue(addOrder2);
            Assert.AreEqual(3000, depthLevel.AggregatedVolume.Value, "Aggregated Volume after addition");
            Assert.AreEqual(2, depthLevel.OrderCount, "Order Count after addition");

            bool removeOrder1 = depthLevel.IncreaseVolume(new Volume(500));

            Assert.IsTrue(removeOrder1);
            Assert.AreEqual(3500, depthLevel.AggregatedVolume.Value, "Aggregated Volume after decrease");
            Assert.AreEqual(2, depthLevel.OrderCount, "Order Count after decrease");
        }
コード例 #3
0
        public void RemoveVolumeFromDepthLevel_IfVolumeRemoved_ReturnsTrueChecksVolumeAndOrderCount()
        {
            DepthLevel depthLevel = new DepthLevel(new Price(491.32M));
            bool       addOrder1  = depthLevel.AddOrder(new Volume(2000));
            bool       addOrder2  = depthLevel.AddOrder(new Volume(1000));

            Assert.IsTrue(addOrder1);
            Assert.IsTrue(addOrder2);
            Assert.AreEqual(3000, depthLevel.AggregatedVolume.Value, "Aggregated Volume after addition");
            Assert.AreEqual(2, depthLevel.OrderCount, "Order Count after addition");

            bool removeOrder1 = depthLevel.CloseOrder(new Volume(500));

            Assert.IsFalse(removeOrder1);
            Assert.AreEqual(2500, depthLevel.AggregatedVolume.Value, "Aggregated Volume after removal");
            Assert.AreEqual(1, depthLevel.OrderCount, "Order Count after removal");
        }
コード例 #4
0
        public void PublishBboToDisruptor_IfBboIsConvertedToByteArray_ItShouldBeReceivedAndCastedToBbo()
        {
            DepthLevel askDepthLevel = new DepthLevel(new Price(491.32M));
            bool       addOrder1     = askDepthLevel.AddOrder(new Volume(2000));
            bool       addOrder2     = askDepthLevel.AddOrder(new Volume(1000));
            DepthLevel bidDepthLevel = new DepthLevel(new Price(491.32M));

            addOrder1 = bidDepthLevel.AddOrder(new Volume(2000));
            addOrder2 = bidDepthLevel.AddOrder(new Volume(1000));
            bool addOrder3 = bidDepthLevel.AddOrder(new Volume(3000));
            BBO  bbo       = new BBO("BTCUSD", bidDepthLevel, askDepthLevel);

            //byte[] array = ObjectToByteArray(bbo);
            OutputDisruptor.Publish(bbo);
            _manualResetEvent.WaitOne(3000);
            Assert.NotNull(_receivedBbo);
            Assert.AreEqual(_receivedBbo.BestAsk.OrderCount, 2);
            Assert.AreEqual(_receivedBbo.BestBid.OrderCount, 3);
        }
コード例 #5
0
        public void PublishAllTypesToOutputDisruptor_IfAllTypesAreConvertedToByteArray_ItShouldReceivedAndProperlyCasted()
        {
            Order order = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "buy", 5, 0,
                                                   new StubbedOrderIdGenerator());

            //byte[] array = ObjectToByteArray(order);
            OutputDisruptor.Publish(order);

            Order buyOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "limit", "buy", 5, 10,
                                                      new StubbedOrderIdGenerator());
            Order sellOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "limit", "sell", 5, 11,
                                                       new StubbedOrderIdGenerator());
            Trade trade = new Trade(new TradeId("123"), "XBTUSD", new Price(100), new Volume(10), DateTime.Now, buyOrder, sellOrder);

            //byte[] array1 = ObjectToByteArray(trade);
            OutputDisruptor.Publish(trade);

            LimitOrderBook limitOrderBook = new LimitOrderBook("XBTUSD");

            limitOrderBook.PlaceOrder(buyOrder);
            limitOrderBook.PlaceOrder(sellOrder);
            //byte[] array2 = ObjectToByteArray(limitOrderBook);
            OutputDisruptor.Publish(limitOrderBook);

            Depth depth = new Depth("XBTUSD", 3);

            depth.AddOrder(new Price(490), new Volume(100), OrderSide.Buy);
            depth.AddOrder(new Price(491), new Volume(100), OrderSide.Buy);
            depth.AddOrder(new Price(492), new Volume(200), OrderSide.Buy);
            //byte[] array3 = ObjectToByteArray(depth);
            OutputDisruptor.Publish(depth);

            DepthLevel askDepthLevel = new DepthLevel(new Price(491.32M));
            bool       addOrder1     = askDepthLevel.AddOrder(new Volume(2000));
            bool       addOrder2     = askDepthLevel.AddOrder(new Volume(1000));
            DepthLevel bidDepthLevel = new DepthLevel(new Price(491.32M));

            addOrder1 = bidDepthLevel.AddOrder(new Volume(2000));
            addOrder2 = bidDepthLevel.AddOrder(new Volume(1000));
            bool addOrder3 = bidDepthLevel.AddOrder(new Volume(3000));
            BBO  bbo       = new BBO("XBTUSD", bidDepthLevel, askDepthLevel);

            //byte[] array4 = ObjectToByteArray(bbo);
            OutputDisruptor.Publish(bbo);
            _manualResetEvent.WaitOne(3000);

            Assert.NotNull(_receviedOrder);
            Assert.AreEqual(_receviedOrder, order);

            Assert.NotNull(_receivedTrade);
            Assert.AreEqual(_receivedTrade.BuyOrder, buyOrder);
            Assert.AreEqual(_receivedTrade.SellOrder, sellOrder);

            Assert.NotNull(_receivedLimitOrderBook);
            Assert.AreEqual(_receivedLimitOrderBook.AskCount, 1);
            Assert.AreEqual(_receivedLimitOrderBook.BidCount, 1);

            Assert.NotNull(_receivedDepth);
            Assert.AreEqual(_receivedDepth.BidLevels[0].Price.Value, 492);
            Assert.AreEqual(_receivedDepth.BidLevels[1].Price.Value, 491);
            Assert.AreEqual(_receivedDepth.BidLevels[2].Price.Value, 490);

            Assert.NotNull(_receivedBbo);
            Assert.AreEqual(_receivedBbo.BestAsk.OrderCount, 2);
            Assert.AreEqual(_receivedBbo.BestBid.OrderCount, 3);
        }