Add Existing Orders into Existing Contingency Group

You can add one or more existing entry order into an existing contingency (OCO, OTO or ELS) group.

To join orders into a group:

1) Create an IO2GValueMap and fill three fields:

Valuemap field

Datatype

Description

Command

const char *

The command. Must be JoinToExistingContingencyGroup.

The field is obligatory.

ContingencyID

const char *

The identifier of an existing contingency group.

The field is obligatory.

ContingencyGroupType

int

The type of the 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 an 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.

Please note that only dependent orders may be added into OTO or ELS groups.

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 processed, 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.

The createOrderRequest method will return a list of request ids for entry orders processed.

Example: Add existing orders into an existing 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::joinToExistingContingencyGroup(const char* accountID, int contingencyType, const char* groupID, const char* secID1, const char* secID2)
  {
      using namespace O2G2;
      O2G2Ptr<IO2GRequestFactory> factory = mSession->getRequestFactory();
 
      O2G2Ptr<IO2GValueMap> valuemap = factory->createValueMap();
      valuemap->setString(Command, Commands::JoinToExistingContingencyGroup);
      valuemap->setString(ContingencyID, groupID);
      //set contingency type of existing group
      valuemap->setInt(ContingencyGroupType, contingencyType);
 
      // 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