Exemplo n.º 1
0
        private void HandleGetPrice(GetPrice query)
        {
            if (query.StockId != _stockId)
            {
                Sender.Tell(new GetPriceResult
                {
                    Reason = "StockId doesn't match"
                });
                return;
            }

            if (_orderStore.BestAsk.HasValue && _orderStore.BestBid.HasValue)
            {
                Sender.Tell(new GetPriceResult
                {
                    Success = true,
                    Ask     = _orderStore.BestAsk,
                    Bid     = _orderStore.BestBid,
                });
            }
            else
            {
                Sender.Tell(new GetPriceResult
                {
                    Reason = "Price is not available at the moment"
                });
            }
        }
Exemplo n.º 2
0
        public async Task Latest_Price_Returns_Null_Values_With_Reason(int bidUnits, decimal bidPrice, int askUnits, decimal askPrice)
        {
            //arrange
            var bid = NewBid(units: bidUnits, price: bidPrice);
            var ask = NewAsk(units: askUnits, price: askPrice);

            //act
            _matcher.Tell(bid);
            _matcher.Tell(ask);

            var message = new GetPrice()
            {
                StockId = StockId
            };
            var result = await _matcher.Ask <GetPriceResult>(message);

            //assert
            Assert.Null(result.Bid);
            Assert.Null(result.Ask);
            Assert.False(result.Success);
            Assert.Equal("Price is not available at the moment", result.Reason);
        }
Exemplo n.º 3
0
        public async Task Latest_Price_Returns_ExpectedData()
        {
            //arrange
            var bid = NewBid(units: 10, price: 100.00m);
            var ask = NewAsk(units: 10, price: 110.00m);

            //act
            _matcher.Tell(bid);
            _matcher.Tell(ask);

            var message = new GetPrice()
            {
                StockId = StockId
            };
            var result = await _matcher.Ask <GetPriceResult>(message);

            //assert
            Assert.Equal(100.00m, result.Bid);
            Assert.Equal(110.00m, result.Ask);
            Assert.True(result.Success);
            Assert.Null(result.Reason);
        }