You can close an open trade or delete a pending order by using
Deletion of a pending order is simple because it can have no properties other than the
// Delete pending order O12345
Framework.SendOrder({
tradingAction: FXB.OrderTypes.CLOSE,
orderId: "O12345"
}, function (MsgResult) {
…
});
Closure of an open trade is slightly more complicated because you can optionally do a partial close instead of a complete close.
The definition for a full close of an open trade is the same as deletion of a pending order:
// Close (completely) open trade T12345
Framework.SendOrder({
tradingAction: FXB.OrderTypes.CLOSE,
orderId: "T12345"
}, function (MsgResult) {
…
});
To do a partial close, you specify a
| expiry: | Description |
| number | Simple numeric value in cash/units, not lots, to close, such as 10000. (If this exceeds the trade volume, the framework will simply close the trade entirely rather than reporting an error.) |
| {lots: x} | Portion to close in lots, converted by the framework to cash/units using the market's |
| {percent: x} | Close the specified percentage of the trade, always rounding up to the nearest permitted trading increment. See the example below. |
The following request closes 75% of trade T12345. This is subject to the trading minimums and increments for the market. For example, if T12345 is a position of 3000 cash/units, and the minimum/increment volume for orders in this market is 1000, then the following instruction will be interpreted as a complete close. The framework always rounds up when doing a close. It will calculate 75% of 3000 = 2250, and round that up to the nearest permitted increment of 1000… which is a complete close of all 3000 cash/units.
// Close 75% of trade T12345
Framework.SendOrder({
tradingAction: FXB.OrderTypes.CLOSE,
orderId: "T12345",
volume: {percent: 75}
}, function (MsgResult) {
…
});