private JsonResponse ProcessRequestPositionsClosing(RequestPositionsClosing req) { var resp = new JsonResponsePositionsClosing { RequestId = req.RequestId }; int countOk, countFailed; string errors; ModifyOrders(req.positions, true, out countOk, out countFailed, out errors); resp.CountClosed = countOk; resp.CountFail = countFailed; resp.ErrorString = errors; resp.Success = countOk > countFailed; return resp; }
private JsonResponse ProcessRequestPositionsClosing(RequestPositionsClosing req) { var resp = new JsonResponsePositionsClosing { RequestId = req.RequestId }; var errorStrings = new Dictionary<string, string>(); int countOk = 0, countFail = 0; try { foreach (var pos in req.positions) { string errorString; var order = new MarketOrder { AccountID = pos.AccountId, ID = pos.Id, Side = pos.Side, Symbol = pos.Symbol, StopLoss = (float)pos.Sl, TakeProfit = (float)pos.Tp, TimeEnter = pos.TimeEnter, TimeExit = pos.TimeExit, Volume = pos.Volume, PriceEnter = (float)pos.PriceEnter, PriceExit = pos.PriceExit == 0 ? (float?)null : (float)pos.PriceExit, ResultDepo = (float)pos.Profit, MasterOrder = pos.Mt4Order }; if (PlatformManager.Instance.proxy.ModifyOrder(order, out errorString)) countOk++; else countFail++; if (!string.IsNullOrEmpty(errorString) && !errorStrings.ContainsKey(errorString)) errorStrings.Add(errorString, string.Empty); } resp.CountClosed = countOk; resp.CountFail = countFail; resp.Success = countFail == 0; resp.ErrorString = string.Join(". ", errorStrings.Keys); } catch (Exception ex) { resp.ErrorString = ex.GetType().Name + ": " + ex.Message; resp.Success = false; } return resp; }