Create a Limit Order
A limit order is used for locking in profit of the existing position when the market condition is met.
Limit orders can be created for existing trades as well as for existing entry orders. Limit orders created for entry orders remain inactive until the trade is created by the entry order.
Only one limit order can be attached to a position or an entry order.
Please note that close orders must be permitted for the account in order to be used.
Please note that stop and limit orders cannot be attached to netting entry orders.
Parameter name |
Datatype |
Description |
||||||
Command |
const char * |
The command. Must be |
||||||
OrderType |
const char * |
The type of the order. Must be |
||||||
OfferID |
const char * |
The identifier of the instrument the order should be placed for.
The value must be obtained from the Offers table, the |
||||||
AccountID |
const char * |
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 |
const char * |
The identifier of the trade to be closed.
The value must be obtained from the Trades table, the |
||||||
BuySell |
const char * |
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 equal to the size of the position (see the |
||||||
Rate |
double |
The rate at which the order must be filled. The rate must be above the market for sell orders and below the market for buy orders. To specify the limit order price, use:
|
||||||
PegType |
const char * |
"Pegged" means that the price is specified as an offset (in pips) against the market price. The field specifies which price should be used to calculate the order price:
Please note that "pegged" orders are stored as "pegged" only while the order is attached to an entry order. Once the entry order gets filled and a position is opened, the peg price is automatically converted to a regular market price. |
||||||
PegOffset |
int |
The offset to the price specified in the The offset must be negative for buy orders and positive for sell orders. |
||||||
TimeInForce |
const char * |
The Time In Force value. Can be GTC (Good Till Cancelled) or DAY (Day Order). The value is optional. Limit orders are GTC orders by default. |
||||||
ClientRate |
double |
The current price of the order instrument. The value is optional. It is used for logging purposes. |
||||||
CustomID |
const char * |
The custom identifier of the order. This value will be populated into these columns of the trading tables:
The value is optional. |
Example: Create a Limit order [hide]
void CreateOrderSample::prepareParamsFromLoginRules(IO2GLoginRules *loginRules) { mParams = new OrderCreationParam(); O2G2Ptr<IO2GResponseReaderFactory> factory = mSession->getResponseReaderFactory(); // Gets first account from login. O2G2Ptr<IO2GResponse> accountsResponse = loginRules->getTableRefreshResponse(Accounts); O2G2Ptr<IO2GAccountsTableResponseReader> accountsReader = factory->createAccountsTableReader(accountsResponse); O2G2Ptr<IO2GAccountRow> account = accountsReader->getRow(0); // Store account id mParams->mAccountID = account->getAccountID(); // Store base amount mParams->mBaseAmount = account->getBaseUnitSize(); // Get offers for eur/usd O2G2Ptr<IO2GResponse> offerResponse = loginRules->getTableRefreshResponse(Offers); O2G2Ptr<IO2GOffersTableResponseReader> offersReader = factory->createOffersTableReader(offerResponse); for (int i = 0; i < offersReader->size(); i++) { O2G2Ptr<IO2GOfferRow> offer = offersReader->getRow(i); if (_stricmp(offer->getInstrument(), "EUR/USD") == 0) { mParams->mOfferID = offer->getOfferID(); mParams->mAsk = offer->getAsk(); mParams->mBid = offer->getBid(); mParams->mPointSize = offer->getPointSize(); break; } } } void CreateOrderSample::prepareParamsAndCallLimitOrder(IO2GTradeRow * trade, int atMarket) { const char * tradeBuySell = trade->getBuySell(); // Close order is opposite to the trade bool buyOrder = false; if (!strcmp (tradeBuySell, "S")) buyOrder = true; const char * tradeOfferID = trade->getOfferID(); double curRate = 0; double limitRate = 0; double pointSize = mParams->mPointSize; if (buyOrder) { curRate = mParams->mAsk; limitRate = curRate - atMarket * pointSize; } else { curRate = mParams->mBid; limitRate = curRate + atMarket * pointSize; } createLimitOrder(tradeOfferID, trade->getAccountID(), trade->getTradeID(), trade->getAmount(), limitRate, buyOrder ? O2G2::Buy : O2G2::Sell); } void CreateOrderSample::createLimitOrder(const char *offerID, const char *accountID, const char *tradeID, int amount, double rate, const char * buySell) { using namespace O2G2; O2G2Ptr<IO2GRequestFactory> factory = mSession->getRequestFactory(); O2G2Ptr<IO2GValueMap> valuemap = factory->createValueMap(); valuemap->setString(Command, Commands::CreateOrder); valuemap->setString(OrderType, Orders::Limit); valuemap->setString(AccountID, accountID); valuemap->setString(OfferID, offerID); // The identifier of the instrument the order should be placed for valuemap->setString(TradeID, tradeID); // The identifier of the trade to be closed valuemap->setString(BuySell, buySell); // The order direction("B" for Buy, "S" for Sell). Must be opposite to the direction of the trade valuemap->setInt(Amount, amount); // The quantity of the instrument to be bought or sold. Must == the size of the position (Lot of the trade). valuemap->setDouble(Rate, rate); // The rate at which the order must be filled (> market for Sell, < market for Buy) valuemap->setString(CustomID, "LimitOrder"); // The custom identifier of the order O2G2Ptr<IO2GRequest> request = factory->createOrderRequest(valuemap); mSession->sendRequest(request); }