public async Task <List <String> > CancelAllOrders() { MyDeleteOrdersRequest request = new MyDeleteOrdersRequest("/orders"); ExchangeResponse genericResponse = null; try { genericResponse = await this.GetResponse(request); } catch (Exception) { throw new Exception("CancelAllOrderError"); } List <string> cancelledOrderList = new List <string>(); if (genericResponse.IsSuccessStatusCode) { var json = genericResponse.ContentBody; var orders_jArr = JArray.Parse(json).ToArray <JToken>(); foreach (var obj in orders_jArr) { cancelledOrderList.Add(obj.Value <string>()); } } else { if (genericResponse.StatusCode == System.Net.HttpStatusCode.Forbidden) { Logger.WriteLog("cancel order permissions denied"); throw new Exception("PermissionDenied"); } else { Logger.WriteLog("cancel order error: " + genericResponse.ContentBody); throw new Exception("CancelOrderError"); } } return(cancelledOrderList); }
public async Task <List <String> > CancelSingleOrder(string orderId) { var endPoint = string.Format(@"/orders/{0}", orderId); MyDeleteOrdersRequest request = new MyDeleteOrdersRequest(endPoint); //var genericResponse = await this.GetResponse(request); ExchangeResponse genericResponse = null; try { genericResponse = await this.GetResponse(request); } catch (Exception) { throw new Exception("CancelSingleOrderError"); } List <string> cancelledOrder = new List <string>(); if (genericResponse.IsSuccessStatusCode) { var json = genericResponse.ContentBody; var orders_jArr = JArray.Parse(json).ToArray <JToken>(); foreach (var obj in orders_jArr) { cancelledOrder.Add(obj.Value <string>()); } } else { if (genericResponse.StatusCode == System.Net.HttpStatusCode.Forbidden) { Logger.WriteLog("cancel order permissions denied"); throw new Exception("PermissionDenied"); } else if (genericResponse.StatusCode == System.Net.HttpStatusCode.NotFound) { Logger.WriteLog(string.Format("order {0} not found, may have been already filled or cancelled otherwise", orderId)); throw new Exception("OrderNotFound"); } else if (genericResponse.StatusCode == System.Net.HttpStatusCode.BadRequest) { if (genericResponse.ContentBody.ToLower().Contains("order already done")) { Logger.WriteLog(string.Format("order {0} already done, may have been already filled or cancelled otherwise", orderId)); throw new Exception("OrderAlreadyDone"); } throw new Exception("OrderBadRequest"); } else { Logger.WriteLog(string.Format("Error cancelling order {0}: ", orderId, genericResponse.StatusCode.ToString())); throw new Exception("CancelOrderError"); } } //if (cancelledOrder.Count() > 0) //{ // //busy waiting // while (isUpdatingOrderList) // Logger.WriteLog("waiting for order list update lock release"); // isUpdatingOrderList = true; //wait // MyChaseOrderList.RemoveAll(x => x.OrderId == cancelledOrder.FirstOrDefault()); // isUpdatingOrderList = false; //release // //fillsClient.RemoveFromOrderWatchList(cancelledOrder.FirstOrDefault()); //} return(cancelledOrder); }