metadev 0 Report post Posted July 23, 2013 Hi, I am trying to open a trade with a stop but I am getting a ‘Server Error’ when I submit. If I leave the IfDone as null then the trade opens fine so it is something to do with the stop. Can somebody help? NewTradeOrderRequestDTO newTradeOrderRequestDTO = new NewTradeOrderRequestDTO { MarketId = Convert.ToInt32(Frame.Symbol), AuditId = TradeValue.AuditID, BidPrice = Convert.ToDecimal(TradeValue.Bid.Price), OfferPrice = Convert.ToDecimal(TradeValue.Ask.Price), Direction = (IsLong) ? "buy" : "sell", Quantity = 1, TradingAccountId = TradingAccountID, PositionMethodId = 1, AutoRollover = false, Currency = Frame.Currency, }; List<ApiIfDoneDTO> apiIfDoneDTO = new List<ApiIfDoneDTO>(); apiIfDoneDTO.Add(new ApiIfDoneDTO()); double stopLoss = (IsLong) ? TradeValue.Bid.Price - StopLoss : TradeValue.Ask.Price + StopLoss; var apiStopLimitOrderDTO = new ApiStopLimitOrderDTO { Applicability = "GTC", ExpiryDateTimeUTC = null, Guaranteed = false, LastChangedDateTimeUTC = DateTime.Now, ParentOrderId = null, TriggerPrice = Convert.ToDecimal(stopLoss), }; apiIfDoneDTO[0].Stop = apiStopLimitOrderDTO; newTradeOrderRequestDTO.IfDone = apiIfDoneDTO.ToArray(); ApiTradeOrderResponseDTO response = rpcClient.TradesAndOrders.Trade(newTradeOrderRequestDTO); Share this post Link to post
marc 0 Report post Posted July 24, 2013 Hi, the problem could be that you are not setting all the necessary information in ApiStopLimitOrderDTO. I can open a trade with Stop/Limit when I set the following fields in this DTO: “TradingAccountId, TriggerPrice, Direction, MarketId, Quantity” So you could try something like this: var apiStopLimitOrderDTO = new ApiStopLimitOrderDTO { TradingAccountId = TradingAccountID, TriggerPrice = Convert.ToDecimal(stopLoss), Direction = (IsLong) ? "sell" : "buy", //opposite direction MarketId = Convert.ToInt32(Frame.Symbol), Quantity = 1 }; I don’t need to set any other values (in my case) and it works with just those fields set. Hope it helps… Share this post Link to post
metadev 0 Report post Posted July 24, 2013 Hi Marc, Thanks for the help. It works well and thanks also for the heads up on switching buy and sell direction. The API docs could do with a re-work in this area I think as they are clearly wrong. Regards David Share this post Link to post