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

String

The command. Must be CreateOrder.

ORDER_TYPE

String

The type of the order. Must be OR.

OFFER_ID

or

SYMBOL

String

OFFER_ID: 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".

ACCOUNT_ID

String

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.

BUY_SELL

String

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.

RATE_MIN

double

The minimum rate at which the order can be filled.

RATE_MAX

double

The maximum rate at which the order can be filled.

TIME_IN_FORCE

String

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.

CLIENT_RATE

double

The current price of the order instrument.

The value is optional. It is used for logging purposes.

CUSTOM_ID

String

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]

 class ParamsFromLoginRules {
    String sAccountID;
    String sOfferID;
    int iBaseAmount;
    double dPointSize;
    double dAskRate;
    double dBidRate;
}
 
   public void prepareParamsAndCallRangeOrder()
   {
        ParamsFromLoginRules params = new ParamsFromLoginRules();
        boolean bParamsOK = prepareParamsFromLoginRules(params);
        if (!bParamsOK)
            return;
 
        String sBuySell = Constants.Sell;
        double dCurrentRate = params.dBidRate;
        int iAtMarket = 20;
        double dRateMin = dCurrentRate - params.dPointSize * iAtMarket;
        double dRateMax = dCurrentRate + params.dPointSize * iAtMarket;
        createRangeOrder(params.sOfferID, params.sAccountID, params.iBaseAmount * 4, dRateMin, dRateMax, sBuySell);
   }
 
   public void createRangeOrder(String sOfferID, String sAccountID, int iAmount, double dRateMin, double dRateMax, String sBuySell)
   {
       O2GRequestFactory factory = mSession.getRequestFactory();
       if (factory == null) {
           return;
       }
       O2GValueMap valuemap = factory.createValueMap();
       valuemap.setString(O2GRequestParamsEnum.COMMAND, Constants.Commands.CreateOrder);
       valuemap.setString(O2GRequestParamsEnum.ORDER_TYPE, Constants.Orders.MarketOpenRange);
       valuemap.setString(O2GRequestParamsEnum.ACCOUNT_ID, sAccountID);       // The identifier of the account the order should be placed for.
       valuemap.setString(O2GRequestParamsEnum.OFFER_ID, sOfferID);           // The identifier of the instrument the order should be placed for.
       valuemap.setString(O2GRequestParamsEnum.BUY_SELL, sBuySell);           // The order direction (Constants.Buy for buy, Constants.Sell for sell).
       valuemap.setDouble(O2GRequestParamsEnum.RATE_MIN, dRateMin);           // The minimum dRate at which the order can be filled.
       valuemap.setDouble(O2GRequestParamsEnum.RATE_MAX, dRateMax);           // The maximum dRate at which the order can be filled.
       valuemap.setInt(O2GRequestParamsEnum.AMOUNT, iAmount);
 
       O2GRequest request = factory.createOrderRequest(valuemap);
       mSession.sendRequest(request);
    }
 
    private boolean prepareParamsFromLoginRules(ParamsFromLoginRules params)
    {
        boolean bOK = false;
        O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();
        if (factory == null) {
            return false;
        }
        O2GLoginRules loginRules = mSession.getLoginRules();
        // get first account from login
        O2GResponse accountResponse = loginRules.getTableRefreshResponse(O2GTable.ACCOUNTS);
        O2GAccountsTableResponseReader accountsReader = factory.createAccountsTableReader(accountResponse);
        O2GAccountRow account = accountsReader.getRow(0);
        // get account id
        params.sAccountID = account.getAccountID();
        // get base amount
        params.iBaseAmount = account.getBaseUnitSize();
        params.sOfferID = "";
        params.dAskRate = 0;
        params.dBidRate = 0;
        params.dPointSize = 0;
        // Get offers for EUR/USD
        O2GResponse offersResponse = loginRules.getTableRefreshResponse(O2GTable.OFFERS);
        O2GOffersTableResponseReader offersReader = factory.createOffersTableReader(offersResponse);
        for (int i = 0; i < offersReader.size(); i++)
        {
            O2GOfferRow offer = offersReader.getRow(i);
            if (offer.getInstrument().equals("EUR/USD"))
            {
                params.sOfferID = offer.getOfferID();
                params.dAskRate = offer.getAsk();
                params.dBidRate = offer.getBid();
                params.dPointSize = offer.getPointSize();
                bOK = true;
                break;
            }
        }
        return bOK;
    }

back