Create a Close Market Order
A close market order closes a position at any currently available market rate.
Please note that close orders must be permitted for the account in order to be used.
Please note that netting close order (see NetQuantity below) can be executed even if close orders are disabled.
Parameter name |
Datatype |
Description |
||||||
Command |
string |
The command. Must be |
||||||
OrderType |
string |
The type of the order. Must be |
||||||
OfferID |
string |
The identifier of the instrument the order should be placed for.
The value must be obtained from the Offers table, the |
||||||
AccountID |
string |
The identifier of the account the order should be placed for.
The value must be obtained from the Accounts table, the Please note that the account identifier may not necessarily be equal to the account name which is shown in the Trading Station application. |
||||||
TradeID |
string |
The identifier of the trade to be closed. The value must be obtained from the Trades table, the Do not fill this value for a net quantity order. |
||||||
BuySell |
string |
The order direction. The value must be |
||||||
Amount |
int |
The amount of the order. In the case of FX instruments, the amount is expressed in the base currency of an instrument. In the case of CFD instruments, the amount is expressed in contracts. Must be divisible by the value of the lot size. The amount must be less than or equal to the size of the position (see the Do not fill this value for a net quantity order. |
||||||
NetQuantity |
string |
The net quantity flag. Use this parameter with the value A close order in the netting mode closes all positions which
exist at the moment of the order filling and which are created for the
order account and order instrument in the direction (see |
||||||
TimeInForce |
string |
The Time In Force value. Can be Close Market orders are |
||||||
ClientRate |
double |
The current price of the order instrument. The value is optional. It is used for logging purposes. |
||||||
CustomID |
string |
The custom identifier of the order. This value will be populated into these columns of the trading tables:
The value is optional. |
Create a Close Market order [hide]
public void PrepareParamsFromLoginRules(O2GLoginRules loginRules) { mParams = new OrderCreationParameters(); O2GResponseReaderFactory factory = mSession.getResponseReaderFactory(); if (factory == null) return; // Gets first account from login. O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTable.Accounts); O2GAccountsTableResponseReader accountsReader = factory.createAccountsTableReader(accountsResponse); O2GAccountRow account = accountsReader.getRow(0); // Store account id mParams.AccountID = account.AccountID; // Store base iAmount mParams.BaseAmount = account.BaseUnitSize; // Get offers for eur/usd O2GResponse offerResponse = loginRules.getTableRefreshResponse(O2GTable.Offers); O2GOffersTableResponseReader offersReader = factory.createOffersTableReader(offerResponse); for (int i = 0; i < offersReader.Count; i++) { O2GOfferRow offer = offersReader.getRow(i); if (string.Compare(offer.Instrument, "EUR/USD", true) == 0) { mParams.OfferID = offer.OfferID; mParams.Ask = offer.Ask; mParams.Bid = offer.Bid; mParams.PointSize = offer.PointSize; break; } } } public void PrepareParamsAndCallTrueMarketCloseOrder(O2GTradeRow tradeRow) { //The order direcion of the close order must be opposite to the direction of the trade. string sTradeBuySell = tradeRow.BuySell; if (sTradeBuySell == Constants.Buy) // trade BuySell=Constants.Buy = order BuySell = Constants.Sell CreateTrueMarketCloseOrder(tradeRow.OfferID, tradeRow.AccountID, tradeRow.TradeID, tradeRow.Amount, Constants.Sell); else // trade BuySell=Constants.Sell = order BuySell = Constants.Buy CreateTrueMarketCloseOrder(tradeRow.OfferID, tradeRow.AccountID, tradeRow.TradeID, tradeRow.Amount, Constants.Buy); } public void CreateTrueMarketCloseOrder(string sOfferID, string sAccountID, string sTradeID, int iAmount, string sBuySell) { O2GRequestFactory factory = mSession.getRequestFactory(); if (factory == null) return; O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); // The identifier of the account the order should be placed for. valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for. // valuemap.setString(O2GRequestParamsEnum.TradeID, sTradeID); // The identifier of the trade to be closed (do not fill for Net amount order). // valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The quantity of the instrument to be bought or sold (do not fill for Net amount order). Must be <= to the size of the position. valuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); // The order direction: Constants.Buy for Buy, Constants.Sell for Sell. Must be opposite to the direction of the trade. valuemap.setString(O2GRequestParamsEnum.CustomID, "CloseTrueMarketOrder"); // The custom identifier of the order. O2GRequest request = factory.createOrderRequest(valuemap); mSession.sendRequest(request); }