The REST API exposes five order-management endpoints. Each endpoint is provided in three overload forms so that the caller can choose the level of control required.
| Method | Description |
| NewTradeOrder | Places a market / at-best trade order on a CFD market. |
| UpdateTradeOrder | Attaches or changes attached stop / limit protection on an existing open trade. |
| NewStopLimitOrder | Places a pending stop or limit order (not yet in the market). |
| UpdateStopLimitOrder | Amends an existing pending stop or limit order. |
| CancelOrder | Cancels a pending stop or limit order. |
Every order method is available in three overloads:
Buy 1000 EUR/USD at market with an attached take-profit and stop-loss
oForex := TsgcWSAPI_Forex.Create(nil);
oForex.Credentials.UserName := '<username>';
oForex.Credentials.Password := '<password>';
oForex.Credentials.AppKey := '<appkey>';
oForex.Connect;
oOrder := TsgcHTTPForexTradeOrder.Create;
try
oOrder.MarketId := 401484830;
oOrder.TradingAccountId:= oForex.TradingAccountId;
oOrder.Direction := fdBuy;
oOrder.Quantity := 1000;
oOrder.BidPrice := 1.09120;
oOrder.OfferPrice := 1.09130;
// attached take-profit at +50 pips (limit)
oIfDoneTP := TsgcHTTPForexIfDoneOrder.Create;
oIfDoneTP.Direction := fdSell;
oIfDoneTP.Quantity := 1000;
oIfDoneTP.TriggerPrice := 1.09630;
oOrder.IfDone.AddLimit(oIfDoneTP);
// attached stop-loss at -30 pips (stop)
oIfDoneSL := TsgcHTTPForexIfDoneOrder.Create;
oIfDoneSL.Direction := fdSell;
oIfDoneSL.Quantity := 1000;
oIfDoneSL.TriggerPrice := 1.08830;
oOrder.IfDone.AddStop(oIfDoneSL);
ShowMessage(oForex.REST_API.NewTradeOrder(oOrder));
finally
oOrder.Free;
end;