Create an Open Range Order

An open range order opens a position at the available market rate in case this rate is in the range specified in the command.

Please note that if hedging is disabled for the account, the command, 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 OR.

OfferID

or

Symbol

const char *

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

or

Symbol: The name of the currency pair. For example: "EUR/USD".

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.

RateMin

double

The minimum rate at which the order can be filled.

RateMax

double

The maximum rate at which the order can be filled.

TimeInForce

const char *

The Time In Force value.

Can be IOC (Immediate Or Cancel) or FOK (Fill Or Kill).

The value is optional.

Open Range orders are IOC 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 Open Range 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::prepareParamsAndCallRangeOrder(const char *offerID, const char *accountID, int amount, double pointSize, int atMarket, const char * buySell)
  {
      bool bBuy = strcmp(buySell, O2G2::Buy) == 0;
      double curRate =  bBuy ? mParams->mAsk : mParams->mBid;
      double rateMin = curRate - pointSize * atMarket;
      double rateMax = curRate + pointSize * atMarket;
      createRangeOrder(offerID, accountID, amount, rateMin, rateMax, buySell);
  }
 
  void CreateOrderSample::createRangeOrder(const char *offerID, const char *accountID, int amount, double rateMin, double rateMax, 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::MarketOpenRange);
      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(RateMin, rateMin);           // The minimum rate at which the order can be filled.
      valuemap->setDouble(RateMax, rateMax);           // The maximum rate at which the order can be filled.
      valuemap->setString(CustomID, "OpenRangeOrder"); // The custom identifier of the order.
      valuemap->setInt(Amount, amount);
 
      O2G2Ptr<IO2GRequest> request = factory->createOrderRequest(valuemap);
      mSession->sendRequest(request);
  }

back