/// <summary> /// This will return all pending orders for an account. /// Note: pending take profit or stop loss orders are recorded in the open trade object, and will not be returned in this request. /// </summary> /// <param name="instrument">Retrieve open orders for a specific instrument only</param> /// <param name="count">Maximum number of open orders to return. Default: 50. Max value: 500</param> /// <param name="maxId">The server will return orders with id less than or equal to this, in descending order (for pagination)</param> /// <param name="ids">An URL encoded comma (%2C) separated list of orders to retrieve. /// Maximum number of ids: 50. No other parameter may be specified with the ids paramete</param> /// <returns></returns> public async Task <List <Order> > GetOrders(string instrument, int?count, long?maxId, string ids) { Dictionary <string, string> routeParams = new Dictionary <string, string>(); routeParams.Add("accountId", _accountId.ToString()); Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("instrument", instrument); if (count != null) { properties.Add("count", count); } if (maxId != null) { properties.Add("maxId", maxId); } if (!string.IsNullOrWhiteSpace(ids)) { properties.Add("ids", ids); } OrdersWrapper ordersWrapper = await Get <OrdersWrapper>(routeParams, properties, _ordersRoute); return(ordersWrapper.Orders); }
/// <summary> /// Validates the list of historical orders and sends them in batches to Riskified Servers. /// The FinancialStatus field of each order should contain the latest order status as described at "http://apiref.riskified.com/net/#actions-historical" /// /// </summary> /// <param name="order">The Orders to send</param> /// <param name="failedOrders">When the method returns false, contains a mapping from order_id (key) to error message (value), otherwise will be null</param> /// <returns>True if all orders were sent successfully, false if one or more failed due to bad format or tranfer error</returns> /// <exception cref="OrderFieldBadFormatException">On bad format of an order (missing fields data or invalid data)</exception> /// <exception cref="RiskifiedTransactionException">On errors with the transaction itself (network errors, bad response data)</exception> public bool SendHistoricalOrders(IEnumerable <Order> orders, out Dictionary <string, string> failedOrders) { const byte batchSize = 10; if (orders == null) { failedOrders = null; return(true); } Dictionary <string, string> errors = new Dictionary <string, string>(); var riskifiedEndpointUrl = HttpUtils.BuildUrl(_env, "/api/historical"); List <Order> batch = new List <Order>(batchSize); var enumerator = orders.GetEnumerator(); do { batch.Clear(); while (batch.Count < batchSize && enumerator.MoveNext()) { // validate orders and assign to next batch until full Order order = enumerator.Current; try { if (_validationMode != Validations.Skip) { order.Validate(_validationMode); } batch.Add(order); } catch (OrderFieldBadFormatException e) { errors.Add(order.Id, e.Message); } } if (batch.Count > 0) { // send batch OrdersWrapper wrappedOrders = new OrdersWrapper(batch); try { HttpUtils.JsonPostAndParseResponseToObject <OrdersWrapper>(riskifiedEndpointUrl, wrappedOrders, _authToken, _shopDomain); } catch (RiskifiedTransactionException e) { batch.ForEach(o => errors.Add(o.Id, e.Message)); } } } while (batch.Count == batchSize); if (errors.Count == 0) { failedOrders = null; return(true); } failedOrders = errors; return(false); }
/// <summary> /// This will return all pending orders for an account. /// Note: pending take profit or stop loss orders are recorded in the open trade object, and will not be returned in this request. /// </summary> /// <returns></returns> public async Task <List <Order> > GetOrders() { Dictionary <string, string> routeParams = new Dictionary <string, string>(); routeParams.Add("accountId", _accountId.ToString()); OrdersWrapper ordersWrapper = await Get <OrdersWrapper>(routeParams, null, _ordersRoute); return(ordersWrapper.Orders); }
public IActionResult Orders() { OrdersWrapper newView = new OrdersWrapper(); newView.AllCustomers = dbContext.Customers.ToList(); newView.AllProducts = dbContext.Products.ToList(); newView.AllOrders = dbContext.Orders .Include(o => o.Customer) .Include(o => o.Product) .ToList(); return(View(newView)); }
/// <summary> /// This will return all pending orders for an account. /// Note: pending take profit or stop loss orders are recorded in the open trade object, and will not be returned in this request. /// </summary> /// <param name="instrument">Retrieve open orders for a specific instrument only</param> /// <returns></returns> public async Task <List <Order> > GetOrders(string instrument) { Dictionary <string, string> routeParams = new Dictionary <string, string>(); routeParams.Add("accountId", _accountId.ToString()); Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("instrument", instrument); OrdersWrapper ordersWrapper = await Get <OrdersWrapper>(routeParams, properties, _ordersRoute); return(ordersWrapper.Orders); }
public IActionResult AddOrder(OrdersWrapper fromForm) { Product thisProduct = dbContext.Products .FirstOrDefault(p => p.ProductId == fromForm.Order.ProductId); if (ModelState.IsValid) { if (fromForm.Order.OrderQty > thisProduct.ProductQty) { ModelState.AddModelError("Order.OrderQty", $"Only {thisProduct.ProductQty} items in stock."); return(View("Orders")); } thisProduct.ProductQty -= fromForm.Order.OrderQty; dbContext.Add(fromForm.Order); dbContext.SaveChanges(); return(RedirectToAction("Orders")); } return(RedirectToAction("Orders")); }