/// <summary> /// Gets a List of closed orders represented as ReadModel /// </summary> /// <param name="traderId"></param> /// <param name="includeTrades"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <returns></returns> public object GetClosedOrders(TraderId traderId, bool includeTrades = false, string startTime = "", string endTime = "") { List <OrderReadModel> orders; if (startTime == "" || endTime == "") { orders = _orderRepository.GetClosedOrders(traderId.Id.ToString(CultureInfo.InvariantCulture)); } else { orders = _orderRepository.GetClosedOrders(traderId.Id.ToString(), Convert.ToDateTime(startTime), Convert.ToDateTime(endTime)); } for (int i = 0; i < orders.Count; i++) { IList <object> trades = _tradeRepository.GetTradesByorderId(orders[i].OrderId); Tuple <decimal, DateTime?> data = CalculateAveragePrice(trades); orders[i].AveragePrice = data.Item1; if (orders[i].Status == OrderState.Complete.ToString()) { orders[i].ClosingDateTime = data.Item2; } if (includeTrades) { orders[i].Trades = trades; } } return(orders); }
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 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 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 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 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 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 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 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 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 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()); }
public CancelOrderCommand(OrderId orderId, TraderId traderId) { AssertionConcern.AssertArgumentNotNull(orderId, "OrderId not provided or it is invalid"); AssertionConcern.AssertArgumentNotNull(traderId, "TraderId not provided or it is invalid"); OrderId = orderId; TraderId = traderId; }
/// <summary> /// Gets the list for the Open orders /// </summary> /// <returns></returns> public object GetOpenOrders(TraderId traderId, bool includeTrades = false) { List <OrderRepresentation> orderList = new List <OrderRepresentation>(); orderList.Add(new OrderRepresentation() { TxId = "EEER342", UserRefId = "WREDF342", Pair = "XBTUSD", Status = OrderState.Accepted, OpenTime = DateTime.Now.AddHours(-2), ExpireTime = DateTime.Now.AddHours(3), Volume = 3000, Cost = 0, Fee = (decimal?)0.25, Price = (decimal)491.23, StopPrice = 0, OFlags = "DUMMY", Trades = "23453,1764,1554,2134", Opened = "045643.23" }); orderList.Add(new OrderRepresentation() { TxId = "EEER342", UserRefId = "YIO468S", Pair = "XBTEURS", Status = OrderState.Accepted, OpenTime = DateTime.Now.AddHours(-2), ExpireTime = DateTime.Now.AddHours(3), Volume = 3000, Cost = 0, Fee = (decimal?)0.25, Price = (decimal)491.23, StopPrice = 0, OFlags = "DUMMY", Trades = "23453,1764,1554,2134", Opened = "045643.23" }); orderList.Add(new OrderRepresentation() { TxId = "EEER342", UserRefId = "GTII5769", Pair = "LTCUSD", Status = OrderState.Accepted, OpenTime = DateTime.Now.AddHours(-2), ExpireTime = DateTime.Now.AddHours(3), Volume = 3000, Cost = 0, Fee = (decimal?)0.25, Price = (decimal)491.23, StopPrice = 0, OFlags = "DUMMY", Trades = "23453,1764,1554,2134", Opened = "045643.23" }); return(orderList); }
/// <summary> /// Initializes a new instance of the <see cref="TradeEvent"/> class. /// </summary> /// <param name="traderId">The trade event trader identifier.</param> /// <param name="orderEvent">The trade event order event.</param> public TradeEvent(TraderId traderId, OrderEvent orderEvent) : base( EventType, orderEvent.Id, orderEvent.Timestamp) { this.TraderId = traderId; this.Event = orderEvent; }
public object GetTradesHistory(TraderId traderId, string start = "", string end = "") { if (start == "" || end == "") { return(_tradeRepository.GetTraderTradeHistory(traderId.Id.ToString())); } return(_tradeRepository.GetTraderTradeHistory(traderId.Id.ToString(), Convert.ToDateTime(start), Convert.ToDateTime(end))); }
public OrderReadModel GetOrderById(TraderId traderId, OrderId orderId) { OrderReadModel model = CurrentSession.Get <OrderReadModel>(orderId.Id); if (model.TraderId.Equals(traderId.Id, StringComparison.InvariantCultureIgnoreCase)) { return(model); } return(null); }
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); }
public object GetOrderById(TraderId traderId, OrderId orderId) { OrderReadModel order = _orderRepository.GetOrderById(traderId, orderId); Tuple <decimal, DateTime?> data = CalculateAveragePrice(_tradeRepository.GetTradesByorderId(orderId.Id)); order.AveragePrice = data.Item1; if (order.Status == OrderState.Complete.ToString()) { order.ClosingDateTime = data.Item2; } return(order); }
/// <summary> /// Factory Constructor for market order /// </summary> /// <param name="orderId"> </param> /// <param name="currencyPair"></param> /// <param name="orderSide"></param> /// <param name="orderType"></param> /// <param name="volume"></param> /// <param name="traderId"></param> public Order(OrderId orderId, string currencyPair, OrderSide orderSide, OrderType orderType, Volume volume, TraderId traderId) { OrderId = orderId; CurrencyPair = currencyPair; OrderSide = orderSide; OrderType = orderType; Volume = volume; Price = new Price(0); TraderId = traderId; this.DateTime = DateTime.Now; FilledQuantity = new Volume(0); FilledCost = new Price(0); OpenQuantity = Volume; }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (Channel == PrepayChannel.WxJs && TraderId.IsNullOrWhiteSpace()) { // jsapi必须传openid yield return(new ValidationResult("参数错误")); } //if ((Channel == Enums.PrePayChannel.WxApp || Channel == Enums.PrePayChannel.AliPayH5) && ClientIp.IsNullOrWhiteSpace()) // yield return new ValidationResult("参数错误"); if (Channel == PrepayChannel.WxH5 && (!ClientIp.IsMatch(Consts.Regexs.Ipv4) || RedirectUrl.IsNullOrWhiteSpace())) { yield return(new ValidationResult("参数错误")); } }
public void CreateChangePasswordRequest(System.Windows.Controls.PasswordBox oPasswordBox, ref ChangePasswordRequest objChangePasswordRequest) { if (objChangePasswordRequest != null) { objChangePasswordRequest.TraderID = Convert.ToUInt32(TraderId.Trim()); objChangePasswordRequest.NewPassword = oPasswordBox.Password; objChangePasswordRequest.Exchange = 1; //1- BSE, 2-BOW, 3-NSE objChangePasswordRequest.Filler_c = ""; objChangePasswordRequest.Market = 1; //1 - Equity, 2- Derv., 3. Curr objChangePasswordRequest.MemberID = UtilityLoginDetails.GETInstance.MemberId; //objChangePasswordRequest.MessageTag = MemoryManager.GetMesageTag(); objChangePasswordRequest.Password = oPasswordBox.Password; UtilityLoginDetails.GETInstance.RequestTraderId = Convert.ToUInt16(objChangePasswordRequest.TraderID); } }
/// <summary> /// Initializes a new instance of the <see cref="AccountInquiry"/> class. /// </summary> /// <param name="traderId">The trader identifier.</param> /// <param name="accountId">The account identifier for the inquiry.</param> /// <param name="commandId">The command identifier.</param> /// <param name="commandTimestamp">The command timestamp.</param> public AccountInquiry( TraderId traderId, AccountId accountId, Guid commandId, ZonedDateTime commandTimestamp) : base( CommandType, commandId, commandTimestamp) { Debug.NotDefault(commandId, nameof(commandId)); Debug.NotDefault(commandTimestamp, nameof(commandTimestamp)); this.TraderId = traderId; this.AccountId = accountId; }
public IHttpActionResult QueryClosedOrders([FromBody] QueryClosedOrdersParams closedOrdersParams) { if (log.IsDebugEnabled) { log.Debug("Query Closed Orders Call: " + closedOrdersParams); } try { //get api key from header var headers = Request.Headers; string apikey = ""; IEnumerable <string> headerParams; if (headers.TryGetValues("Auth", out headerParams)) { string[] auth = headerParams.ToList()[0].Split(','); apikey = auth[0]; } if (log.IsDebugEnabled) { log.Debug("Query Closed Orders Call: ApiKey=" + apikey); } TraderId traderId = new TraderId(_apiKeyInfoAccess.GetUserIdFromApiKey(apikey).ToString()); object orders = _orderQueryService.GetClosedOrders(traderId, closedOrdersParams.IncludeTrades, closedOrdersParams.StartTime, closedOrdersParams.EndTime); if (orders is List <OrderRepresentation> ) { List <OrderRepresentation> openOrderList = (List <OrderRepresentation>)orders; return(Ok <List <OrderRepresentation> >(openOrderList)); } else if (orders is List <OrderReadModel> ) { List <OrderReadModel> openOrderList = (List <OrderReadModel>)orders; return(Ok <List <OrderReadModel> >(openOrderList)); } return(BadRequest()); } catch (Exception exception) { if (log.IsErrorEnabled) { log.Error("Query Closed Orders Call Error", exception); } return(InternalServerError(exception)); } }
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()); }