public async Task GetAllAsync_WithSolution_ReturnsOkayResult() { const string expectedDescription = "A description"; var context = CatalogueSolutionsControllerTestContext.Setup(); context.Order.SetDescription(OrderDescription.Create(expectedDescription).Value); var serviceRecipients = new List <(string Ods, string Name)> { ("eu", "EU test") }; context.Order.SetServiceRecipient(serviceRecipients, Guid.Empty, string.Empty); var orderItem = OrderItemBuilder.Create().WithOdsCode(serviceRecipients[0].Ods).Build(); context.Order.AddOrderItem(orderItem, Guid.Empty, string.Empty); var result = await context.Controller.GetAllAsync("myOrder"); result.Value.Should().BeOfType <CatalogueSolutionsModel>(); var model = result.Value; model.CatalogueSolutions.Count().Should().Be(1); var expectedCatalogueSolutionList = new List <CatalogueSolutionModel> { CreateCatalogueSolutionModel(orderItem, serviceRecipients[0]) }; model.OrderDescription.Should().Be(expectedDescription); model.CatalogueSolutions.Should().BeEquivalentTo(expectedCatalogueSolutionList); }
internal Order Build() { var order = new Order { OrderId = _orderId, OrganisationId = _organisationId, OrganisationName = _organisationName, OrganisationOdsCode = _organisationOdsCode, OrganisationAddress = _organisationAddress, OrganisationContact = _organisationContact, SupplierId = _supplierId, SupplierName = _supplierName, SupplierAddress = _supplierAddress, SupplierContact = _supplierContact, CommencementDate = _commencementDate, ServiceRecipientsViewed = _serviceRecipientsViewed, CatalogueSolutionsViewed = _catalogueSolutionsViewed, Created = _created, LastUpdated = _lastUpdated, LastUpdatedBy = _lastUpdatedBy, LastUpdatedByName = _lastUpdatedByName, OrderStatus = _orderStatus }; order.SetDescription(OrderDescription.Create(_orderDescription).Value); foreach (var orderItem in _orderItems) { order.AddOrderItem(orderItem, _lastUpdatedBy, _lastUpdatedByName); } return(order); }
public void Create_DescriptionExceedsMaxLength_ReturnsFailureResult() { var isValid = OrderDescription.Create(new string('a', 101)); isValid.IsSuccess.Should().BeFalse(); isValid.Errors.Should().BeEquivalentTo(OrderErrors.OrderDescriptionTooLong()); }
public void Create_DescriptionIsValid_ReturnsSuccessResult() { var isValid = OrderDescription.Create("New Description"); isValid.IsSuccess.Should().BeTrue(); isValid.Errors.Should().BeEmpty(); }
public void Create_DescriptionIsNullOrWhitespace_ReturnsFailureResult(string description) { var isValid = OrderDescription.Create(description); isValid.IsSuccess.Should().BeFalse(); isValid.Errors.Should().BeEquivalentTo(OrderErrors.OrderDescriptionRequired()); }
public async Task <Result <string> > CreateAsync(CreateOrderRequest createOrderRequest) { if (createOrderRequest is null) { throw new ArgumentNullException(nameof(createOrderRequest)); } var isDescriptionValid = OrderDescription.Create(createOrderRequest.Description); var isOrganisationValid = OrderOrganisationId.Create(createOrderRequest.OrganisationId); if (!isDescriptionValid.IsSuccess || !isOrganisationValid.IsSuccess) { var allErrors = isDescriptionValid.Errors.Union(isOrganisationValid.Errors); return(Result.Failure <string>(allErrors)); } var order = new Order { OrderStatus = new OrderStatus() { OrderStatusId = 2, Name = "Unsubmitted" }, OrganisationId = isOrganisationValid.Value, LastUpdatedByName = createOrderRequest.LastUpdatedByName, LastUpdatedBy = createOrderRequest.LastUpdatedById, Created = DateTime.UtcNow, LastUpdated = DateTime.UtcNow }; order.SetDescription(isDescriptionValid.Value); var orderId = await _orderRepository.CreateOrderAsync(order); return(Result.Success(orderId)); }
public IOrder CreateLimitOrder(OrderDescription orderDescription) { var marketGateway = this.gateways[orderDescription.TargetMarketName]; ApiMarketWay apiMarketWay = (orderDescription.OrderWay == Way.Sell) ? ApiMarketWay.Sell : ApiMarketWay.Buy; ApiLimitOrder apiLimitOrder = marketGateway.CreateLimitOrder(apiMarketWay, orderDescription.Quantity, orderDescription.OrderPrice, orderDescription.AllowPartialExecution); return(new LimitOrderAdapter(marketGateway, apiLimitOrder)); }
public IOrder CreateMarketOrder(OrderDescription orderDescription) { // Adapts from the SOR model to the external market gateway one var marketGateway = this.gateways[orderDescription.TargetMarketName]; ApiMarketWay apiMarketWay = (orderDescription.OrderWay == Way.Sell) ? ApiMarketWay.Sell : ApiMarketWay.Buy; ApiMarketOrder apiMarketOrder = marketGateway.CreateMarketOrder(apiMarketWay, orderDescription.Quantity); return(new MarketOrderAdapter(marketGateway, apiMarketOrder)); }
public async Task GetAllAsync_WithDescriptionAndNoSolution_ReturnsOkResult() { const string expectedDescription = "A description"; var context = CatalogueSolutionsControllerTestContext.Setup(); context.Order.SetDescription(OrderDescription.Create(expectedDescription).Value); var result = await context.Controller.GetAllAsync("myOrder"); result.Value.Should().BeOfType <CatalogueSolutionsModel>(); var model = result.Value; model.CatalogueSolutions.Should().BeEmpty(); model.OrderDescription.Should().Be(expectedDescription); }
public void Configure(EntityTypeBuilder <Order> builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Property(x => x.Description).HasConversion(description => description.Value, data => OrderDescription.Create(data).Value); builder.HasMany(x => x.OrderItems) .WithOne(); builder.HasMany(x => x.ServiceRecipients) .WithOne(x => x.Order); }
public async Task Get_OtherOrganisationId_ReturnsForbidden() { var orderId = "C0000014-01"; var context = OrderDescriptionTestContext.Setup(); var testData = CreateOrderDescriptionTestData( orderId, OrderDescription.Create("Test Description").Value, Guid.NewGuid() ); context.Order = testData.order; using var controller = context.OrderDescriptionController; var result = await controller.GetAsync(orderId); result.Should().BeOfType <ForbidResult>(); }
public OpenOrder(string refID, OrderInfo orderInfo, FXMarket fxmkt)//, Dictionary<string, PnLElement> pnlInfo) { ID = refID; OrderDescription orderDescr = orderInfo.Descr; string descrPair = orderDescr.Pair; var infos = orderDescr.Order.Split(' '); IsBuyOrder = orderDescr.Type == "buy"; Volume = Convert.ToDouble(infos[1]); int cryptoLen = descrPair.Length - 3; Currency ccy1 = CurrencyPorperties.FromNameToCurrency(descrPair.Substring(0, cryptoLen)); Currency ccy2 = CurrencyPorperties.FromNameToCurrency(descrPair.Substring(cryptoLen, 3)); CurrencyPair cp = new CurrencyPair(ccy1, ccy2); Rate = new XChangeRate((double)orderInfo.Descr.Price, cp); CurrentRate = fxmkt.GetQuote(cp); Return = Rate.Rate / CurrentRate.Rate - 1; PreviouslyExecutedVolume = 0.0; TotalPnL = 0; }
public async Task Get_OrderIdExists_ReturnsTheOrdersDescription() { var orderId = "C0000014-01"; var context = OrderDescriptionTestContext.Setup(); var testData = CreateOrderDescriptionTestData( orderId, OrderDescription.Create("Test Description").Value, context.PrimaryOrganisationId ); context.Order = testData.order; using var controller = context.OrderDescriptionController; var result = await controller.GetAsync(orderId) as OkObjectResult; var orderDescription = result.Value as OrderDescriptionModel; orderDescription.Should().BeEquivalentTo(testData.expectedDescription); }
public void SetRequisites(string checkNumber, string orderDescription) { if ((CheckNumber?.Equals(checkNumber) ?? false) && (OrderDescription?.Equals(orderDescription) ?? false)) { return; } if (!string.IsNullOrEmpty(CheckNumber) && !CheckNumber.Equals(checkNumber)) { throw new ArgumentException($"{nameof(checkNumber)}. Cannot have a different number with aggregate"); } if (!string.IsNullOrEmpty(OrderDescription) && !OrderDescription.Equals(orderDescription)) { throw new ArgumentException($"{nameof(orderDescription)}. Cannot have a different description with aggregate"); } var domainEvent = new RequisitesEvent(orderDescription, checkNumber); Update(domainEvent); }
public async Task <ActionResult> UpdateAsync([FromRoute][Required] string orderId, [FromBody][Required] OrderDescriptionModel model) { if (model is null) { throw new ArgumentNullException(nameof(model)); } var order = await _orderRepository.GetOrderByIdAsync(orderId); if (order is null) { return(NotFound()); } var primaryOrganisationId = User.GetPrimaryOrganisationId(); if (primaryOrganisationId != order.OrganisationId) { return(Forbid()); } var isValid = OrderDescription.Create(model.Description); if (!isValid.IsSuccess) { return(BadRequest(new ErrorsModel(isValid.Errors.Select(x => new ErrorModel(x.Id, x.Field))))); } order.SetDescription(isValid.Value); var name = User.Identity.Name; order.SetLastUpdatedBy(User.GetUserId(), name); await _orderRepository.UpdateOrderAsync(order); return(NoContent()); }
/// <summary> /// Gets all open orders on the account. /// NOTE: The order objects returned do not have QC order IDs. /// </summary> /// <returns>The open orders returned from IB</returns> public override List <Order> GetOpenOrders() { List <Order> list = new List <Order>(); Dictionary <string, OrderInfo> orders = _restApi.GetOpenOrders(); foreach (KeyValuePair <string, OrderInfo> pair in orders) { OrderInfo info = pair.Value; OrderDescription desc = info.Descr; // check for debug purposes here if (pair.Key != desc.Pair) { throw new KrakenException("this doesn't match, please inspect!!"); } var SOR = new SubmitOrderRequest( TranslateOrderTypeToLean(info.Descr.OrderType), SecurityType.Crypto, this.SymbolMapper.GetLeanSymbol(desc.Pair, SecurityType.Crypto, Market.Kraken), info.Volume - info.VolumeExecuted, info.StopPrice.HasValue ? info.StopPrice.Value : 0m, info.LimitPrice.HasValue ? info.LimitPrice.Value : 0m, UnixTimeStampToDateTime(info.OpenTm), "" ); var order = Order.CreateOrder(SOR); list.Add(order); } return(list); }