Ejemplo n.º 1
0
        public async Task Reroute_One_Failed_Limit_Order()
        {
            // arrange

            var marketOrder = new MarketOrder("tmp", AssetPair, OrderType.Buy, 47)
            {
                Status = MarketOrderStatus.Active
            };

            _marketOrderServiceMock.Setup(o => o.GetNextActiveAsync())
            .Returns(Task.FromResult(marketOrder));

            _exchangeServiceMock.Setup(o => o.CreateLimitOrderAsync(
                                           It.Is <string>(exchangeName => exchangeName == Exchange3),
                                           It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <OrderType>()))
            .Returns((string exchangeName, string assetPair, decimal price, decimal volume, OrderType orderType) =>
                     Task.FromResult(new ExternalLimitOrder(Guid.NewGuid().ToString(), exchangeName, assetPair,
                                                            price, volume, orderType)));

            _exchangeServiceMock.Setup(o => o.CreateLimitOrderAsync(
                                           It.Is <string>(exchangeName => exchangeName == Exchange1 || exchangeName == Exchange2),
                                           It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <decimal>(), It.IsAny <OrderType>()))
            .Throws(new FailedOperationException("error"));

            var expectedExternalLimitOrders = new List <ExternalLimitOrder>
            {
                new ExternalLimitOrder(Guid.NewGuid().ToString(), Exchange3, AssetPair,
                                       3200, 20, OrderType.Buy),
                new ExternalLimitOrder(Guid.NewGuid().ToString(), Exchange3, AssetPair,
                                       3300, 8, OrderType.Buy)
            };

            var actualExternalLimitOrders = new List <ExternalLimitOrder>();

            _externalLimitOrderServiceMock.Setup(o => o.AddAsync(It.IsAny <string>(), It.IsAny <ExternalLimitOrder>()))
            .Returns(Task.CompletedTask)
            .Callback((string parentId, ExternalLimitOrder externalLimitOrder) =>
                      actualExternalLimitOrders.Add(externalLimitOrder));

            // act

            await _service.ExecuteMarketOrdersAsync();

            // assert

            Assert.IsTrue(AreEqual(expectedExternalLimitOrders, actualExternalLimitOrders));
        }
 protected override Task OnExecuteAsync(CancellationToken cancellation)
 {
     return(_smartOrderRouter.ExecuteMarketOrdersAsync());
 }