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 O2GValueMap and fill only two fields:

Valuemap field

Datatype

Description

Command

string

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 O2GValueMap for each entry order you want to add into the contingency group. Fill these value maps as:

Valuemap field

Datatype

Description

AcctID

string

The identifier of the account which the order belongs to.

The field is obligatory.

OrderID

string

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 O2GValueMap.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 O2GRequest (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 an new contingency group [hide]

    static bool PrepareParamsFromLoginRules(out string sAccountID, out string sOfferID, out int iBaseAmount, out double dPointSize, out double dAskRate, out double dBidRate)
    {
        bool bOK = false;
        O2GResponseReaderFactory factory = session.getResponseReaderFactory();
        if (factory == null)
            return bOK;
        O2GLoginRules loginRules = session.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
        sAccountID = account.AccountID;
        // get base amount
        iBaseAmount = account.BaseUnitSize;
        sOfferID = "";
        dAskRate = 0;
        dBidRate = 0;
        dPointSize = 0;
        // Get offers for EUR/USD
        O2GResponse offersResponse = loginRules.getTableRefreshResponse(O2GTable.Offers);
        O2GOffersTableResponseReader offersReader = factory.createOffersTableReader(offersResponse);
        for (int i = 0; i < offersReader.Count; i++)
        {
            O2GOfferRow offer = offersReader.getRow(i);
            if (String.Equals(offer.Instrument, "EUR/USD"))
            {
                sOfferID = offer.OfferID;
                dAskRate = offer.Ask;
                dBidRate = offer.Bid;
                dPointSize = offer.PointSize;
                bOK = true;
                break;
            }
        }
        return bOK;
    }
 
    static void JoinNewContigencyGroup(string sAccountID, int iContingencyType, string sPrimaryID, string sSecondaryID1, string sSecondaryID2)
    {
        O2GRequestFactory factory = session.getRequestFactory();
        if (factory == null)
            return;
        O2GValueMap valuemap = factory.createValueMap();
        valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.JoinToNewContingencyGroup);
        //set contingencyType for created group
        valuemap.setInt(O2GRequestParamsEnum.ContingencyGroupType, iContingencyType);
 
        // primary order
        valuemap.appendChild(CreateValueMapForExistingOrder(sPrimaryID, sAccountID));
        // secondary order
        valuemap.appendChild(CreateValueMapForExistingOrder(sSecondaryID1, sAccountID));
        // secondary order
        valuemap.appendChild(CreateValueMapForExistingOrder(sSecondaryID2, sAccountID));
 
        // create request from valueMap
        responseListener.SendRequest(valuemap);
    }
 
    // Helper method for creating valueMap for existing order
    static O2GValueMap CreateValueMapForExistingOrder(string sOrderID, string sAccountID)
    {
      O2GRequestFactory factory = session.getRequestFactory();
      O2GValueMap valuemap = factory.createValueMap();
 
      valuemap.setString(O2GRequestParamsEnum.OrderID, sOrderID);
      valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID);
      return valuemap;
    }

back