/// <summary> /// Get Ohlc info /// </summary> /// <param name="pair"></param> /// <param name="interval"></param> /// <param name="since"></param> /// <returns></returns> public OhlcRepresentation GetOhlcInfo(string pair, int interval, string since) { Ohlc ohlcData = new Ohlc(DateTime.UtcNow, 113, 111, 123, 114, 100, 1000, 23); List <Ohlc> dataList = new List <Ohlc>(); for (int i = 0; i < 10; i++) { dataList.Add(ohlcData); } OhlcRepresentation representation = new OhlcRepresentation(dataList, pair, 100); return(representation); }
public void SendSomeOrders_IfOrdersAreMatching_OhlcAndTickerInfoWillBeFormed() { // Get the context // IApplicationContext applicationContext = ContextRegistry.GetContext(); // Get the instance through Spring configuration OrderController orderController = (OrderController)_applicationContext["OrderController"]; orderController.Request = new HttpRequestMessage(HttpMethod.Post, ""); orderController.Request.Headers.Add("Auth", "123456789"); ManualResetEvent manualResetEvent = new ManualResetEvent(false); IHttpActionResult orderHttpResult = orderController.CreateOrder(new CreateOrderParam() { Pair = "XBTUSD", Price = 491, Volume = 100, Side = "buy", Type = "limit" }); OkNegotiatedContentResult <NewOrderRepresentation> orderRepresentationContent = (OkNegotiatedContentResult <NewOrderRepresentation>)orderHttpResult; Assert.IsNotNull(orderRepresentationContent.Content); manualResetEvent.Reset(); manualResetEvent.WaitOne(3000); orderController.CreateOrder(new CreateOrderParam() { Pair = "XBTUSD", Price = 492, Volume = 300, Side = "buy", Type = "limit" }); manualResetEvent.Reset(); manualResetEvent.WaitOne(3000); orderController.CreateOrder(new CreateOrderParam() { Pair = "XBTUSD", Price = 492, Volume = 1000, Side = "sell", Type = "limit" }); manualResetEvent.Reset(); manualResetEvent.WaitOne(3000); orderController.CreateOrder(new CreateOrderParam() { Pair = "XBTUSD", Price = 492, Volume = 900, Side = "buy", Type = "limit" }); manualResetEvent.Reset(); manualResetEvent.WaitOne(3000); orderController.CreateOrder(new CreateOrderParam() { Pair = "XBTUSD", Price = 498, Volume = 800, Side = "sell", Type = "limit" }); manualResetEvent.Reset(); manualResetEvent.WaitOne(3000); orderController.CreateOrder(new CreateOrderParam() { Pair = "XBTUSD", Price = 497, Volume = 700, Side = "sell", Type = "limit" }); manualResetEvent.Reset(); manualResetEvent.WaitOne(20000); MarketController marketController = (MarketController)_applicationContext["MarketController"]; IHttpActionResult tickerinfo = marketController.TickerInfo("XBTUSD"); OkNegotiatedContentResult <object> readmodel = (OkNegotiatedContentResult <object>)tickerinfo; Assert.NotNull(readmodel); TickerInfoReadModel model = readmodel.Content as TickerInfoReadModel; Assert.NotNull(model); Assert.AreEqual(model.CurrencyPair, "XBTUSD"); Assert.AreEqual(model.TradePrice, 492); Assert.AreEqual(model.TradeVolume, 700); Assert.AreEqual(model.OpeningPrice, 492); Assert.AreEqual(model.TodaysHigh, 492); Assert.AreEqual(model.Last24HoursHigh, 492); Assert.AreEqual(model.TodaysLow, 492); Assert.AreEqual(model.Last24HoursLow, 492); Assert.AreEqual(model.TodaysVolume, 1000); Assert.AreEqual(model.Last24HourVolume, 1000); Assert.AreEqual(model.TodaysTrades, 2); Assert.AreEqual(model.Last24HourTrades, 2); Assert.AreEqual(model.TodaysVolumeWeight, 492); Assert.AreEqual(model.Last24HourVolumeWeight, 492); Assert.AreEqual(model.AskPrice, 497); Assert.AreEqual(model.AskVolume, 700); Assert.AreEqual(model.BidPrice, 492); Assert.AreEqual(model.BidVolume, 200); IHttpActionResult ohlcActionResult = marketController.OhlcInfo("XBTUSD"); OkNegotiatedContentResult <OhlcRepresentation> representation = (OkNegotiatedContentResult <OhlcRepresentation>)ohlcActionResult; Assert.NotNull(representation); OhlcRepresentation ohlc = representation.Content as OhlcRepresentation; Assert.NotNull(ohlc); object[] ohlcValues = ohlc.OhlcInfo[0] as object[]; Assert.AreEqual(ohlc.PairName, "XBTUSD"); Assert.AreEqual(ohlcValues[0], 492); //open Assert.AreEqual(ohlcValues[1], 492); //high Assert.AreEqual(ohlcValues[2], 492); //low Assert.AreEqual(ohlcValues[3], 492); //close }