internal void GetPositionsOpen_WhenNotPositionsInCache_ReturnsEmptyDictionary() { // Arrange var order = new StubOrderBuilder().BuildMarketOrder(); var traderId = TraderId.FromString("TESTER-000"); var accountId = AccountId.FromString("NAUTILUS-000-SIMULATED"); var strategyId = new StrategyId("SCALPER", "001"); var positionId = new PositionId("P-123456"); this.database.AddOrder(order, traderId, accountId, strategyId, positionId); var position = new Position(positionId, StubEventMessageProvider.OrderPartiallyFilledEvent( order, Quantity.Create(50000), Quantity.Create(50000))); this.database.AddPosition(position); position.Apply(StubEventMessageProvider.OrderFilledEvent(order)); this.database.UpdatePosition(position); // Act this.database.ClearCaches(); // Assert Assert.Empty(this.database.GetPositionsOpen()); Assert.Empty(this.database.GetPositionsOpen(traderId)); Assert.Empty(this.database.GetPositionsOpen(traderId, strategyId)); }
internal void GetPositionsClosed_WhenNotPositionsInCache_ReturnsEmptyDictionary() { // Arrange var order1 = new StubOrderBuilder() .WithOrderId("O-123456-1") .BuildMarketOrder(); var order2 = new StubOrderBuilder() .WithOrderId("O-123456-2") .WithOrderSide(OrderSide.Sell) .BuildMarketOrder(); var traderId = TraderId.FromString("TESTER-000"); var accountId = AccountId.FromString("NAUTILUS-000-SIMULATED"); var strategyId = new StrategyId("SCALPER", "001"); var positionId = new PositionId("P-123456"); this.database.AddOrder(order1, traderId, accountId, strategyId, positionId); this.database.AddOrder(order2, traderId, accountId, strategyId, positionId); var position = new Position(positionId, StubEventMessageProvider.OrderFilledEvent(order1)); this.database.AddPosition(position); position.Apply(StubEventMessageProvider.OrderFilledEvent(order2)); this.database.UpdatePosition(position); // Act this.database.ClearCaches(); // Assert Assert.Empty(this.database.GetPositionsClosed()); Assert.Empty(this.database.GetPositionsClosed(traderId)); Assert.Empty(this.database.GetPositionsClosed(traderId, strategyId)); }
internal void AddOrder_WithNoOrdersInDatabase_CorrectlyAddsOrderWithIndexes() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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.AddOrder(order, traderId, accountId, strategyId, positionId); // Assert Assert.Equal(order, this.database.GetOrder(order.Id)); Assert.Equal(positionId, this.database.GetPositionId(order.Id)); Assert.Equal(traderId, this.database.GetTraderId(order.Id)); Assert.Single(this.database.GetOrders()); Assert.Single(this.database.GetOrders(traderId)); Assert.Single(this.database.GetOrders(traderId, strategyId)); Assert.Contains(order.Id, this.database.GetOrders()); Assert.Contains(order.Id, this.database.GetOrders(traderId)); Assert.Contains(order.Id, this.database.GetOrders(traderId, strategyId)); Assert.Contains(traderId, this.database.GetTraderIds()); Assert.Contains(accountId, this.database.GetAccountIds()); Assert.Contains(strategyId, this.database.GetStrategyIds(traderId)); }
internal void UpdateOrder_WhenOrderCompleted_CorrectlyUpdatesIndexes() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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(order, traderId, accountId, strategyId, positionId); order.Apply(StubEventMessageProvider.OrderSubmittedEvent(order)); this.database.UpdateOrder(order); order.Apply(StubEventMessageProvider.OrderRejectedEvent(order)); // Act this.database.UpdateOrder(order); // Assert Assert.Contains(order.Id, this.database.GetOrderIds()); Assert.Contains(order.Id, this.database.GetOrderIds(traderId)); Assert.Contains(order.Id, this.database.GetOrderIds(traderId, strategyId)); Assert.Contains(order.Id, this.database.GetOrderCompletedIds()); Assert.Contains(order.Id, this.database.GetOrderCompletedIds(traderId)); Assert.Contains(order.Id, this.database.GetOrderCompletedIds(traderId, strategyId)); Assert.DoesNotContain(order.Id, this.database.GetOrderWorkingIds()); Assert.Contains(order.Id, this.database.GetOrders(traderId)); Assert.Contains(order.Id, this.database.GetOrders(traderId, strategyId)); Assert.Contains(order.Id, this.database.GetOrdersCompleted(traderId)); Assert.Contains(order.Id, this.database.GetOrdersCompleted(traderId, strategyId)); }
internal void OnSubmitOrderCommand_WhenCommandValid_OperatesDatabaseAndSendsToGateway() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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 SubmitOrder( traderId, accountId, strategyId, positionId, order, Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); // Act this.engine.Endpoint.SendAsync(command).Wait(); Task.Delay(100).Wait(); // Buffer to avoid intermittent tests // Assert Assert.Null(this.engine.UnhandledMessages.FirstOrDefault()); Assert.Equal(2, this.engine.ProcessedCount); Assert.Equal(1, this.engine.CommandCount); Assert.Single(this.tradingGateway.CalledMethods); Assert.Single(this.tradingGateway.ReceivedObjects); Assert.Equal("SubmitOrder", this.tradingGateway.CalledMethods[0]); Assert.Equal(order, this.tradingGateway.ReceivedObjects[0]); }
internal void OnOrderPartiallyFilledEvent_UpdatesOrderSendsToPublisher() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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 submitOrder = new SubmitOrder( traderId, accountId, strategyId, positionId, order, Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); // Act this.engine.Endpoint.SendAsync(submitOrder).Wait(); this.engine.Endpoint.SendAsync(StubEventMessageProvider.OrderAcceptedEvent(order)).Wait(); this.engine.Endpoint.SendAsync(StubEventMessageProvider.OrderPartiallyFilledEvent( order, Quantity.Create(50000), Quantity.Create(50000))).Wait(); Task.Delay(100).Wait(); // Buffer to avoid intermittent tests // Assert Assert.Null(this.engine.UnhandledMessages.FirstOrDefault()); Assert.Equal(4, this.engine.ProcessedCount); Assert.Equal(1, this.engine.CommandCount); Assert.Equal(2, this.engine.EventCount); Assert.Equal(3, this.receiver.Messages.Count); Assert.Equal(OrderState.PartiallyFilled, order.State); }
internal void OnOrderFilledEvent_WithNoPosition_OpensPosition() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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 submitOrder = new SubmitOrder( traderId, accountId, strategyId, positionId, order, Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); // Act this.engine.Endpoint.SendAsync(submitOrder).Wait(); this.engine.Endpoint.SendAsync(StubEventMessageProvider.OrderSubmittedEvent(order)).Wait(); this.engine.Endpoint.SendAsync(StubEventMessageProvider.OrderAcceptedEvent(order)).Wait(); this.engine.Endpoint.SendAsync(StubEventMessageProvider.OrderFilledEvent(order)).Wait(); Task.Delay(100).Wait(); // Buffer to avoid intermittent tests // Assert Assert.Single(this.database.GetPositions()); }
internal void UpdatePosition_WhenPositionOpen_CorrectlyUpdatesIndexes() { // Arrange var order = new StubOrderBuilder().BuildMarketOrder(); var traderId = TraderId.FromString("TESTER-000"); var accountId = AccountId.FromString("NAUTILUS-000-SIMULATED"); var strategyId = new StrategyId("SCALPER", "001"); var positionId = new PositionId("P-123456"); this.database.AddOrder(order, traderId, accountId, strategyId, positionId); var position = new Position(positionId, StubEventMessageProvider.OrderPartiallyFilledEvent( order, Quantity.Create(50000), Quantity.Create(50000))); this.database.AddPosition(position); // Act position.Apply(StubEventMessageProvider.OrderFilledEvent(order)); this.database.UpdatePosition(position); // Assert Assert.Equal(position, this.database.GetPosition(positionId)); Assert.Contains(position.Id, this.database.GetPositions()); Assert.Contains(position.Id, this.database.GetPositions(traderId)); Assert.Contains(position.Id, this.database.GetPositions(traderId, strategyId)); Assert.Contains(position.Id, this.database.GetPositionsOpen()); Assert.Contains(position.Id, this.database.GetPositionsOpen(traderId)); Assert.Contains(position.Id, this.database.GetPositionsOpen(traderId, strategyId)); Assert.Contains(position.Id, this.database.GetPositionIds()); Assert.Contains(position.Id, this.database.GetPositionOpenIds()); Assert.DoesNotContain(position.Id, this.database.GetPositionClosedIds()); }
internal void OnModifyOrderCommand_WhenNoOrderExists_DoesNotSendToGateway() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); var traderId = TraderId.FromString("TESTER-000"); var accountId = AccountId.FromString("NAUTILUS-000-SIMULATED"); var modify = new ModifyOrder( traderId, accountId, order.Id, order.Quantity, Price.Create(1.00010m, 5), Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); // Act this.engine.Endpoint.SendAsync(modify); Task.Delay(100).Wait(); // Buffer to avoid intermittent tests // Assert Assert.Null(this.engine.UnhandledMessages.FirstOrDefault()); Assert.Equal(2, this.engine.ProcessedCount); Assert.Equal(1, this.engine.CommandCount); Assert.Equal(0, this.engine.EventCount); Assert.Empty(this.tradingGateway.CalledMethods); Assert.Empty(this.tradingGateway.ReceivedObjects); Assert.Empty(this.receiver.Messages); }
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)); }
internal void GetOrdersCompleted_WhenDoesNotExistInCache_ReturnsEmptyDictionary() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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(order, traderId, accountId, strategyId, positionId); order.Apply(StubEventMessageProvider.OrderSubmittedEvent(order)); this.database.UpdateOrder(order); order.Apply(StubEventMessageProvider.OrderRejectedEvent(order)); this.database.UpdateOrder(order); // Act this.database.ClearCaches(); // Assert Assert.Empty(this.database.GetOrders()); Assert.Empty(this.database.GetOrders(traderId)); Assert.Empty(this.database.GetOrders(traderId, strategyId)); Assert.Empty(this.database.GetOrdersWorking()); Assert.Empty(this.database.GetOrdersWorking(traderId)); Assert.Empty(this.database.GetOrdersWorking(traderId, strategyId)); Assert.Empty(this.database.GetOrdersCompleted()); Assert.Empty(this.database.GetOrdersCompleted(traderId)); Assert.Empty(this.database.GetOrdersCompleted(traderId, strategyId)); }
internal void OnModifyOrderCommand_WhenOrderAlreadyBeingModified_DoesNotSendToGateway() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildStopMarketOrder(); 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 submit = new SubmitOrder( traderId, accountId, strategyId, positionId, order, Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); var modify1 = new ModifyOrder( traderId, accountId, order.Id, order.Quantity, Price.Create(1.00010m, 5), Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); var modify2 = new ModifyOrder( traderId, accountId, order.Id, order.Quantity, Price.Create(1.00010m, 5), Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); // Act this.engine.Endpoint.SendAsync(submit).Wait(); this.engine.Endpoint.SendAsync(StubEventMessageProvider.OrderAcceptedEvent(order)).Wait(); this.engine.Endpoint.SendAsync(StubEventMessageProvider.OrderWorkingEvent(order)).Wait(); this.engine.Endpoint.SendAsync(modify1).Wait(); this.engine.Endpoint.SendAsync(modify2).Wait(); Task.Delay(100).Wait(); // Buffer to avoid intermittent tests // Assert Assert.Null(this.engine.UnhandledMessages.FirstOrDefault()); Assert.Equal(6, this.engine.ProcessedCount); Assert.Equal(3, this.engine.CommandCount); Assert.Equal(2, this.engine.EventCount); Assert.Equal(2, this.tradingGateway.CalledMethods.Count); Assert.Equal(2, this.tradingGateway.ReceivedObjects.Count); Assert.Equal("SubmitOrder", this.tradingGateway.CalledMethods[0]); Assert.Equal("ModifyOrder", this.tradingGateway.CalledMethods[1]); Assert.Equal(3, this.receiver.Messages.Count); }
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); }
internal void ClearCaches_WithOrderInCaches_CorrectlyClearsCache() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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(order, traderId, accountId, strategyId, positionId); // Act this.database.ClearCaches(); // Assert Assert.Null(this.database.GetOrder(order.Id)); }
internal void AddOrder_WhenOrderAlreadyExists_ReturnsFailureResult() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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(order, traderId, accountId, strategyId, positionId); // Act var result = this.database.AddOrder(order, traderId, accountId, strategyId, positionId); // Assert Assert.True(result.IsFailure); }
internal void Test_can_publish_events() { // Arrange const string testAddress = "tcp://127.0.0.1:56601"; var publisher = new EventPublisher( this.container, new MsgPackEventSerializer(), new BypassCompressor(), EncryptionSettings.None(), new Label("test-publisher"), new Port(56601)); publisher.Start().Wait(); var subscriber = new SubscriberSocket(testAddress); subscriber.Connect(testAddress); subscriber.Subscribe("Event:Trade:TESTER-001"); Task.Delay(100).Wait(); // Allow socket to subscribe var serializer = new MsgPackEventSerializer(); var order = new StubOrderBuilder().BuildMarketOrder(); var rejected = StubEventMessageProvider.OrderRejectedEvent(order); var tradeEvent = new TradeEvent(TraderId.FromString("TESTER-001"), rejected); // Act publisher.Endpoint.Send(tradeEvent); this.Output.WriteLine("Waiting for published events..."); var topic = subscriber.ReceiveFrameBytes(); var message = subscriber.ReceiveFrameBytes(); var @event = serializer.Deserialize(message); // Assert Assert.Equal("Event:Trade:TESTER-001", Encoding.UTF8.GetString(topic)); Assert.Equal(typeof(OrderRejected), @event.GetType()); // Tear Down subscriber.Disconnect(testAddress); subscriber.Dispose(); publisher.Stop().Wait(); publisher.Dispose(); }
internal void CanSerializeAndDeserialize_AccountInquiryCommands() { // Arrange var command = new AccountInquiry( TraderId.FromString("TESTER-000"), new AccountId("FXCM", "028999999", "SIMULATED"), Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); // Act var packed = this.serializer.Serialize(command); var unpacked = (AccountInquiry)this.serializer.Deserialize(packed); // Assert Assert.Equal(command, unpacked); this.Output.WriteLine(Convert.ToBase64String(packed)); this.Output.WriteLine(Encoding.UTF8.GetString(packed)); }
internal void UpdatePosition_WhenMultipleOrdersForPositionLeavingPositionOpen_CorrectlyUpdatesIndexes() { // Arrange var order1 = new StubOrderBuilder() .WithOrderId("O-123456-1") .BuildMarketOrder(); var order2 = new StubOrderBuilder() .WithOrderId("O-123456-2") .BuildMarketOrder(); var order3 = new StubOrderBuilder() .WithOrderId("O-123456-3") .BuildMarketOrder(); var traderId = TraderId.FromString("TESTER-000"); var accountId = AccountId.FromString("NAUTILUS-000-SIMULATED"); var strategyId = new StrategyId("SCALPER", "001"); var positionId = new PositionId("P-123456"); this.database.AddOrder(order1, traderId, accountId, strategyId, positionId); this.database.AddOrder(order2, traderId, accountId, strategyId, positionId); this.database.AddOrder(order3, traderId, accountId, strategyId, positionId); var position = new Position(positionId, StubEventMessageProvider.OrderFilledEvent(order1)); this.database.AddPosition(position); position.Apply(StubEventMessageProvider.OrderFilledEvent(order2)); this.database.UpdatePosition(position); // Act position.Apply(StubEventMessageProvider.OrderFilledEvent(order3)); this.database.UpdatePosition(position); // Assert Assert.Equal(position, this.database.GetPosition(positionId)); Assert.Contains(position.Id, this.database.GetPositionsOpen()); Assert.Contains(position.Id, this.database.GetPositionsOpen(traderId)); Assert.Contains(position.Id, this.database.GetPositionsOpen(traderId, strategyId)); Assert.Contains(position.Id, this.database.GetPositionIds()); Assert.Contains(position.Id, this.database.GetPositionOpenIds()); Assert.DoesNotContain(position.Id, this.database.GetPositionClosedIds()); }
internal void GetOrders_WhenDoesNotExistInCache_ReturnsEmptyDictionary() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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(order, traderId, accountId, strategyId, positionId); // Act this.database.ClearCaches(); // Assert Assert.Empty(this.database.GetOrders()); Assert.Empty(this.database.GetOrders(traderId)); Assert.Empty(this.database.GetOrders(traderId, strategyId)); }
internal void OnAccountInquiryCommand_SendsToGateway() { // Arrange var command = new AccountInquiry( TraderId.FromString("TESTER-000"), AccountId.FromString("NAUTILUS-000-SIMULATED"), Guid.NewGuid(), StubZonedDateTime.UnixEpoch()); // Act this.engine.Endpoint.SendAsync(command).Wait(); Task.Delay(100).Wait(); // Buffer to avoid intermittent tests // Assert Assert.Null(this.engine.UnhandledMessages.FirstOrDefault()); Assert.Equal(2, this.engine.ProcessedCount); Assert.Equal(1, this.engine.CommandCount); Assert.Single(this.tradingGateway.CalledMethods); Assert.Equal("AccountInquiry", this.tradingGateway.CalledMethods[0]); }
internal void LoadOrdersCache_WhenOrdersInDatabase_CorrectlyCachesOrders() { // Arrange var order1 = new StubOrderBuilder().EntryOrder("O-123456-1").BuildStopMarketOrder(); var order2 = new StubOrderBuilder().EntryOrder("O-123456-2").BuildStopMarketOrder(); 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(order1, traderId, accountId, strategyId, positionId); this.database.AddOrder(order2, traderId, accountId, strategyId, positionId); order2.Apply(StubEventMessageProvider.OrderSubmittedEvent(order2)); this.database.UpdateOrder(order2); order2.Apply(StubEventMessageProvider.OrderAcceptedEvent(order2)); this.database.UpdateOrder(order2); order2.Apply(StubEventMessageProvider.OrderWorkingEvent(order2)); this.database.UpdateOrder(order2); order2.Apply(StubEventMessageProvider.OrderCancelledEvent(order2)); this.database.UpdateOrder(order2); this.database.ClearCaches(); // Act this.database.LoadOrdersCache(); // Assert Assert.Equal(order1, this.database.GetOrders()[order1.Id]); Assert.Equal(order2, this.database.GetOrders()[order2.Id]); Assert.Equal(1, this.database.GetOrders()[order1.Id].EventCount); Assert.Equal(5, this.database.GetOrders()[order2.Id].EventCount); Assert.Equal(OrderState.Initialized, this.database.GetOrders()[order1.Id].State); Assert.Equal(OrderState.Cancelled, this.database.GetOrders()[order2.Id].State); }
internal void Flush_WithOrderInDatabase_FlushesData() { // Arrange var order = new StubOrderBuilder().EntryOrder("O-123456").BuildMarketOrder(); 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(order, traderId, accountId, strategyId, positionId); // Act this.database.Flush(); // Assert Assert.Null(this.database.GetTraderId(order.Id)); Assert.Empty(this.database.GetOrders(traderId)); Assert.Empty(this.database.GetOrders(traderId, strategyId)); Assert.DoesNotContain(order.Id, this.database.GetOrders(traderId)); Assert.DoesNotContain(order.Id, this.database.GetOrders(traderId, strategyId)); Assert.DoesNotContain(traderId, this.database.GetTraderIds()); Assert.DoesNotContain(accountId, this.database.GetAccountIds()); Assert.DoesNotContain(strategyId, this.database.GetStrategyIds(traderId)); }
/// <summary> /// Returns a TraderId extracted from the given unpacked dictionary. /// </summary> /// <param name="unpacked">The dictionary to extract from.</param> /// <returns>The extracted TraderId.</returns> internal static TraderId AsTraderId(Dictionary <string, byte[]> unpacked) { return(TraderId.FromString(Decode(unpacked[nameof(TraderId)]))); }