public IActionResult GetOrders([FromQuery] GetOrdersOptions options) { options ??= new GetOrdersOptions(); if (options.PageNumber < 1) { options.PageNumber = 1; } if (options.PageSize < 0) { options.PageSize = 10; } List <OrderListDto> orders = this._orderService.GetOrders(options); return(this.Ok(orders)); }
private static async Task Execute(GetOrdersOptions options, Client client = null) { client ??= new Client(options.Url, new HttpClient()); try { var orders = await client.GetOrdersAsync(); Console.WriteLine($"Found {orders.Count} orders:"); foreach (var order in orders) { Console.WriteLine($"{order.Security} - {order.Side} {order.Quantity} units @ {order.Price}"); } } catch (Exception exc) { Console.WriteLine(exc); } }
/// <summary> /// Retrieve all orders. /// </summary> /// <param name="apiKey">Your apiKey.</param> /// <param name="apiSecret">Your apiSecretKey.</param> /// <response code="200">List of orders.</response> /// <response code="400_InvalidUrlParameters">Invalid URL parameters.</response> /// <response code="403">Not authorized to use this endpoint.</response> /// <response code="500">Server error.</response> /// <returns></returns> public async Task <Result <List <GetOrdersResponse>, ErrorResponse> > GetOrdersAsync(string apiKey, string apiSecret) { GetOrdersOptions options = new GetOrdersOptions(); return(await GetOrdersAsync(apiKey, apiSecret, options)); }
/// <summary> /// Gets the orders. /// </summary> /// <param name="options">The options for filtering the results.</param> /// <returns>The filtered list of orders.</returns> public List <OrderListDto> GetOrders(GetOrdersOptions options) { List <Order> orders = this._orderStore.GetOrders(options); return(orders.Select(x => new OrderListDto(x)).ToList()); }
/// <summary> /// Retrieve all orders. /// </summary> /// <param name="apiKey">Your apiKey.</param> /// <param name="apiSecret">Your apiSecretKey.</param> /// <param name="options">Request body.</param> /// <response code="200">List of orders.</response> /// <response code="400_InvalidUrlParameters">Invalid URL parameters.</response> /// <response code="403">Not authorized to use this endpoint.</response> /// <response code="500">Server error.</response> /// <returns></returns> public async Task <Result <List <GetOrdersResponse>, ErrorResponse> > GetOrdersAsync(string apiKey, string apiSecret, GetOrdersOptions options) { #region IEnumerable <ValidationResult> validation = options.Validate(); if (validation.Any()) { foreach (var item in validation) { throw new ArgumentNullException(item.ErrorMessage); } } #endregion string token = getAuthToken(apiKey, apiSecret); var result = new Result <List <GetOrdersResponse>, ErrorResponse>(); string requestUri = $"{mEnv.BaseUrl}/v1/Orders"; var queryParams = new List <string>(); if (options.StartDateTime.HasValue) { queryParams.Add($"startDateTime={options.StartDateTime.Value.ToString("o")}"); } if (options.EndDateTime.HasValue) { queryParams.Add($"endDateTime={options.EndDateTime.Value.ToString("o")}"); } if (options.Status.HasValue) { queryParams.Add($"status={options.Status}"); } queryParams.Add($"offset={options.Offset}"); queryParams.Add($"limit={options.Limit}"); requestUri = $"{requestUri}?{string.Join("&", queryParams)}"; try { using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add(AUTHORIZATION, $"{BASIC} {token}"); using (HttpResponseMessage response = await httpClient.GetAsync(requestUri)) { if (response.IsSuccessStatusCode) { List <GetOrdersResponse> orderResponse = await response.Content.ReadAsAsync <List <GetOrdersResponse> >(); result.IsSuccess = true; result.Data = orderResponse; return(result); } string contentString = await response.Content.ReadAsStringAsync(); result.Error = ResponseHandler.GetError(response.StatusCode, requestUri, contentString); } } } catch (HttpRequestException) { result.IsSuccess = false; result.Error = ResponseHandler.GetExceptionError(); } return(result); }