Create an Entry Stop Order

A regular entry order opens a position when the specified market condition is met.

A netting entry order closes all positions for the specified instrument and account which are in the direction (buy or sell) opposite to the direction of the entry order.

A stop entry order with a sell direction is filled when the market is below the rate specified in the order.

A stop entry order with a buy direction is filled when the market is above the rate specified in the order.

Please note that if hedging is disabled for the account, the order, first, closes existing opposite positions for the same account and instrument and only then opens a new position in the remaining amount.

Parameter name

Datatype

Description

Command

const char *

The command. Must be CreateOrder.

OrderType

const char *

The type of the order. Must be SE.

OfferID

const char *

The identifier of the instrument the order should be placed for. The value must be obtained from the Offers table, the OfferID column.

AccountID

const char *

The identifier of the account the order should be placed for. The value must be obtained from the Accounts table, the AccountID column.

Please note that the account identifier may not necessarily be equal to the account name which is shown in the Trading Station application.

BuySell

const char *

The order direction.

The value must be B - for buy orders and S - for sell orders.

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 not be specified in case the NetQuantity parameter is used.

NetQuantity

const char *

The net quantity flag. Use this parameter with the value y or Y only for a net quantity order.

An entry order in the netting mode does not create any positions but 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 BuySell) opposite to the direction of the order.

Rate

double

The rate at which the order must be filled.

The sell order rate must be below the market. The buy order rate must be above the market.

TrailStep

int

The trailing entry order follows the market in case the market moves in the direction opposite to that of the order (i.e. when the distance between the order and the current market price increases).

The value specifies the maximum change of the market price after which the rate of the order will be changed as well.

The value is expressed in the units of the minimum change of the price (see the Digits column of the Offers table).

For example, if the value in the Digits column is 3 and the value of this field is 5, the maximum change of the market price will be 5 * 10-3 = 0.005.

If the value is 1, it means that the dynamic trailing mode is used, i.e. the order rate is changed with every change of the market price. Please note that in some systems, only dynamic trailing mode is supported.

The value is optional. By default, this value is 0. 0, it means a non-trailing order.

If the value is specified, the order type in the Orders table will be STE.

TimeInForce

const char *

The Time In Force value.

Can be GTC (Good Till Cancelled) or DAY (Day Order).

The value is optional.

Entry 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:

Table

Column for opening order

Column for closing order

Orders

RequestTXT

RequestTXT

Trades

OpenOrderRequestTXT

N/A

Closed Trades

OpenOrderRequestTXT

CloseOrderRequestTXT

The value is optional.

You can also create a pair of stop and limit orders for the trade using the same command. Please refer to Attach Stop and/or Limit Orders to the Command for details.

Example: Create an Entry Stop 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::prepareParamsAndCallEntryStopOrder(const char *offerID, const char *accountID, int amount, double pointSize, int numPoints, const char * buySell)
  {
      double curRate = 0;
      double orderRate = 0;
      if (!strcmp(buySell, "B"))
      {
          curRate = mParams->mAsk;
          orderRate = curRate + pointSize * numPoints;  // The buy order rate must be above the market.
      }
      else    // BuySell = "S"
      {
          curRate = mParams->mBid;
          orderRate = curRate - pointSize * numPoints;  // The sell order rate must be below the market.
      }
      createEntryStopOrder(offerID, accountID, amount, orderRate, buySell);
  }
 
  void CreateOrderSample::createEntryStopOrder(const char * offerID, const char * accountID, 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::StopEntry);
      valuemap->setString(AccountID, accountID);         // The identifier of the account the order should be placed for.
      valuemap->setString(OfferID, offerID);             // The identifier of the instrument the order should be placed for.
      valuemap->setString(BuySell, buySell);             // The order direction ("B" for buy, "S" for sell)
      valuemap->setDouble(Rate, rate);                 // The rate at which the order must be filled (above current rate for Buy, bellow current rate for Sell)
      valuemap->setInt(Amount, amount);                 // The quantity of the instrument to be bought or sold.
      valuemap->setString(CustomID, "StopEntryOrder"); // The custom identifier of the order.
 
      O2G2Ptr<IO2GRequest> request = factory->createOrderRequest(valuemap);
      mSession->sendRequest(request);
      // Store request and set delete actions. After order has been created
      // then delete its.
      mActions[request->getRequestID()] = deleteOrderAction;
  }

back