Create New Contingency Group

You can join two or more existing entry orders into a new contingency (OCO, OTO or ELS) group.

To join orders into a contingency group:

1) Create an IO2GValueMap and fill only two fields:

Valuemap field

Datatype

Description

Command

const char *

The command. Must be JoinToNewContingencyGroup.

The field is obligatory.

ContingencyGroupType

int

The type of a new contingency group. Must be:

1

OCO group.

2

OTO group.

3

ELS group.

The field is obligatory.

2) Create an IO2GValueMap for each entry order you want to add into the contingency group. Fill these value maps as:

Valuemap field

Datatype

Description

AcctID

const char *

The identifier of the account which the order belongs to.

The field is obligatory.

OrderID

const char *

The identifier of the order to be included into the group.

The order must exist, must be an entry order (LE or SE) and must be in the Waiting status.

The field is obligatory.

3) Append each entry order valuemap to the main valuemap using the IO2GValueMap.appendChild method.

For OTO and ELS groups, append the order that must be a root order of the contingency group first.

4) Pass the main valuemap table to the createOrderRequest method.

Limitations:

1) All entry orders must be created for the same account.

Returns:

The createOrderRequest method will return an IO2GRequest (the main request) containing child requests. If 3 entry orders are created, 3 child requests will be returned. Note that you will receive responses to the child requests and will not receive a response to the main request.

Example: Create a new contingency group [hide]

  void CExample::prepareParamsFromLoginRules(IO2GLoginRules *loginRules)
  {
      mParams = new OrderCreationParam();
 
 
      O2G2Ptr<IO2GResponseReaderFactory> factory = mSession->getResponseReaderFactory();
      // Get 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;
          }
      }
  }
 
  // Helper method for creating valueMap for existing order
  IO2GValueMap* CExample::existOrder(const char* orderID, const char* accountID)
  {
      using namespace O2G2;
      O2G2Ptr<IO2GRequestFactory> factory = getRequestFactory();
 
      IO2GValueMap* valuemap = factory->createValueMap();
 
      valuemap->setString(OrderID, orderID);
      valuemap->setString(AccountID, accountID);
 
      return valuemap;
  }
 
  void CreateOrderSample::joinToNewContingencyGroup(const char* accountID, int contingencyType, const char* primaryID, const char* secID1, const char* secID2)
  {
      using namespace O2G2;
      O2G2Ptr<IO2GRequestFactory> factory = mSession->getRequestFactory();
 
      O2G2Ptr<IO2GValueMap> valuemap = factory->createValueMap();
      valuemap->setString(Command, Commands::JoinToNewContingencyGroup);
      //set contingency type for created group
      valuemap->setInt(ContingencyGroupType, contingencyType);
 
      // primary order
      valuemap->appendChild(existOrder(primaryID, accountID));
      // secondary order
      valuemap->appendChild(existOrder(secID1, accountID));
      // secondary order
      valuemap->appendChild(existOrder(secID2, accountID));
 
      // create request from valueMap
      O2G2Ptr<IO2GRequest> request = factory->createOrderRequest(valuemap);
      for (int i = 0; i < request->getChildrenCount(); i++)
      {
          O2G2Ptr<IO2GRequest> childRequest = request->getChildRequest(i);
          mActions[childRequest->getRequestID()] = manageOTOAction;
      }
      mSession->sendRequest(request);
  }

back