public OAOrders GetMarketOrders(string accountId, string instrument) { Task <List <Trade> > callTask = Task.Run(() => Rest20.GetOpenTradeListAsync(accountId)); callTask.Wait(); OAOrders oaOrders = new OAOrders(); foreach (Trade trade in callTask.Result.FindAll(x => x.instrument == instrument)) { OAOrder oaOrder = new OAOrder(); oaOrder.Id = trade.id; oaOrder.Units = trade.currentUnits; oaOrder.Instrument = trade.instrument; oaOrder.Price = trade.price; oaOrders.Add(oaOrder); } return(oaOrders); }
public async Task ModifyMarketOrder(string accountId, OAOrder order) { SetCredentials(accountId); PriceInformation priceInformation = new PriceInformation(); priceInformation.instrument = await GetInstrument(accountId, order.Instrument); priceInformation.priceProperties = new List <string>(); PatchExitOrdersRequest request = new PatchExitOrdersRequest(); request.stopLoss = new StopLossDetails(instruments[0]); request.stopLoss.price = Math.Round(order.SL, priceInformation.instrument.displayPrecision); request.stopLoss.timeInForce = TimeInForce.GoodUntilCancelled; if (order.PT > 1) // != 0, kvuli zaokrouhlovani { request.takeProfit = new TakeProfitDetails(instruments[0]); request.takeProfit.price = Math.Round(order.PT, priceInformation.instrument.displayPrecision); request.takeProfit.timeInForce = TimeInForce.GoodUntilCancelled; } else { request.takeProfit = null; } try { TradePatchExitOrdersResponse tradePatchExitOrdersResponse = await Rest20.PatchTradeExitOrders(accountId, order.Id, request); } catch (Exception e) { if (e.Message.IndexOf("NO_SUCH_TRADE") > 0) { return; } throw e; } }