public void GetRatesTest_ChecksTheRatesForAllCurrencyPairsSubmittingDepthLevels_ChecksTheRatesReturnedToVerify()
        {
            MarketController marketController = (MarketController)_applicationContext["MarketController"];
            BBOMemoryImage   bboMemoryImage   = (BBOMemoryImage)_applicationContext["BBOMemoryImage"];

            DepthLevel xbtUsdBidLevel = new DepthLevel(new Price(491));
            DepthLevel ltcUsdBidLevel = new DepthLevel(new Price(492));
            DepthLevel btcUsdBidLevel = new DepthLevel(new Price(493));

            DepthLevel xbtUsdAskLevel = new DepthLevel(new Price(494));
            DepthLevel ltcUsdAskLevel = new DepthLevel(new Price(495));
            DepthLevel btcUsdAskLevel = new DepthLevel(new Price(496));

            bboMemoryImage.OnBBOArrived("XBT/USD", xbtUsdBidLevel, xbtUsdAskLevel);
            bboMemoryImage.OnBBOArrived("LTC/USD", ltcUsdBidLevel, ltcUsdAskLevel);
            bboMemoryImage.OnBBOArrived("BTC/USD", btcUsdBidLevel, btcUsdAskLevel);
            IHttpActionResult httpActionResult = marketController.GetAllRates();

            OkNegotiatedContentResult <RatesList> returnedOkRate = (OkNegotiatedContentResult <RatesList>)httpActionResult;
            RatesList ratesList = returnedOkRate.Content;

            Assert.AreEqual("XBT/USD", ratesList.ToList()[0].CurrencyPair);
            Assert.AreEqual(492.5, ratesList.ToList()[0].RateValue); // MidPoint of xbtUsdBidLevel = 491 & xbtUsdAskLevel = 494
            Assert.AreEqual("LTC/USD", ratesList.ToList()[1].CurrencyPair);
            Assert.AreEqual(493.5, ratesList.ToList()[1].RateValue); // MidPoint of ltcUsdBidLevel = 492 & ltcUsdAskLevel = 495
            Assert.AreEqual("BTC/USD", ratesList.ToList()[2].CurrencyPair);
            Assert.AreEqual(494.5, ratesList.ToList()[2].RateValue); // MidPoint of btcUsdBidLevel = 493 & btcUsdAskLevel = 496
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 public MarketDataQueryService(OrderBookMemoryImage orderBookMemoryImage, DepthMemoryImage depthMemoryImage,
                               BBOMemoryImage bboMemoryImage, IOhlcRepository ohlcRepository, TickerInfoService tickerInfoService)
 {
     _orderBookMemoryImage = orderBookMemoryImage;
     _depthMemoryImage     = depthMemoryImage;
     _bboMemoryImage       = bboMemoryImage;
     _ohlcRepository       = ohlcRepository;
     _tickerInfoService    = tickerInfoService;
 }
        public void GetRateTest_ChecksTheRateForTheGivenCurrencyPairAfterSubmittingDepthLevels_ChecksTheRateReturnedToVerify()
        {
            MarketController marketController = (MarketController)_applicationContext["MarketController"];
            BBOMemoryImage   bboMemoryImage   = (BBOMemoryImage)_applicationContext["BBOMemoryImage"];

            DepthLevel bidLevel1 = new DepthLevel(new Price(491));
            DepthLevel bidLevel2 = new DepthLevel(new Price(492));
            DepthLevel bidLevel3 = new DepthLevel(new Price(493));

            DepthLevel askLevel1 = new DepthLevel(new Price(494));
            DepthLevel askLevel2 = new DepthLevel(new Price(495));
            DepthLevel askLevel3 = new DepthLevel(new Price(496));

            bboMemoryImage.OnBBOArrived("XBT/USD", bidLevel1, askLevel1);
            IHttpActionResult httpActionResult = marketController.GetRate("XBT/USD");

            OkNegotiatedContentResult <Rate> returnedOkRate = (OkNegotiatedContentResult <Rate>)httpActionResult;
            Rate rate = returnedOkRate.Content;

            Assert.AreEqual("XBT/USD", rate.CurrencyPair);
            Assert.AreEqual(492.5, rate.RateValue); // MidPoint of bidLevel1 = 491 & askLevel1 = 494

            bboMemoryImage.OnBBOArrived("XBT/USD", bidLevel2, askLevel2);
            httpActionResult = marketController.GetRate("XBT/USD");
            returnedOkRate   = (OkNegotiatedContentResult <Rate>)httpActionResult;
            rate             = returnedOkRate.Content;

            Assert.AreEqual("XBT/USD", rate.CurrencyPair);
            Assert.AreEqual(493.5, rate.RateValue); // MidPoint of bidLevel2 = 492 & askLevel2 = 495

            bboMemoryImage.OnBBOArrived("XBT/USD", bidLevel3, askLevel3);
            httpActionResult = marketController.GetRate("XBT/USD");
            returnedOkRate   = (OkNegotiatedContentResult <Rate>)httpActionResult;
            rate             = returnedOkRate.Content;

            Assert.AreEqual("XBT/USD", rate.CurrencyPair);
            Assert.AreEqual(494.5, rate.RateValue); // MidPoint of bidLevel3 = 493 & askLevel3 = 496
        }
        public void AddRatesForMultiplkeCurrenciesTest_AddRatesForMultipleCurrenciesAndExpectsAListOfRates_VerifiesThroughTheReturnedRateList()
        {
            BBOMemoryImage bboMemoryImage = new BBOMemoryImage();

            DepthLevel xbtUsdBidLevel = new DepthLevel(new Price(491));
            DepthLevel ltcUsdBidLevel = new DepthLevel(new Price(492));
            DepthLevel btcUsdBidLevel = new DepthLevel(new Price(493));

            DepthLevel xbtUsdAskLevel = new DepthLevel(new Price(494));
            DepthLevel ltcUsdAskLevel = new DepthLevel(new Price(495));
            DepthLevel btcUsdAskLevel = new DepthLevel(new Price(496));

            bboMemoryImage.OnBBOArrived("XBT/USD", xbtUsdBidLevel, xbtUsdAskLevel);
            bboMemoryImage.OnBBOArrived("LTC/USD", ltcUsdBidLevel, ltcUsdAskLevel);
            bboMemoryImage.OnBBOArrived("BTC/USD", btcUsdBidLevel, btcUsdAskLevel);

            Assert.AreEqual("XBT/USD", bboMemoryImage.RatesList.ToList()[0].CurrencyPair);
            Assert.AreEqual(492.5, bboMemoryImage.RatesList.ToList()[0].RateValue); // MidPoint of xbtUsdBidLevel = 491 & xbtUsdAskLevel = 494
            Assert.AreEqual("LTC/USD", bboMemoryImage.RatesList.ToList()[1].CurrencyPair);
            Assert.AreEqual(493.5, bboMemoryImage.RatesList.ToList()[1].RateValue); // MidPoint of ltcUsdBidLevel = 492 & ltcUsdAskLevel = 495
            Assert.AreEqual("BTC/USD", bboMemoryImage.RatesList.ToList()[2].CurrencyPair);
            Assert.AreEqual(494.5, bboMemoryImage.RatesList.ToList()[2].RateValue); // MidPoint of btcUsdBidLevel = 493 & btcUsdAskLevel = 496
        }
        public void GetBboTest_ChecksIfTheBboIsRetreivedSuccessfully_ReturnsBboForCurrencypairIfPresent()
        {
            BBOMemoryImage         bboMemoryImage = new BBOMemoryImage();
            MarketDataQueryService queryService   = new MarketDataQueryService(null, null, bboMemoryImage, null, null);

            DepthLevel bestBid = new DepthLevel(new Price(491));

            bestBid.IncreaseVolume(new Volume(100));
            DepthLevel bestAsk = new DepthLevel(new Price(492));

            bestAsk.IncreaseVolume(new Volume(200));
            bboMemoryImage.OnBBOArrived("BTCUSD", bestBid, bestAsk);

            BBORepresentation bboRepresentation = queryService.GetBBO("BTCUSD");

            Assert.IsNotNull(bboRepresentation);
            Assert.AreEqual(bestBid.Price.Value, bboRepresentation.BestBidPrice);
            Assert.AreEqual(bestBid.AggregatedVolume.Value, bboRepresentation.BestBidVolume);
            Assert.AreEqual(bestBid.OrderCount, bboRepresentation.BestBidOrderCount);
            Assert.AreEqual(bestAsk.Price.Value, bboRepresentation.BestAskPrice);
            Assert.AreEqual(bestAsk.AggregatedVolume.Value, bboRepresentation.BestAskVolume);
            Assert.AreEqual(bestAsk.OrderCount, bboRepresentation.BestAskOrderCount);
        }
        public void AddRateTest_TestIfTheRateForACurrencyPairIsAsExpected_VerifiesThroughTheReturnedRate()
        {
            BBOMemoryImage bboMemoryImage = new BBOMemoryImage();

            DepthLevel bidLevel1 = new DepthLevel(new Price(491));
            DepthLevel bidLevel2 = new DepthLevel(new Price(492));
            DepthLevel bidLevel3 = new DepthLevel(new Price(493));

            DepthLevel askLevel1 = new DepthLevel(new Price(494));
            DepthLevel askLevel2 = new DepthLevel(new Price(495));
            DepthLevel askLevel3 = new DepthLevel(new Price(496));

            bboMemoryImage.OnBBOArrived("XBT/USD", bidLevel1, askLevel1);
            Assert.AreEqual("XBT/USD", bboMemoryImage.RatesList.ToList()[0].CurrencyPair);
            Assert.AreEqual(492.5, bboMemoryImage.RatesList.ToList()[0].RateValue); // MidPoint of bidLevel1 = 491 & askLevel1 = 494

            bboMemoryImage.OnBBOArrived("XBT/USD", bidLevel2, askLevel2);
            Assert.AreEqual("XBT/USD", bboMemoryImage.RatesList.ToList()[0].CurrencyPair);
            Assert.AreEqual(493.5, bboMemoryImage.RatesList.ToList()[0].RateValue); // MidPoint of bidLevel2 = 492 & askLevel2 = 495

            bboMemoryImage.OnBBOArrived("XBT/USD", bidLevel3, askLevel3);
            Assert.AreEqual("XBT/USD", bboMemoryImage.RatesList.ToList()[0].CurrencyPair);
            Assert.AreEqual(494.5, bboMemoryImage.RatesList.ToList()[0].RateValue); // MidPoint of bidLevel3 = 493 & askLevel3 = 496
        }
        public void BboAddTest_ChecksWhetherTheBestBidAndOfferAreAddedSuccessfully_VerifiesBBoListFromMEmoryImage()
        {
            BBOMemoryImage bboMemoryImage = new BBOMemoryImage();

            DepthLevel bestBid = new DepthLevel(new Price(491));

            bestBid.IncreaseVolume(new Volume(600));
            bestBid.UpdateOrderCount(1);

            DepthLevel bestAsk = new DepthLevel(new Price(496));

            bestAsk.IncreaseVolume(new Volume(500));
            bestAsk.UpdateOrderCount(1);

            bboMemoryImage.OnBBOArrived("XTCUSD", bestBid, bestAsk);

            Assert.AreEqual(1, bboMemoryImage.BBORepresentationList.Count());
            Assert.AreEqual(491, bboMemoryImage.BBORepresentationList.First().BestBidPrice);
            Assert.AreEqual(496, bboMemoryImage.BBORepresentationList.First().BestAskPrice);
            Assert.AreEqual(600, bboMemoryImage.BBORepresentationList.First().BestBidVolume);
            Assert.AreEqual(500, bboMemoryImage.BBORepresentationList.First().BestAskVolume);
            Assert.AreEqual(1, bboMemoryImage.BBORepresentationList.First().BestBidOrderCount);
            Assert.AreEqual(1, bboMemoryImage.BBORepresentationList.First().BestAskOrderCount);
        }
 public TickerInfoService(ITickerInfoRepository tickerInfoRepository, BBOMemoryImage bboMemoryImage)
 {
     _tickerInfoRepository = tickerInfoRepository;
     _bboMemoryImage       = bboMemoryImage;
 }