Create OCO Orders

From FxCodeBaseWiki
(Redirected from How to Create OCO Orders)
Jump to: navigation, search

Read First

Start Using

Please read Start Using ForexConnect in C++ project first to understand how to use ForexConnect API in your C++ project.

Login

To execute any command you must be logged in. See How to login in ForexConnect API SDK for details.

OCO Order

Scope

OCO Order (One Cancels the Others) is an order which contains two or more linked entry orders. When the market price reaches the price of one of the orders, this order is executed while the other orders are automatically cancelled.

Please see the article OCO Order for details about effective usage of OCO orders.

In ForexConnect API, an OCO order is created and modified as a batch request of a special type. See How to Use Batch Command for details about creating batch requests.

Restrictions

There are the following restrictions:

  1. Only entry orders can be joined into OCO. However, entry orders with attached stops and limits, either regular or ELS, can be joined into OCO.
  2. All entry orders must be created for the same account.

Creating OCO Order

To create a new OCO order, use the CreateOCO command of a batch request.

Note that the entry orders that are parts of OCO have Commands::CreateOrder as a Command parameter. Parameters of a child request for creating an entry order as a part of OCO are same as for creating a regular entry order. See the ConditionalOrders SDK article for details.

As OCO is a batch request, you will not receive a response for a whole OCO request, instead you will receive responses for each child request. You can get and store their RequestIDs by enumerating child requests of the OCO request:

      O2G2Ptr<IO2GRequest> OCORequest = factory->createOrderRequest(OCOValueMap);
      for (int i = 0; i < OCORequest->getChildrenCount(); i++)
      {
          O2G2Ptr<IO2GRequest> childRequest = OCORequest->getChildRequest(i);
          //mOCOChildRequestsIDs.Add(childRequest->getRequestID()); //get and store "child" entry order RequestId
      }
      mSession->sendRequest(request);

See the Create OCO Orders ForexConnect SDK article for example of OCO order creation.

Joining to OCO

To add an existing entry order to an existing OCO group, use the JoinToOCO command. All child requests of the JoinToOCO batch request must have the JoinToOCO command name too.

You must specify the following command parameters for the child request:

  • Command (must be "JoinToOCO")
  • AccountID (must be the same as AccountID of the OCO order)
  • OCOBulkID (the OCO order ID which can be obtained using the IO2GOrderRow::getContingentOrderID method with any other entry order of OCO)
  • OrderID (the order ID of the exisiting entry order which you include in OCO)

Excluding from OCO

To exclude an entry order from OCO, use the ExcludeFromOCO command. For a child request of a batch OCO request, you must specify the following parameters:

  • Command (must be "ExcludeFromOCO")
  • OrderID (the order ID of the entry order that you want to exclude from OCO)
  • AccountID

The entry order will be excluded from the OCO which it belonged to.

Searching for OCO Orders

To check if an order is a part of OCO, you can use the IO2GOrderRow::getContingencyType and IO2GOrderRow::getContingentOrderID methods.

This Article in Other Languages

Language: English  • español • français • русский • 中文 • 中文(繁體)‎