Create OCO Orders
You can create two or more entry orders and then join them into OCO using just one call.
To create an OCO order:
1) Create an O2GValueMap
and specify only one parameter:
Parameter name |
Datatype |
Description |
COMMAND |
String |
The command. Must be The field is obligatory. |
2) Create an O2GValueMap
for each entry order you want to create and
fill it as for a regular entry order.
3) Append each entry order value map to the main value map using the O2GValueMap.appendChild
method.
4) Pass the main IO2GValueMap
to the createOrderRequest
method.
Limitations:
1) Only entry orders can be joined into OCO. However, Entry orders with attached stop limits, either regular or ELS can be joined into OCO.
2) All entry orders must be created for the same account.
Returns:
The createOrderRequest method will return the list of request IDs for each entry order created. So, if 3 entry orders are created - 3 request IDs separated by commas (,) will be returned. Moreover, if any of the orders is an ELS order, 3 request IDs will be returned per each ELS order inside the OCO.
Example: Create an OCO order [hide]
class ParamsFromLoginRules { String sAccountID; String sOfferID; int iBaseAmount; double dPointSize; double dAskRate; double dBidRate; } private void prepareAndCreateOCO() { ParamsFromLoginRules params = new ParamsFromLoginRules(); boolean bParamsOK = prepareParamsFromLoginRules(params); if (!bParamsOK) return; O2GRequestFactory factory = mSession.getRequestFactory(); if (factory == null) { return; } O2GValueMap mainValueMap = factory.createValueMap(); mainValueMap.setString(O2GRequestParamsEnum.COMMAND, Constants.Commands.CreateOCO); String sAccountID = params.sAccountID; double dRate = params.dAskRate; int iAmount = params.iBaseAmount; String sBuySell = Constants.Buy; String sOrderType = Constants.Orders.LimitEntry; double dOrderRate = dRate - 50 * params.dPointSize; String sOfferID = params.sOfferID; O2GValueMap valuemap1 = createOrder(sAccountID, sOfferID, dOrderRate, iAmount, sBuySell, sOrderType); mainValueMap.appendChild(valuemap1); dOrderRate = dRate + 50 * params.dPointSize; sBuySell = Constants.Sell; sOrderType = Constants.Orders.LimitEntry; O2GValueMap valuemap2 = createOrder(sAccountID, sOfferID, dOrderRate, iAmount, sBuySell, sOrderType); mainValueMap.appendChild(valuemap2); O2GRequest request = factory.createOrderRequest(mainValueMap); 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; }