Пример #1
0
        internal void AddBracketOrder_WithNoTakeProfit_CorrectlyAddsOrdersWithIndexes()
        {
            // Arrange
            var bracketOrder = StubBracketOrderProvider.Create(false);
            var traderId     = TraderId.FromString("TESTER-000");
            var accountId    = AccountId.FromString("NAUTILUS-000-SIMULATED");
            var positionId   = new PositionId("P-123456");
            var strategyId   = new StrategyId("SCALPER", "001");

            // Act
            this.database.AddBracketOrder(bracketOrder, traderId, accountId, strategyId, positionId);

            // Assert
            Assert.Equal(bracketOrder.Entry, this.database.GetOrder(bracketOrder.Entry.Id));
            Assert.Equal(bracketOrder.StopLoss, this.database.GetOrder(bracketOrder.StopLoss.Id));
            Assert.Equal(positionId, this.database.GetPositionId(bracketOrder.Entry.Id));
            Assert.Equal(positionId, this.database.GetPositionId(bracketOrder.StopLoss.Id));
            Assert.Equal(traderId, this.database.GetTraderId(bracketOrder.Entry.Id));
            Assert.Equal(traderId, this.database.GetTraderId(bracketOrder.StopLoss.Id));
            Assert.Equal(2, this.database.GetOrders().Count);
            Assert.Equal(2, this.database.GetOrders(traderId).Count);
            Assert.Equal(2, this.database.GetOrders(traderId, strategyId).Count);
            Assert.Contains(bracketOrder.Entry.Id, this.database.GetOrderIds());
            Assert.Contains(bracketOrder.Entry.Id, this.database.GetOrders());
            Assert.Contains(bracketOrder.Entry.Id, this.database.GetOrders(traderId));
            Assert.Contains(bracketOrder.Entry.Id, this.database.GetOrders(traderId, strategyId));
            Assert.DoesNotContain(bracketOrder.Entry.Id, this.database.GetOrderWorkingIds());
            Assert.DoesNotContain(bracketOrder.Entry.Id, this.database.GetOrderCompletedIds());
            Assert.DoesNotContain(bracketOrder.Entry.Id, this.database.GetOrdersWorking());
            Assert.DoesNotContain(bracketOrder.Entry.Id, this.database.GetOrdersCompleted());
            Assert.Contains(bracketOrder.StopLoss.Id, this.database.GetOrderIds());
            Assert.Contains(bracketOrder.StopLoss.Id, this.database.GetOrders());
            Assert.Contains(bracketOrder.StopLoss.Id, this.database.GetOrders(traderId));
            Assert.Contains(bracketOrder.StopLoss.Id, this.database.GetOrders(traderId, strategyId));
        }
Пример #2
0
        internal void OnSubmitBracketOrderCommand_WhenDuplicatedCommand_OperatesDatabaseAndSendsToGateway()
        {
            // Arrange
            var bracketOrder = StubBracketOrderProvider.Create();
            var traderId     = TraderId.FromString("TESTER-000");
            var accountId    = AccountId.FromString("NAUTILUS-000-SIMULATED");
            var positionId   = new PositionId("P-123456");
            var strategyId   = new StrategyId("SCALPER", "001");

            var command = new SubmitBracketOrder(
                traderId,
                accountId,
                strategyId,
                positionId,
                bracketOrder,
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            // Act
            this.engine.Endpoint.SendAsync(command).Wait();
            this.engine.Endpoint.SendAsync(command).Wait();
            Task.Delay(100).Wait();  // Buffer to avoid intermittent tests

            // Assert
            Assert.Null(this.engine.UnhandledMessages.FirstOrDefault());
            Assert.Equal(3, this.engine.ProcessedCount);
            Assert.Equal(2, this.engine.CommandCount);
            Assert.Single(this.tradingGateway.CalledMethods);
            Assert.Single(this.tradingGateway.ReceivedObjects);
            Assert.Equal("SubmitOrder", this.tradingGateway.CalledMethods[0]);
            Assert.Equal(bracketOrder, this.tradingGateway.ReceivedObjects[0]);
        }
Пример #3
0
        internal void AddBracketOrder_WhenStopLossOrderAlreadyExists_ReturnsFailureResult()
        {
            // Arrange
            var bracketOrder = StubBracketOrderProvider.Create();
            var traderId     = TraderId.FromString("TESTER-000");
            var accountId    = AccountId.FromString("NAUTILUS-000-SIMULATED");
            var positionId   = new PositionId("P-123456");
            var strategyId   = new StrategyId("SCALPER", "001");

            this.database.AddOrder(bracketOrder.StopLoss, traderId, accountId, strategyId, positionId);

            // Act
            var result = this.database.AddBracketOrder(bracketOrder, traderId, accountId, strategyId, positionId);

            // Assert
            Assert.True(result.IsFailure);
        }