Investing in financial products involves risk to your capital.

Close Navigation
Learn more about IBKR accounts

Order Types

Introduction

This page is used to document all available order types available through the Interactive Brokers API interfaces. The values documented showcase the minimum values needed to create the order. Additional parameters can be used or combined in some cases.

You can find the available fields or parameters for orders in their respective interfaces:

Notes & Limitations

  • While the Interactive Brokers support team can help assist with required parameters for the API, they can not comment on best orders to use, financial or trading advice, or any further information aside from API logic.
  • It is important to test the order type idea manually in TWS before writing the API execution tactic because some execution ideas (e.g. applying STP LMT on Iceberg / applying Bracket Order with IBALGO) may not supported by TWS. As a result, they will not be supported by API too.
  • Paper Trading Accounts are based on a simulated environment, and as a result, order execution behavior is not indicative of real world trading conditions. The paper accounts should be used exclusively for understanding how tools function.
  • It is important to test the order type idea manually in TWS before writing the API execution tactic because some execution ideas (e.g. applying STP LMT on Iceberg / applying Bracket Order with IBALGO) may not supported by TWS. As a result, they will not be supported by API too.
  • Interacive Brokers APIs do not support fractional or cash quantity trading with exception to Cryptocurrencies and Forex trading.

Cryptocurrency Trading

Because Cryptocurrencies at Interactive Brokers are managed through external groups like ZEROHASH and PAXOS, the available order types and behaviors are slightly different from average. The lists below indicate what is available for BUY and SELL orders when using Cryptocurrencies.

Please be aware that no other order types are available for Crypto orders.

BUY

Order Types
  • LMT Order Using “quantity” or “totalQuantity” values.
  • MKT Orders using “cashQty” value.
Time in Force
  • LMT Orders support “DAY”, “GTC”, “IOC”
    • The TWS API Also Supports the “Minutes” time in force.
  • MKT Orders only support “IOC”.

SELL

Order Types
  • LMT Order Using “quantity” or “totalQuantity values.
  • MKT orders using “quantity” or “totalQuantity” values.
Time in Force
  • LMT Orders support “DAY”, “GTC”, “IOC”
    • The TWS API Also Supports the “Minutes” time in force.
  • MKT Orders only support “IOC”.

Order Efficiency Ratio

While Interactive Brokers’ API offerings do maintain their own pacing limitations, Interactive Brokers as a whole maintains an order pacing limitation. This is known as the Order Efficiency Ratio. While this does not typically effect regular traders, automated trading systems may be impacted. This is because OER does not necessarily impact a lower volume of trades, but will effect those who submit thousands of orders without regular execution.

More information about measuring and understanding the order efficiency ratio can be found in our Order Management Overview article.

Order Type by API

It is important to note that while this page does document both our TWS API and CPAPI, not all order types are available in both platforms.

As such, please keep in mind:

  • Orders labeled in Python, Java, C++, C#, and Visual Basic are for use in the TWS API
  • Orders labeled in CURL are for use in the Client Portal API

Basic Orders

This section will explore all available orders through Interactive Brokers that can be accomplished in a single standard request structure. This includes typical behaviors such as Market, Limit, and Stop orders.

Auction Orders

Auction

An Auction order is entered into the electronic trading system during the pre-market opening period for execution at the Calculated Opening Price (COP). If your order is not filled on the open, the order is re-submitted as a limit order with the limit price set to the COP or the best bid/ask after the market opens.

Products: FUT, STK

More on Auction Orders

More on Supported exchanges

order = Order()
order.action = action
order.tif = "AUC"
order.orderType = "MTL"
order.totalQuantity = quantity
order.lmtPrice = price

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.tif("AUC");
order.orderType("MTL");
order.totalQuantity(quantity);
order.lmtPrice(price);

 

Order order;
order.action = action;
order.tif = "AUC";
order.orderType = "MTL";
order.totalQuantity = quantity;
order.lmtPrice = price;

 

Order order = new Order();
order.Action = action;
order.Tif = "AUC";
order.OrderType = "MTL";
order.TotalQuantity = quantity;
order.LmtPrice = price;

 

Dim order As Order = New Order
order.Action = action
order.Tif = "AUC"
order.OrderType = "MTL"
order.TotalQuantity = quantity
order.LmtPrice = price

 

Auction Limit

For option orders routed to the Boston Options Exchange (BOX) you may elect to participate in the BOX’s price improvement auction in pennies. All BOX-directed price improvement orders are immediately sent from Interactive Brokers to the BOX order book, and when the terms allow, IB will evaluate it for inclusion in a price improvement auction based on price and volume priority. In the auction, your order will have priority over broker-dealer price improvement orders at the same price. An Auction Limit order at a specified price. Use of a limit order ensures that you will not receive an execution at a price less favorable than the limit price. Enter limit orders in penny increments with your auction improvement amount computed as the difference between your limit order price and the nearest listed increment.

Products: OPT (BOX only)

More on price improvement orders

order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = price
order.auctionStrategy = auctionStrategy

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.totalQuantity(quantity);
order.lmtPrice(price);
order.auctionStrategy(auctionStrategy);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.lmtPrice = price;
order.auctionStrategy = auctionStrategy;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.LmtPrice = price;
order.AuctionStrategy = auctionStrategy;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.LmtPrice = price
order.AuctionStrategy = auctionStrategy

 

Auction Pegged to Stock

For option orders routed to the Boston Options Exchange (BOX) you may elect to participate in the BOX’s price improvement auction in pennies. All BOX-directed price improvement orders are immediately sent from Interactive Brokers to the BOX order book, and when the terms allow, IB will evaluate it for inclusion in a price improvement auction based on price and volume priority. In the auction, your order will have priority over broker-dealer price improvement orders at the same price. An Auction Pegged to Stock order adjusts the order price by the product of a signed delta (which is entered as an absolute and assumed to be positive for calls, negative for puts) and the change of the option’s underlying stock price. A buy or sell call order price is determined by adding the delta times a change in an underlying stock price change to a specified starting price for the call. To determine the change in price, a stock reference price (NBBO midpoint at the time of the order is assumed if no reference price is entered) is subtracted from the current NBBO midpoint. A stock range may also be entered that cancels an order when reached. The delta times the change in stock price will be rounded to the nearest penny in favor of the order and will be used as your auction improvement amount.

Products: OPT (BOX only)

More on price improvement orders

order = Order()
order.action = action
order.orderType = "PEG STK"
order.totalQuantity = quantity
order.delta = delta
order.startingPrice = startingPrice

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("PEG STK");
order.totalQuantity(quantity);
order.delta(delta);
order.startingPrice(startingPrice);

 

Order order;
order.action = action;
order.orderType = "PEG STK";
order.totalQuantity = quantity;
order.delta = delta;
order.startingPrice = startingPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "PEG STK";
order.TotalQuantity = quantity;
order.Delta = delta;
order.StartingPrice = startingPrice;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "PEG STK"
order.TotalQuantity = quantity
order.Delta = delta
order.StartingPrice = startingPrice

 

Auction Relative

Stock-Option contracts directly routed to BOX will support a Price Improvement Auction Orders compared to standard SMART routing. This order will necessitate a standard Relative / Pegged-To-Primary order with the contract being directly routed to “BOX” rather than “SMART” or another exchange.

Products: OPT (BOX only)

More on price improvement orders

contract.exchange = "BOX"
order = Order()
order.action = action
order.orderType = "REL"
order.totalQuantity = quantity
order.auxPrice = offset

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("REL");
order.totalQuantity(quantity);
order.auxPrice(offset);

 

Order order;
order.action = action;
order.orderType = "REL";
order.totalQuantity = quantity;
order.auxPrice = offset;

 

Order order = new Order();
order.Action = action;
order.OrderType = "REL";
order.TotalQuantity = quantity;
order.AuxPrice = offset;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "REL"
order.TotalQuantity = quantity
order.AuxPrice = offset

 

Block

The Block attribute is used for large volume option orders on ISE that consist of at least 50 contracts. To execute large-volume orders over time without moving the market, use the Accumulate/Distribute algorithm.

Products: OPT

More on Block Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity#Large volumes!
order.lmtPrice = price
order.blockOrder = True

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.totalQuantity(quantity);//Large volumes!
order.lmtPrice(price);
order.blockOrder(true);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.lmtPrice = price;
order.blockOrder = true;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;//Large volumes!
order.LmtPrice = price;
order.BlockOrder = true;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity ' Large volumes!
order.LmtPrice = price
order.BlockOrder = True

 

Box Top

A Box Top order executes as a market order at the current best price. If the order is only partially filled, the remainder is submitted as a limit order with the limit price equal to the price at which the filled portion of the order executed.

Products: OPT (BOX only)

More on Box Top Orders

order = Order()
order.action = action
order.orderType = "BOX TOP"
order.totalQuantity = quantity

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("BOX TOP");
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "BOX TOP";
order.totalQuantity = quantity;

 

Order order = new Order();
order.Action = action;
order.OrderType = "BOX TOP";
order.TotalQuantity = quantity;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "BOX TOP"
order.TotalQuantity = quantity

 

Combo Limit

Create combination orders that include options, stock and futures legs (stock legs can be included if the order is routed through SmartRouting). Although a combination/spread order is constructed of separate legs, it is executed as a single transaction if it is routed directly to an exchange. For combination orders that are SmartRouted, each leg may be executed separately to ensure best execution.

Products: OPT, STK, FUT

order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = limitPrice
if nonGuaranteed:
	order.smartComboRoutingParams = []
	order.smartComboRoutingParams.append(TagValue("NonGuaranteed", "1"))

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "LMT",
      "price": price,
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.lmtPrice(limitPrice);
order.totalQuantity(quantity);
if (nonGuaranteed)
{
	order.smartComboRoutingParams().add(new TagValue("NonGuaranteed", "1"));
}

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.lmtPrice = limitPrice;
if(nonGuaranteed){
	TagValueSPtr tag1(new TagValue("NonGuaranteed", "1"));
	order.smartComboRoutingParams.reset(new TagValueList());
	order.smartComboRoutingParams->push_back(tag1);
}

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.LmtPrice = limitPrice;
if (nonGuaranteed)
{
	order.SmartComboRoutingParams = new List<TagValue>();
	order.SmartComboRoutingParams.Add(new TagValue("NonGuaranteed", "1"));
}

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.LmtPrice = limitPrice
If (nonGuaranteed) Then
	order.SmartComboRoutingParams = New List(Of TagValue)
	order.SmartComboRoutingParams.Add(New TagValue("NonGuaranteed", "1"))
End If

 

Combo Limit with Price per Leg

Create combination orders that include options, stock and futures legs (stock legs can be included if the order is routed through SmartRouting). Although a combination/spread order is constructed of separate legs, it is executed as a single transaction if it is routed directly to an exchange. For combination orders that are SmartRouted, each leg may be executed separately to ensure best execution.

Products: OPT, STK, FUT

order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.orderComboLegs = []

for price in legPrices:
	comboLeg = OrderComboLeg()
	comboLeg.price = price
	order.orderComboLegs.append(comboLeg)
   
if nonGuaranteed:
	order.smartComboRoutingParams = []
	order.smartComboRoutingParams.append(TagValue("NonGuaranteed", "1"))

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.totalQuantity(quantity);
order.orderComboLegs(new ArrayList<>());

for(double price : legPrices) {
	OrderComboLeg comboLeg = new OrderComboLeg();
	comboLeg.price(5.0);
	order.orderComboLegs().add(comboLeg);
}

if (nonGuaranteed)
{
	order.smartComboRoutingParams().add(new TagValue("NonGuaranteed", "1"));
}

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.orderComboLegs.reset(new Order::OrderComboLegList());
for(unsigned int i = 0; i < legprices.size(); i++){
	OrderComboLegSPtr comboLeg(new OrderComboLeg());
	comboLeg->price = legprices[i];
	order.orderComboLegs->push_back(comboLeg);
}
if(nonGuaranteed){
	TagValueSPtr tag1(new TagValue("NonGuaranteed", "1"));
	order.smartComboRoutingParams.reset(new TagValueList());
	order.smartComboRoutingParams->push_back(tag1);
}

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.OrderComboLegs = new List<OrderComboLeg>();
foreach(double price in legPrices)
{
	OrderComboLeg comboLeg = new OrderComboLeg();
	comboLeg.Price = 5.0;
	order.OrderComboLegs.Add(comboLeg);
}           
if (nonGuaranteed)
{
	order.SmartComboRoutingParams = new List<TagValue>();
	order.SmartComboRoutingParams.Add(new TagValue("NonGuaranteed", "1"));
}

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.OrderComboLegs = New List(Of OrderComboLeg)
For Each price As Double In legPrices
	Dim ComboLeg As OrderComboLeg = New OrderComboLeg
	ComboLeg.Price = 5.0
	order.OrderComboLegs.Add(ComboLeg)
Next price
If (nonGuaranteed) Then
	order.SmartComboRoutingParams = New List(Of TagValue)
	order.SmartComboRoutingParams.Add(New TagValue("NonGuaranteed", "1"))
End If

 

Combo Market

Create combination orders that include options, stock and futures legs (stock legs can be included if the order is routed through SmartRouting). Although a combination/spread order is constructed of separate legs, it is executed as a single transaction if it is routed directly to an exchange. For combination orders that are SmartRouted, each leg may be executed separately to ensure best execution.

Products: OPT, STK, FUT

order = Order()
order.action = action
order.orderType = "MKT"
order.totalQuantity = quantity
if nonGuaranteed:
	order.smartComboRoutingParams = []
	order.smartComboRoutingParams.append(TagValue("NonGuaranteed", "1"))

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conidex": "{spread_conid};;;{leg_conid1}/{ratio},{leg_conid2}/{ratio}",
      "orderType": "orderType",
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

See the Client Portal Combo / Spread Orders section

Order order = new Order();
order.action(action);
order.orderType("MKT");
order.totalQuantity(quantity);
if (nonGuaranteed)
{
	order.smartComboRoutingParams().add(new TagValue("NonGuaranteed", "1"));
}

 

Order order;
order.action = action;
order.orderType = "MKT";
order.totalQuantity = quantity;
if(nonGuaranteed){
	TagValueSPtr tag1(new TagValue("NonGuaranteed", "1"));
	order.smartComboRoutingParams.reset(new TagValueList());
	order.smartComboRoutingParams->push_back(tag1);
}

 

Order order = new Order();
order.Action = action;
order.OrderType = "MKT";
order.TotalQuantity = quantity;
if (nonGuaranteed)
{
	order.SmartComboRoutingParams = new List<TagValue>();
	order.SmartComboRoutingParams.Add(new TagValue("NonGuaranteed", "1"));
}

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MKT"
order.TotalQuantity = quantity
If (nonGuaranteed) Then
	order.SmartComboRoutingParams = New List(Of TagValue)
	order.SmartComboRoutingParams.Add(New TagValue("NonGuaranteed", "1"))
End If

Discretionary

An Discretionary order is a limit order submitted with a hidden, specified ‘discretionary’ amount off the limit price which may be used to increase the price range over which the limit order is eligible to execute. The market sees only the limit price.

Products: STK

More on Discretionary Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = price
order.discretionaryAmt = discretionaryAmount

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.totalQuantity(quantity);
order.lmtPrice(price);
order.discretionaryAmt(discretionaryAmt);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.lmtPrice = price;
order.discretionaryAmt = discretionaryAmount;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.LmtPrice = price;
order.DiscretionaryAmt = discretionaryAmount;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.LmtPrice = price
order.DiscretionaryAmt = discretionaryAmount

 

Forex Cash Quantity Order

Forex orders can be placed in denomination of second currency in pair using cashQty field.

Products: CASH

More on Forex Cash Quantity Orders

order = Order()
order.action = action
order.orderType = "LMT"
order.lmtPrice = limitPrice
order.cashQty = cashQty

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "orderType",
      "price": price,
      "side": "side",
      "tif": "tif",
      "fxQty": fxQty,
      "isCcyConv": true
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.lmtPrice(limitPrice);
order.cashQty(cashQty);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.lmtPrice = limitPrice;
order.cashQty = cashQty;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.LmtPrice = limitPrice;
order.CashQty = cashQty;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.LmtPrice = limitPrice
order.CashQty = cashQty

 

Limit Orders

Limit Order

A Limit order is an order to buy or sell at a specified price or better. The Limit order ensures that if the order fills, it will not fill at a price less favorable than your limit price, but it does not guarantee a fill.

Products: BOND, CASH, CFD, CMDTY, FUT, FOP, OPT, STK, WAR

More on Limit Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = limitPrice

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "LMT",
      "price": price,
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.totalQuantity(quantity);
order.lmtPrice(limitPrice);
order.tif(TimeInForce.DAY);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.lmtPrice = limitPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.LmtPrice = limitPrice;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.LmtPrice = limitPrice

 

Limit If Touched

A Limit if Touched is an order to buy (or sell) a contract at a specified price or better, below (or above) the market. This order is held in the system until the trigger price is touched. An LIT order is similar to a stop limit order, except that an LIT sell order is placed above the current market price, and a stop limit sell order is placed below.

Products: BOND, CASH, CFD, CMDTY, FUT, FOP, OPT, STK, WAR

More on Limit If Touched Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "LIT"
order.totalQuantity = quantity
order.lmtPrice = limitPrice
order.auxPrice = triggerPrice

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "LIT",
      "price": price,
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("LIT");
order.totalQuantity(quantity);
order.lmtPrice(limitPrice);
order.auxPrice(triggerPrice);

 

Order order;
order.action = action;
order.orderType = "LIT";
order.totalQuantity = quantity;
order.lmtPrice = limitPrice;
order.auxPrice = triggerPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LIT";
order.TotalQuantity = quantity;
order.LmtPrice = limitPrice;
order.AuxPrice = triggerPrice;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LIT"
order.TotalQuantity = quantity
order.LmtPrice = limitPrice
order.AuxPrice = triggerPrice

 

Limit On Close

A Limit-on-close (LOC) order will be submitted at the close and will execute if the closing price is at or better than the submitted limit price.

Products: CFD, FUT, STK, WAR

More on Limit On Close Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "LOC"
order.totalQuantity = quantity
order.lmtPrice = limitPrice

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "LOC",
      "price": price,
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

 
 

Order order = new Order();
order.action(action);
order.orderType("LOC");
order.totalQuantity(quantity);
order.lmtPrice(limitPrice);

 

Order order;
order.action = action;
order.orderType = "LOC";
order.totalQuantity = quantity;
order.lmtPrice = limitPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LOC";
order.TotalQuantity = quantity;
order.LmtPrice = limitPrice;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LOC"
order.TotalQuantity = quantity
order.LmtPrice = limitPrice

 

Limit On Open

A Limit-on-Open (LOO) order combines a limit order with the OPG time in force to create an order that is submitted at the market’s open, and that will only execute at the specified limit price or better. Orders are filled in accordance with specific exchange rules.

Products: CFD, STK, OPT, WAR

More on Limit on Open Orders

More on Supported exchanges

order = Order()
order.action = action
order.tif = "OPG"
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = limitPrice

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "LMT",
      "price": price,
      "side": "side",
      "tif": "OPG",
      "quantity": quantity
    }
  ]
}

 
 

Order order = new Order();
order.action(action);
order.tif("OPG");
order.orderType("LOC");
order.totalQuantity(quantity);
order.lmtPrice(limitPrice);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.tif = "OPG";
order.totalQuantity = quantity;
order.lmtPrice = limitPrice;

 

Order order = new Order();
order.Action = action;
order.Tif = "OPG";
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.LmtPrice = limitPrice;

 

Dim order As Order = New Order
order.Action = action
order.Tif = "OPG"
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.LmtPrice = limitPrice

 

Limit Order With Manual Order Time

The Limit Order With Manual Order Time is a Limit Order with ManualOrderTime property.

Placing a Limit Order With Manual Order Time
The Manual Order Time field is required for, and becomes editable for, “manual” orders, which are orders that originate from a client (whether by phone, email, chat, verbally from the floor, from another desk, etc.) and are then entered into the system.
The Manual Order Time field is not used for client orders received electronically, nor for orders that originate from the account manager (with discretion) in the client’s accounts, or when an order is allocated to ALL accounts or among multiple accounts using an account group or model portfolio.

Canceling a Limit Order With Manual Order Time
The Manual Order Cancel Time field is required for, and becomes editable for, “manual” order cancelations, which are order cancelations that originate from a client (whether by phone, email, chat, verbally from the floor, from another desk, etc.) and are then entered into the system.
The Manual Order Cancel Time field is not used for client orders cancelations received electronically, nor for orders that originate from the account manager (with discretion) in the client’s accounts, or when an order is allocated to ALL accounts or among multiple accounts using an account group or model portfolio.

More on Limit Orders

order = OrderSamples.LimitOrder(action, quantity, limitPrice)
order.manualOrderTime = manualOrderTime

self.placeOrder(self.nextOrderId(), ContractSamples.USStockAtSmart(), OrderSamples.LimitOrderWithManualOrderTime("BUY", Decimal("100"), 111.11, "20220314-13:00:00"))

self.cancelOrder(self.simplePlaceOid, "20220303-13:00:00")

 

Not available for use in the Client Portal API.

Order order = OrderSamples.LimitOrder(action, quantity, limitPrice);
order.manualOrderTime(manualOrderTime);

client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), OrderSamples.LimitOrderWithManualOrderTime("BUY", Decimal.get(100), 111.11, "20220314-13:00:00"));
 
cancelID = nextOrderId - 1;
client.cancelOrder(cancelID, "20220314-19:00:00");

 

Order order = OrderSamples::LimitOrder(action, quantity, limitPrice);
order.manualOrderTime = manualOrderTime;

m_pClient->placeOrder(m_orderId++, ContractSamples::USStockAtSmart(), OrderSamples::LimitOrderWithManualOrderTime("BUY", stringToDecimal("100"), 111.11, "20220314-13:00:00"));

m_pClient->cancelOrder(m_orderId - 1, "20220314-19:00:00");

 

Order order = OrderSamples.LimitOrder(action, quantity, limitPrice);
order.ManualOrderTime = manualOrderTime;

client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), OrderSamples.LimitOrderWithManualOrderTime("BUY", Util.StringToDecimal("100"), 111.11, "20220314-13:00:00"));

client.cancelOrder(nextOrderId - 1, "20220314-19:00:00");

 

Dim order As Order = OrderSamples.LimitOrder(action, quantity, limitPrice)
order.ManualOrderTime = manualOrderTime

client.placeOrder(increment(nextOrderId), ContractSamples.USStockAtSmart(), OrderSamples.LimitOrderWithManualOrderTime("BUY", Util.StringToDecimal("100"), 111.11, "20220314-13:00:00"))

client.cancelOrder(nextOrderId - 1, "20220314-19:00:00")

Market Orders

Market Order

A Market order is an order to buy or sell at the market bid or offer price. A market order may increase the likelihood of a fill and the speed of execution, but unlike the Limit order a Market order provides no price protection and may fill at a price far lower/higher than the current displayed bid/ask.

Products: BOND, CFD, EFP, CASH, FUND, FUT, FOP, OPT, STK, WAR

More on Market Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "MKT"
order.totalQuantity = quantity

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "MKT",
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("MKT");
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "MKT";
order.totalQuantity = quantity;

 

 

Order order = new Order();
order.Action = action;
order.OrderType = "MKT";
order.TotalQuantity = quantity;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MKT"
order.TotalQuantity = quantity

 

Market If Touched

A Market If Touched (MIT) is an order to buy (or sell) a contract below (or above) the market. Its purpose is to take advantage of sudden or unexpected changes in share or other prices and provides investors with a trigger price to set an order in motion. Investors may be waiting for excessive strength (or weakness) to cease, which might be represented by a specific price point. MIT orders can be used to determine whether or not to enter the market once a specific price level has been achieved. This order is held in the system until the trigger price is touched, and is then submitted as a market order. An MIT order is similar to a stop order, except that an MIT sell order is placed above the current market price, and a stop sell order is placed below

Products: BOND, CFD, CASH, FUT, FOP, OPT, STK, WAR

More on Market If Touched Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "MIT"
order.totalQuantity = quantity
order.auxPrice = price

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "MIT",
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("MIT");
order.totalQuantity(quantity);
order.auxPrice(price);

 

Order order;
order.action = action;
order.orderType = "MIT";
order.totalQuantity = quantity;
order.auxPrice = price;

 

Order order = new Order();
order.Action = action;
order.OrderType = "MIT";
order.TotalQuantity = quantity;
order.AuxPrice = price;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MIT"
order.TotalQuantity = quantity
order.AuxPrice = price

 

Market On Close

A Market On Close (MOC) order is a market order that is submitted to execute as close to the closing price as possible.

Products: CFD, FUT, STK, WAR

More on Market On Close Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "MOC"
order.totalQuantity = quantity

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "MOC",
      "side": "side",
      "tif": "DAY",
      "quantity": quantity
    }
  ]
}

 

order = Order()
order.action = action
order.orderType = "MOC"
order.totalQuantity = quantity

 

Order order;
order.action = action;
order.orderType = "MOC";
order.totalQuantity = quantity;

 

Order order = new Order();
order.Action = action;
order.OrderType = "MOC";
order.TotalQuantity = quantity;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MOC"
order.TotalQuantity = quantity

 

Market On Open

A Market On Open (MOO) combines a market order with the OPG time in force to create an order that is automatically submitted at the market’s open and fills at the market price.

Products: CFD, FUT, STK, WAR

More on Market On Open Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "MKT"
order.totalQuantity = quantity
order.tif = "OPG"

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "MKT",
      "side": "side",
      "tif": "OPG",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("MKT");
order.totalQuantity(quantity);
order.tif("OPG");

 

Order order;
order.action = action;
order.orderType = "MKT";
order.totalQuantity = quantity;
order.tif = "OPG";

 

Order order = new Order();
order.Action = action;
order.OrderType = "MKT";
order.TotalQuantity = quantity;
order.Tif = "OPG";

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MKT"
order.TotalQuantity = quantity
order.Tif = "OPG"

 

Market to Limit

A Market-to-Limit (MTL) order is submitted as a market order to execute at the current best market price. If the order is only partially filled, the remainder of the order is canceled and re-submitted as a limit order with the limit price equal to the price at which the filled portion of the order executed.

Products: CFD, FUT, FOP, OPT, STK, WAR

More on Market to Limit Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "MTL"
order.totalQuantity = quantity

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("MTL");
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "MTL";
order.totalQuantity = quantity;

 

Order order = new Order();
order.Action = action;
order.OrderType = "MTL";
order.TotalQuantity = quantity;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MTL"
order.TotalQuantity = quantity

 

Market with Protection

This order type is useful for futures traders using Globex. A Market with Protection order is a market order that will be cancelled and resubmitted as a limit order if the entire order does not immediately execute at the market price. The limit price is set by Globex to be close to the current market price, slightly higher for a sell order and lower for a buy order.

Products: FUT, FOP

More on Market with Protection Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "MKT PRT"
order.totalQuantity = quantity

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("MKT PRT");
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "MKT PRT";
order.totalQuantity = quantity;

 

Order order = new Order();
order.Action = action;
order.OrderType = "MKT PRT";
order.TotalQuantity = quantity;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MKT PRT"
order.TotalQuantity = quantity

 

Passive Relative

Passive Relative orders provide a means for traders to seek a less aggressive price than the National Best Bid and Offer (NBBO) while keeping the order pegged to the best bid (for a buy) or ask (for a sell). The order price is automatically adjusted as the markets move to keep the order less aggressive. For a buy order, your order price is pegged to the NBB by a less aggressive offset, and if the NBB moves up, your bid will also move up. If the NBB moves down, there will be no adjustment because your bid will become aggressive and execute. For a sell order, your price is pegged to the NBO by a less aggressive offset, and if the NBO moves down, your offer will also move down. If the NBO moves up, there will be no adjustment because your offer will become aggressive and execute. In addition to the offset, you can define an absolute cap, which works like a limit price, and will prevent your order from being executed above or below a specified level. The Passive Relative order is similar to the Relative/Pegged-to-Primary order, except that the Passive relative subtracts the offset from the bid and the Relative adds the offset to the bid.

Products: STK, WAR

More on Passive Relative Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "PASSV REL"
order.totalQuantity = quantity
order.auxPrice = offset

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("PASSV REL");
order.totalQuantity(quantity);
order.auxPrice(offset);

 

Order order;
order.action = action;
order.orderType = "PASSV REL";
order.totalQuantity = quantity;
order.auxPrice = offset;

 

Order order = new Order();
order.Action = action;
order.OrderType = "PASSV REL";
order.TotalQuantity = quantity;
order.AuxPrice = offset;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "PASSV REL"
order.TotalQuantity = quantity
order.AuxPrice = offset

 

Peg Orders

Pegged to Benchmark

The Pegged to Benchmark order is similar to the Pegged to Stock order for options, except that the Pegged to Benchmark allows you to specify any asset type as the reference (benchmark) contract for a stock or option order. Both the primary and reference contracts must use the same currency.

Products: STK, OPT

More on Pegged to Benchmark Orders

More on Supported exchanges

order = Order()
order.orderType = "PEG BENCH"
#BUY or SELL
order.action = action
order.totalQuantity = quantity
#Beginning with price...
order.startingPrice = startingPrice
#increase/decrease price..
order.isPeggedChangeAmountDecrease = peggedChangeAmountDecrease
#by... (and likewise for price moving in opposite direction)
order.peggedChangeAmount = peggedChangeAmount
#whenever there is a price change of...
order.referenceChangeAmount = referenceChangeAmount
#in the reference contract...
order.referenceContractId = referenceConId
#being traded at...
order.referenceExchange = referenceExchange
#starting reference price is...
order.stockRefPrice = stockReferencePrice
#Keep order active as long as reference contract trades between...
order.stockRangeLower = referenceContractLowerRange
#and...
order.stockRangeUpper = referenceContractUpperRange

 

Not available for use in the Client Portal API.

Order order = new Order();
order.orderType("PEG BENCH");
//BUY or SELL
order.action(action);
order.totalQuantity(quantity);
//Beginning with price...
order.startingPrice(startingPrice);
//increase/decrease price...
order.isPeggedChangeAmountDecrease(peggedChangeAmountDecrease);
//by... (and likewise for price moving in opposite direction)
order.peggedChangeAmount(peggedChangeAmount);
//whenever there is a price change of...
order.referenceChangeAmount(referenceChangeAmount);
//in the reference contract...
order.referenceContractId(referenceConId);
//being traded at...
order.referenceExchangeId(referenceExchange);
//starting reference price is...
order.stockRefPrice(stockReferencePrice);
//Keep order active as long as reference contract trades between...
order.stockRangeLower(referenceContractLowerRange);
//and...
order.stockRangeUpper(referenceContractUpperRange);

 

Order order = new Order();
order.orderType("PEG BENCH");
//BUY or SELL
order.action(action);
order.totalQuantity(quantity);
//Beginning with price...
order.startingPrice(startingPrice);
//increase/decrease price...
order.isPeggedChangeAmountDecrease(peggedChangeAmountDecrease);
//by... (and likewise for price moving in opposite direction)
order.peggedChangeAmount(peggedChangeAmount);
//whenever there is a price change of...
order.referenceChangeAmount(referenceChangeAmount);
//in the reference contract...
order.referenceContractId(referenceConId);
//being traded at...
order.referenceExchangeId(referenceExchange);
//starting reference price is...
order.stockRefPrice(stockReferencePrice);
//Keep order active as long as reference contract trades between...
order.stockRangeLower(referenceContractLowerRange);
//and...
order.stockRangeUpper(referenceContractUpperRange);

 

Order order = new Order();
order.OrderType = "PEG BENCH";
//BUY or SELL
order.Action = action;
order.TotalQuantity = quantity;
//Beginning with price...
order.StartingPrice = startingPrice;
//increase/decrease price..
order.IsPeggedChangeAmountDecrease = peggedChangeAmountDecrease;
//by... (and likewise for price moving in opposite direction)
order.PeggedChangeAmount = peggedChangeAmount;
//whenever there is a price change of...
order.ReferenceChangeAmount = referenceChangeAmount;
//in the reference contract...
order.ReferenceContractId = referenceConId;
//being traded at...
order.ReferenceExchange = referenceExchange;
//starting reference price is...
order.StockRefPrice = stockReferencePrice;
//Keep order active as long as reference contract trades between...
order.StockRangeLower = referenceContractLowerRange;
//and...
order.StockRangeUpper = referenceContractUpperRange;

 

Dim order As Order = New Order
order.OrderType = "PEG BENCH"
'BUY Or SELL
order.Action = action
order.TotalQuantity = quantity
'Beginning with price...
order.StartingPrice = startingPrice
'increase/decrease price..
order.IsPeggedChangeAmountDecrease = peggedChangeAmountDecrease
'by... (And likewise for price moving in opposite direction)
order.PeggedChangeAmount = peggedChangeAmount
'whenever there Is a price change of...
order.ReferenceChangeAmount = referenceChangeAmount
'in the reference contract...
order.ReferenceContractId = referenceConId
'being traded at...
order.ReferenceExchange = referenceExchange
'starting reference price Is...
order.StockRefPrice = stockReferencePrice
'Keep order active as long as reference contract trades between...
order.StockRangeLower = referenceContractLowerRange
'And...
order.StockRangeUpper = referenceContractUpperRange

 

Pegged To Market

A pegged-to-market order is designed to maintain a purchase price relative to the national best offer (NBO) or a sale price relative to the national best bid (NBB). Depending on the width of the quote, this order may be passive or aggressive. The trader creates the order by entering a limit price which defines the worst limit price that they are willing to accept. Next, the trader enters an offset amount which computes the active limit price as follows: Sell order price = Bid price + offset amount Buy order price = Ask price – offset amount

Products: STK

More on Pegged To Market Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "PEG MKT"
order.totalQuantity = quantity
order.auxPrice = marketOffset#Offset price

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("PEG MKT");
order.totalQuantity(Decimal.ONE_HUNDRED);
order.auxPrice(marketOffset);//Offset price

 

Order order;
order.action = action;
order.orderType = "PEG MKT";
order.totalQuantity = quantity;
order.auxPrice = marketOffset;

 

Order order = new Order();
order.Action = action;
order.OrderType = "PEG MKT";
order.TotalQuantity = 100;
order.AuxPrice = marketOffset;//Offset price

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "PEG MKT"
order.TotalQuantity = 100
order.AuxPrice = marketOffset ' Offset price

 

Pegged To Primary / Relative

Relative (a.k.a. Pegged-to-Primary) orders provide a means for traders to seek a more aggressive price than the National Best Bid and Offer (NBBO). By acting as liquidity providers, and placing more aggressive bids and offers than the current best bids and offers, traders increase their odds of filling their order. Quotes are automatically adjusted as the markets move, to remain aggressive. Stocks, Options and Futures – not available on paper trading.

Products: CFD, STK, OPT, FUT

More on Pegged To Primary Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "REL"
order.totalQuantity = quantity
order.lmtPrice = priceCap
order.auxPrice = offsetAmount

 

curl {baseURL}/iserver/account/{accountId}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "REL",
      "price": Limit_Price,
      "auxPrice": Offset_Price,
      "side": "side",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("REL");
order.totalQuantity(quantity);
order.lmtPrice(priceCap);
order.auxPrice(offsetAmount);

 

Order order;
order.action = action;
order.orderType = "REL";
order.totalQuantity = quantity;
order.lmtPrice = priceCap;
order.auxPrice = offsetAmount;

 

Order order = new Order();
order.Action = action;
order.OrderType = "REL";
order.TotalQuantity = quantity;
order.LmtPrice = priceCap;
order.AuxPrice = offsetAmount;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "REL"
order.TotalQuantity = quantity
order.LmtPrice = priceCap
order.AuxPrice = offsetAmount

 

Pegged To Stock

A Pegged to Stock order continually adjusts the option order price by the product of a signed user-define delta and the change of the option’s underlying stock price. The delta is entered as an absolute and assumed to be positive for calls and negative for puts. A buy or sell call order price is determined by adding the delta times a change in an underlying stock price to a specified starting price for the call. To determine the change in price, the stock reference price is subtracted from the current NBBO midpoint. The Stock Reference Price can be defined by the user, or defaults to the NBBO midpoint at the time of the order if no reference price is entered. You may also enter a high/low stock price range which cancels the order when reached. The delta times the change in stock price will be rounded to the nearest penny in favor of the order.

Products: OPT

More on Pegged To Stock Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "PEG STK"
order.totalQuantity = quantity
order.delta = delta
order.stockRefPrice = stockReferencePrice
order.startingPrice = startingPrice

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("PEG STK");
order.totalQuantity(quantity);
order.delta(delta);
order.stockRefPrice(stockReferencePrice);
order.startingPrice(startingPrice);

 

Order order;
order.action = action;
order.orderType = "PEG STK";
order.totalQuantity = quantity;
order.delta = delta;
order.stockRefPrice = stockReferencePrice;
order.startingPrice = startingPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "PEG STK";
order.TotalQuantity = quantity;
order.Delta = delta;
order.StockRefPrice = stockReferencePrice;
order.StartingPrice = startingPrice;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "PEG STK"
order.TotalQuantity = quantity
order.Delta = delta
order.StockRefPrice = stockReferencePrice
order.StartingPrice = startingPrice

 

Relative Limit Combo

Create combination orders that include options, stock and futures legs (stock legs can be included if the order is routed through SmartRouting). Although a combination/spread order is constructed of separate legs, it is executed as a single transaction if it is routed directly to an exchange. For combination orders that are SmartRouted, each leg may be executed separately to ensure best execution.

Products: OPT, STK, FUT

order = Order()
order.action = action
order.totalQuantity = quantity
order.orderType = "REL + LMT"
order.lmtPrice = limitPrice

if nonGuaranteed:
	order.smartComboRoutingParams = []
	order.smartComboRoutingParams.append(TagValue("NonGuaranteed", "1"))

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("REL + LMT");
order.totalQuantity(quantity);
order.lmtPrice(limitPrice);
if (nonGuaranteed)
{
	order.smartComboRoutingParams().add(new TagValue("NonGuaranteed", "1"));
}

 

Order order;
order.action = action;
order.totalQuantity = quantity;
order.orderType = "Rel + LMT";
order.lmtPrice = limitPrice;
if(nonGuaranteed){
	TagValueSPtr tag1(new TagValue("NonGuaranteed", "1"));
	order.smartComboRoutingParams.reset(new TagValueList());
	order.smartComboRoutingParams->push_back(tag1);
}

 

Order order = new Order();
order.Action = action;
order.TotalQuantity = quantity;
order.OrderType = "REL + LMT";
order.LmtPrice = limitPrice;
if (nonGuaranteed)
{
	order.SmartComboRoutingParams = new List<TagValue>();
	order.SmartComboRoutingParams.Add(new TagValue("NonGuaranteed", "1"));
}

 

Dim order As Order = New Order
order.Action = action
order.TotalQuantity = quantity
order.OrderType = "REL + LMT"
order.LmtPrice = limitPrice
If (nonGuaranteed) Then
	order.SmartComboRoutingParams = New List(Of TagValue)
	order.SmartComboRoutingParams.Add(New TagValue("NonGuaranteed", "1"))
End If

 

Relative Market Combo

Create combination orders that include options, stock and futures legs (stock legs can be included if the order is routed through SmartRouting). Although a combination/spread order is constructed of separate legs, it is executed as a single transaction if it is routed directly to an exchange. For combination orders that are SmartRouted, each leg may be executed separately to ensure best execution.

Products: OPT, STK, FUT

order = Order()
order.action = action
order.totalQuantity = quantity
order.orderType = "REL + MKT"

if nonGuaranteed:
	order.smartComboRoutingParams = []
	order.smartComboRoutingParams.append(TagValue("NonGuaranteed", "1"))

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("REL + MKT");
order.totalQuantity(quantity);
if (nonGuaranteed)
{
	order.smartComboRoutingParams().add(new TagValue("NonGuaranteed", "1"));
}

 

Order order;
order.action = action;
order.totalQuantity = quantity;
order.orderType = "Rel + MKT";
if(nonGuaranteed){
	TagValueSPtr tag1(new TagValue("NonGuaranteed", "1"));
	order.smartComboRoutingParams.reset(new TagValueList());
	order.smartComboRoutingParams->push_back(tag1);
}

 

Order order = new Order();
order.Action = action;
order.TotalQuantity = quantity;
order.OrderType = "REL + MKT";
if (nonGuaranteed)
{
	order.SmartComboRoutingParams = new List<TagValue>();
	order.SmartComboRoutingParams.Add(new TagValue("NonGuaranteed", "1"));
}

 

Dim order As Order = New Order
order.Action = action
order.TotalQuantity = quantity
order.OrderType = "REL + MKT"
If (nonGuaranteed) Then
	order.SmartComboRoutingParams = New List(Of TagValue)
	order.SmartComboRoutingParams.Add(New TagValue("NonGuaranteed", "1"))
End If

 

Stop

A Stop order is an instruction to submit a buy or sell market order if and when the user-specified stop trigger price is attained or penetrated. A Stop order is not guaranteed a specific execution price and may execute significantly away from its stop price. A Sell Stop order is always placed below the current market price and is typically used to limit a loss or protect a profit on a long stock position. A Buy Stop order is always placed above the current market price. It is typically used to limit a loss or help protect a profit on a short sale.

Products: CFD, BAG, CASH, FUT, FOP, OPT, STK, WAR

More on Stop Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "STP"
order.auxPrice = stopPrice
order.totalQuantity = quantity

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "STP",
      "price": price,
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("STP");
order.auxPrice(stopPrice);
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "STP";
order.totalQuantity = quantity;
order.auxPrice = stopPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "STP";
order.AuxPrice = stopPrice;
order.TotalQuantity = quantity;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "STP"
order.AuxPrice = stopPrice
order.TotalQuantity = quantity

 

Stop Limit

A Stop-Limit order is an instruction to submit a buy or sell limit order when the user-specified stop trigger price is attained or penetrated. The order has two basic components: the stop price and the limit price. When a trade has occurred at or through the stop price, the order becomes executable and enters the market as a limit order, which is an order to buy or sell at a specified price or better.

Products: CFD, CASH, FUT, FOP, OPT, STK, WAR

More on Stop Limit Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "STP LMT"
order.totalQuantity = quantity
order.lmtPrice = limitPrice
order.auxPrice = stopPrice

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "STP LMT",
      "price": price,
      "auxPrice": "auxPrice",
      "side": "side",
      "tif": "tif",
      "quantity": quantity
    }
  ]
}

Price is the Limit price while auxPrice represents the stop price trigger.
 

Order order = new Order();
order.action(action);
order.orderType("STP LMT");
order.lmtPrice(limitPrice);
order.auxPrice(stopPrice);
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "STP LMT";
order.totalQuantity = quantity;
order.lmtPrice = limitPrice;
order.auxPrice = stopPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "STP LMT";
order.TotalQuantity = quantity;
order.LmtPrice = limitPrice;
order.AuxPrice = stopPrice;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "STP LMT"
order.TotalQuantity = quantity
order.LmtPrice = limitPrice
order.AuxPrice = stopPrice

 

Stop with Protection

A Stop with Protection order combines the functionality of a stop limit order with a market with protection order. The order is set to trigger at a specified stop price. When the stop price is penetrated, the order is triggered as a market with protection order, which means that it will fill within a specified protected price range equal to the trigger price +/- the exchange-defined protection point range. Any portion of the order that does not fill within this protected range is submitted as a limit order at the exchange-defined trigger price +/- the protection points.

Products: FUT

More on Stop with Protection Orders

More on Supported exchanges

order = Order()
order.totalQuantity = quantity
order.action = action
order.orderType = "STP PRT"
order.auxPrice = stopPrice

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("STP PRT");
order.auxPrice(stopPrice);
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "STP PRT";
order.totalQuantity = quantity;
order.auxPrice = stopPrice;

 

Order order = new Order();
order.TotalQuantity = quantity;
order.Action = action;
order.OrderType = "STP PRT";
order.AuxPrice = stopPrice;

 

Dim order As Order = New Order
order.TotalQuantity = quantity
order.Action = action
order.OrderType = "STP PRT"
order.AuxPrice = stopPrice

 

Sweep to Fill

Sweep-to-fill orders are useful when a trader values speed of execution over price. A sweep-to-fill order identifies the best price and the exact quantity offered/available at that price, and transmits the corresponding portion of your order for immediate execution. Simultaneously it identifies the next best price and quantity offered/available, and submits the matching quantity of your order for immediate execution.

Products: CFD, STK, WAR (SMART only)

More on Sweep to Fill Orders

order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = price
order.sweepToFill = True

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.totalQuantity(quantity);
order.lmtPrice(price);
order.sweepToFill(true);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.lmtPrice = price;
order.sweepToFill = true;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.LmtPrice = price;
order.SweepToFill = true;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.LmtPrice = price
order.SweepToFill = True

 

Trailing Stop

For a discussion of the handling and behavior of Trailing Stop orders, please see our brokerage-wide documentation on this order type at: Trailing Stop Orders
Supported exchanges for Trailing Stop orders: Supported Exchanges

Order Type Identifier:

“TRAIL”

Parameters:

Trail Offset. Required.
Specifies the distance that your order’s stop price will maintain away from the market. A Trailing Stop order ticket must include exactly one of the following two forms of Trail Offset:

  • Absolute Offset: An explicit numerical value (in the instrument’s currency) which will be added to or subtracted from the market price of the instrument.
  • Relative Offset: A percentage of the market price of the instrument, from which absolute price offsets will be computed (which in turn may vary in size as the market price moves).

Note: The Trail Offset value, whether absolute or relative, must conform to the instrument’s price increment rules.

Stop Price.
This value is not required. If supplied, this is the trigger price beyond which the Trailing Stop order will begin its trailing behavior. If no Stop Price value is supplied, the market price for the instrument at the time of submission will assigned to this value automatically.

TWS API: Trailing Stop

Trail Offset. Required.
One of the following class attributes must be supplied with the order ticket.

  • Absolute Offset: Order.auxPrice
  • Relative Offset: Order.trailingPercent
    Note that the value assigned to trailingPercent will be interpreted as a true percent, e.g., trailingPercent = 0.50 becomes 0.50% = 0.0050.

Stop Price: Order.trailStopPrice

In the example to the right, we have outlined two Trailing Stop orders with explicit Stop Prices via order.trailStopPrice.
In the first order, we supply a relative offset of 2% using order.TrailStopPercent.
In the second order, we supply an absolute offset of 3 units of currency using order.auxPrice.

order = Order()
order.orderType = "TRAIL"
order.trailStopPrice = 100
order.trailingPercent = 2
order = Order()
order.orderType = "TRAIL"
order.trailStopPrice = 100
order.auxPrice = 3

 

Order order = new Order();
order.orderType("TRAIL");
order.trailStopPrice(100);
order.trailingPercent(2);
Order order = new Order();
order.orderType("TRAIL");
order.trailStopPrice(100);
order.auxPrice(3);
Order order;
order.orderType = "TRAIL";
order.trailStopPrice = 100;
order.trailingPercent = 2;
Order order;
order.orderType = "TRAIL";
order.trailStopPrice = 100;
order.auxPrice = 3;
Order order = new Order();
order.OrderType = "TRAIL";
order.TrailStopPrice = 100;
order.TrailingPercent = 2;
Order order = new Order();
order.OrderType = "TRAIL";
order.TrailStopPrice = 100;
order.AuxPrice= 3;
Dim order As Order = New Order
order.OrderType = "TRAIL"
order.TrailStopPrice = 100
order.TrailingPercent = 2
Dim order As Order = New Order
order.OrderType = "TRAIL"
order.TrailStopPrice = 100
order.AuxPrice= 3

CP API: Trailing Stop

Trail Offset. Required.
One of the following approaches to Trail Offset specification must be used with the order ticket.

  • Absolute Offset: "trailingType": "amt", "trailingAmt": {{currency}}
  • Relative Offset: "trailingType": "%", "trailingAmt": {{number 0 to 100}}
    Note that you must pass a literal % character as the value of the trailingType field in order to use a percentage trailingAmt value.

Stop Price: "price"

In the example to the right, we have outlined two Trailing Stop orders with explicit Stop Prices via the price field.
In the first order, we supply a relative offset of 2% using "trailingType": "%" and "trailingAmt": 2.
In the second order, we supply an absolute offset of 3 units of currency using "trailingType": "amt" and "trailingAmt": 3.

{
  "orderType": "TRAIL",
  "price": 100,
  "trailingAmt": 2,
  "trailingType": "%"
}
{
  "orderType": "TRAIL",
  "price": 100,
  "trailingAmt": 3,
  "trailingType": "amt"
}

Trailing Stop Limit

A trailing stop limit order is designed to allow an investor to specify a limit on the maximum possible loss, without setting a limit on the maximum possible gain. A SELL trailing stop limit moves with the market price, and continually recalculates the stop trigger price at a fixed amount below the market price, based on the user-defined “trailing” amount. The limit order price is also continually recalculated based on the limit offset. As the market price rises, both the stop price and the limit price rise by the trail amount and limit offset respectively, but if the stock price falls, the stop price remains unchanged, and when the stop price is hit a limit order is submitted at the last calculated limit price. A “Buy” trailing stop limit order is the mirror image of a sell trailing stop limit, and is generally used in falling markets.

Trailing Stop Limit orders can be sent with the trailing amount specified as an absolute amount, as in the example below, or as a percentage, specified in the trailingPercent field.

Important: the ‘limit offset’ field is set by default in the TWS/IBG settings. This setting either needs to be changed in the Order Presets, the default value accepted, or the limit price offset sent from the API as in the example below. Not both the ‘limit price’ and ‘limit price offset’ fields can be set in TRAIL LIMIT orders.

Products: BOND, CFD, CASH, FUT, FOP, OPT, STK, WAR

More on Trailing Stop Limit Orders

order = Order()
order.action = action
order.orderType = "TRAIL LIMIT"
order.totalQuantity = quantity
order.trailStopPrice = trailStopPrice
order.lmtPriceOffset = lmtPriceOffset
order.auxPrice = trailingAmount

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
  "orders": [
    {
      "conid": conid,
      "orderType": "TRAILLMT",
      "price": price,
      "auxPrice": "auxPrice",
      "side": "side",
      "tif": "tif",
      "trailingAmt": trailingAmt,
      "trailingType": "trailingType",
      "quantity": quantity
    }
  ]
}

 

Order order = new Order();
order.action(action);
order.orderType("TRAIL LIMIT");
order.lmtPriceOffset(lmtPriceOffset);
order.auxPrice(trailingAmount);
order.trailStopPrice(trailStopPrice);
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "TRAIL LIMIT";
order.totalQuantity = quantity;
order.trailStopPrice = trailStopPrice;
order.lmtPriceOffset = lmtPriceOffset;
order.auxPrice = trailingAmount;

 

Order order = new Order();
order.Action = action;
order.OrderType = "TRAIL LIMIT";
order.TotalQuantity = quantity;
order.TrailStopPrice = trailStopPrice;
order.LmtPriceOffset = lmtPriceOffset;
order.AuxPrice = trailingAmount;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "TRAIL LIMIT"
order.TotalQuantity = quantity
order.LmtPriceOffset = lmtPriceOffset
order.TrailStopPrice = trailStopPrice
order.AuxPrice = trailingAmount

 

Volatility

Specific to US options, investors are able to create and enter Volatility-type orders for options and combinations rather than price orders. Option traders may wish to trade and position for movements in the price of the option determined by its implied volatility. Because implied volatility is a key determinant of the premium on an option, traders position in specific contract months in an effort to take advantage of perceived changes in implied volatility arising before, during or after earnings or when company specific or broad market volatility is predicted to change. In order to create a Volatility order, clients must first create a Volatility Trader page from the Trading Tools menu and as they enter option contracts, premiums will display in percentage terms rather than premium. The buy/sell process is the same as for regular orders priced in premium terms except that the client can limit the volatility level they are willing to pay or receive.

Products: FOP, OPT

More on Volatility Type Orders

More on Supported exchanges

order = Order()
order.action = action
order.orderType = "VOL"
order.totalQuantity = quantity
order.volatility = volatilityPercent#Expressed in percentage (40%)
order.volatilityType = volatilityType# 1=daily, 2=annual

 

Not available for use in the Client Portal API.

Order order = new Order();
order.action(action);
order.orderType("VOL");
order.volatility(volatilityPercent);//Expressed in percentage (40%)
order.volatilityType(volatilityType);// 1=daily, 2=annual
order.totalQuantity(quantity);

 

Order order;
order.action = action;
order.orderType = "VOL";
order.totalQuantity = quantity;
order.volatility = volatilityPercent; //Expressed in percentage (40%)
order.volatilityType = volatilityType; // 1=daily, 2=annual

 

Order order = new Order();
order.Action = action;
order.OrderType = "VOL";
order.TotalQuantity = quantity;
order.Volatility = volatilityPercent;//Expressed in percentage (40%)
order.VolatilityType = volatilityType;// 1=daily, 2=annual

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "VOL"
order.TotalQuantity = quantity
order.Volatility = volatilityPercent  'Expressed in percentage (40%)
order.VolatilityType = volatilityType  ' 1=daily, 2=annual

 

Complex Orders

Hedging

Hedging orders are similar to Bracket Orders. With hedging order, a child order is submitted only on execution of the parent. Orders can be hedged by an attached forex trade, Beta hedge, or Pair Trade, just as in TWS.

For an example of a forex hedge, when buying a contract on a currency other than your base, you can attach an FX order to convert base currency to the currency of the contract to cover the cost of the trade thanks to the TWS API’s Attaching Orders mechanism.

More on Hedging Orders in TWS

More on Attaching Orders

Note that in some cases it will be necessary to include a small delay of 50 ms or less after placing the parent order for processing, before placing the child order. Otherwise the error “10006: Missing parent order” will be triggered.

 @staticmethod
def MarketFHedge(parentOrderId:int, action:str):
    #FX Hedge orders can only have a quantity of 0
    order = OrderSamples.MarketOrder(action, 0)
    order.parentId = parentOrderId
    order.hedgeType = "F"
    return order

# Parent order on a contract which currency differs from your base currency
parent = OrderSamples.LimitOrder("BUY", 100, 10)
parent.orderId = self.nextOrderId()
parent.transmit = False

# Hedge on the currency conversion
hedge = OrderSamples.MarketFHedge(parent.orderId, "BUY")

# Place the parent first...
self.placeOrder(parent.orderId, ContractSamples.EuropeanStock(), parent)

# Then the hedge order
self.placeOrder(self.nextOrderId(), ContractSamples.EurGbpFx(), hedge)

 

public static Order MarketFHedge(int parentOrderId, String action) {
    //FX Hedge orders can only have a quantity of 0
    Order order = MarketOrder(action, Decimal.ZERO);
    order.parentId(parentOrderId);
    order.hedgeType("F");
    return order;
}

//Parent order on a contract which currency differs from your base currency
Order parent = OrderSamples.LimitOrder("BUY", Decimal.ONE_HUNDRED, 10);
parent.orderId(nextOrderId++);
parent.transmit(false);
//Hedge on the currency conversion
Order hedge = OrderSamples.MarketFHedge(parent.orderId(), "BUY");
//Place the parent first...
client.placeOrder(parent.orderId(), ContractSamples.EuropeanStock(), parent);
//Then the hedge order
client.placeOrder(nextOrderId++, ContractSamples.EurGbpFx(), hedge);

 

Order OrderSamples::MarketFHedge(int parentOrderId, std::string action){
    //FX Hedge orders can only have a quantity of 0
    Order order = MarketOrder(action, 0);
    order.parentId = parentOrderId;
    order.hedgeType = "F";
    return order;
}

//Parent order on a contract which currency differs from your base currency
Order parent = OrderSamples::LimitOrder("BUY", stringToDecimal("100"), 10);
parent.orderId = m_orderId++;
parent.transmit = false;

//Hedge on the currency conversion
Order hedge = OrderSamples::MarketFHedge(parent.orderId, "BUY");

//Place the parent first...
m_pClient->placeOrder(parent.orderId, ContractSamples::EuropeanStock(), parent);

//Then the hedge order
m_pClient->placeOrder(m_orderId++, ContractSamples::EurGbpFx(), hedge);

 

 public static Order MarketFHedge(int parentOrderId, string action)
{
    //FX Hedge orders can only have a quantity of 0
    Order order = MarketOrder(action, 0);
    order.ParentId = parentOrderId;
    orderHedgeType = "F";
    return order;
 }

 //Parent order on a contract which currency differs from your base currency
Order parent = OrderSamples.LimitOrder("BUY", 100, 10);
parent.OrderId = nextOrderId++;
parent.Transmit = false;

 //Hedge on the currency conversion
Order hedge = OrderSamples.MarketFHedge(parent.OrderId, "BUY");

//Place the parent first...
client.placeOrder(parent.OrderId, ContractSamples.EuropeanStock(), parent);

//Then the hedge order
client.placeOrder(nextOrderId++, ContractSamples.EurGbpFx(), hedge);

 

Public Shared Function MarketFHedge(parentOrderId As Integer, action As String) As Order
    'FX Hedge orders can only have a quantity of 0
    Dim Order As Order = MarketOrder(action, 0)
    Order.ParentId = parentOrderId
    Order.HedgeType = "F"
    Return Order
End Function

'Parent order on a contract which currency differs from your base currency
Dim parent As Order = OrderSamples.LimitOrder("BUY", 100, 10)
parent.OrderId = increment(nextOrderId)
parent.Transmit = False

'Hedge on the currency conversion
Dim hedge As Order = OrderSamples.MarketFHedge(parent.OrderId, "BUY")

'Place the parent first...
client.placeOrder(parent.OrderId, ContractSamples.EuropeanStock(), parent)

'Then the hedge order
client.placeOrder(increment(increment(nextOrderId)), ContractSamples.EurGbpFx(), hedge)

 

Bracket Orders

Bracket Orders are designed to help limit your loss and lock in a profit by “bracketing” an order with two opposite-side orders. A BUY order is bracketed by a high-side sell limit order and a low-side sell stop order. A SELL order is bracketed by a high-side buy stop order and a low side buy limit order. Note how bracket orders make use of the TWS API’s Attaching Orders mechanism.

One key thing to keep in mind is to handle the order transmission accurately. Since a Bracket consists of three orders, there is always a risk that at least one of the orders gets filled before the entire bracket is sent. To avoid it, make use of the IBApi.Order.Transmit flag. When this flag is set to ‘false’, the TWS will receive the order but it will not send (transmit) it to the servers. In the example below, the first (parent) and second (takeProfit) orders will be send to the TWS but not transmitted to the servers. When the last child order (stopLoss) is sent however and given that its IBApi.Order.Transmit flag is set to true, the TWS will interpret this as a signal to transmit not only its parent order but also the rest of siblings, removing the risks of an accidental execution.

More on Bracket Orders

More on Attaching Orders

More on the  IBApi.Order.Transmit flag

@staticmethod
def BracketOrder(parentOrderId:int, action:str, quantity:Decimal, 
                 limitPrice:float, takeProfitLimitPrice:float, 
                 stopLossPrice:float):
     
	#This will be our main or "parent" order
	parent = Order()
	parent.orderId = parentOrderId
	parent.action = action
	parent.orderType = "LMT"
	parent.totalQuantity = quantity
	parent.lmtPrice = limitPrice
	#The parent and children orders will need this attribute set to False to prevent accidental executions.
	#The LAST CHILD will have it set to True, 
	parent.transmit = False
 
	takeProfit = Order()
	takeProfit.orderId = parent.orderId + 1
	takeProfit.action = "SELL" if action == "BUY" else "BUY"
	takeProfit.orderType = "LMT"
	takeProfit.totalQuantity = quantity
	takeProfit.lmtPrice = takeProfitLimitPrice
	takeProfit.parentId = parentOrderId
	takeProfit.transmit = False
 
	stopLoss = Order()
	stopLoss.orderId = parent.orderId + 2
	stopLoss.action = "SELL" if action == "BUY" else "BUY"
	stopLoss.orderType = "STP"
	#Stop trigger price
	stopLoss.auxPrice = stopLossPrice
	stopLoss.totalQuantity = quantity
	stopLoss.parentId = parentOrderId
	#In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to True 
	#to activate all its predecessors
	stopLoss.transmit = True
 
	bracketOrder = [parent, takeProfit, stopLoss]
	return bracketOrder

bracket = OrderSamples.BracketOrder(self.nextOrderId(), "BUY", 100, 30, 40, 20)
for o in bracket:
	self.placeOrder(o.orderId, ContractSamples.EuropeanStock(), o)
	self.nextOrderId()  # need to advance this we'll skip one extra oid, it's fine

 

 public static List<Order> BracketOrder(int parentOrderId, String action, Decimal quantity, double limitPrice, double takeProfitLimitPrice, double stopLossPrice) {
	//This will be our main or "parent" order
	Order parent = new Order();
	parent.orderId(parentOrderId);
	parent.action(action);
	parent.orderType("LMT");
	parent.totalQuantity(quantity);
	parent.lmtPrice(limitPrice);
	//The parent and children orders will need this attribute set to false to prevent accidental executions.
	//The LAST CHILD will have it set to true.
	parent.transmit(false);
        
	Order takeProfit = new Order();
	takeProfit.orderId(parent.orderId() + 1);
	takeProfit.action(action.equals("BUY") ? "SELL" : "BUY");
	takeProfit.orderType("LMT");
	takeProfit.totalQuantity(quantity);
	takeProfit.lmtPrice(takeProfitLimitPrice);
	takeProfit.parentId(parentOrderId);
	takeProfit.transmit(false);
        
	Order stopLoss = new Order();
	stopLoss.orderId(parent.orderId() + 2);
	stopLoss.action(action.equals("BUY") ? "SELL" : "BUY");
	stopLoss.orderType("STP");
	//Stop trigger price
	stopLoss.auxPrice(stopLossPrice);
	stopLoss.totalQuantity(quantity);
	stopLoss.parentId(parentOrderId);
	//In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to true 
	//to activate all its predecessors
	stopLoss.transmit(true);
        
	List<Order> bracketOrder = new ArrayList<>();
	bracketOrder.add(parent);
	bracketOrder.add(takeProfit);
	bracketOrder.add(stopLoss);
        
	return bracketOrder;
}

List<Order> bracket = OrderSamples.BracketOrder(nextOrderId++, "BUY", Decimal.ONE_HUNDRED, 30, 40, 20);
for(Order o : bracket) {
	client.placeOrder(o.orderId(), ContractSamples.EuropeanStock(), o);
}

 

void OrderSamples::BracketOrder(int parentOrderId, Order& parent, Order& takeProfit, Order& stopLoss, std::string action, Decimal quantity, double limitPrice, double takeProfitLimitPrice, double stopLossPrice){
	//This will be our main or "parent" order
	parent.orderId = parentOrderId;
	parent.action = action;
	parent.orderType = "LMT";
	parent.totalQuantity = quantity;
	parent.lmtPrice = limitPrice;
	//The parent and children orders will need this attribute set to false to prevent accidental executions.
	//The LAST CHILD will have it set to true, 
	parent.transmit = false;
	takeProfit.orderId = parent.orderId + 1;
	takeProfit.action = (action == "BUY") ? "SELL" : "BUY";
	takeProfit.orderType = "LMT";
	takeProfit.totalQuantity = quantity;
	takeProfit.lmtPrice = takeProfitLimitPrice;
	takeProfit.parentId = parentOrderId;
	takeProfit.transmit = false;
	stopLoss.orderId = parent.orderId + 2;
	stopLoss.action = (action == "BUY") ? "SELL" : "BUY";
	stopLoss.orderType = "STP";
	//Stop trigger price
	stopLoss.auxPrice = stopLossPrice;
	stopLoss.totalQuantity = quantity;
	stopLoss.parentId = parentOrderId;
	//In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to true 
	//to activate all its predecessors
	stopLoss.transmit = true;
}

OrderSamples::BracketOrder(m_orderId++, parent, takeProfit, stopLoss, "BUY", stringToDecimal("100"), 30, 40, 20);
m_pClient->placeOrder(parent.orderId, ContractSamples::EuropeanStock(), parent);
m_pClient->placeOrder(takeProfit.orderId, ContractSamples::EuropeanStock(), takeProfit);
m_pClient->placeOrder(stopLoss.orderId, ContractSamples::EuropeanStock(), stopLoss);

 

public static List<Order> BracketOrder(int parentOrderId, string action, decimal quantity, double limitPrice, 
            double takeProfitLimitPrice, double stopLossPrice)
{
	//This will be our main or "parent" order
	Order parent = new Order();
	parent.OrderId = parentOrderId;
	parent.Action = action;
	parent.OrderType = "LMT";
	parent.TotalQuantity = quantity;
	parent.LmtPrice = limitPrice;
	//The parent and children orders will need this attribute set to false to prevent accidental executions.
	//The LAST CHILD will have it set to true, 
	parent.Transmit = false;
	Order takeProfit = new Order();
	takeProfit.OrderId = parent.OrderId + 1;
	takeProfit.Action = action.Equals("BUY") ? "SELL" : "BUY";
	takeProfit.OrderType = "LMT";
	takeProfit.TotalQuantity = quantity;
	takeProfit.LmtPrice = takeProfitLimitPrice;
	takeProfit.ParentId = parentOrderId;
	takeProfit.Transmit = false;
	Order stopLoss = new Order();
	stopLoss.OrderId = parent.OrderId + 2;
	stopLoss.Action = action.Equals("BUY") ? "SELL" : "BUY";
	stopLoss.OrderType = "STP";
	//Stop trigger price
	stopLoss.AuxPrice = stopLossPrice;
	stopLoss.TotalQuantity = quantity;
	stopLoss.ParentId = parentOrderId;
	//In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to true 
	//to activate all its predecessors
	stopLoss.Transmit = true;
	List<Order> bracketOrder = new List<Order>();
	bracketOrder.Add(parent);
	bracketOrder.Add(takeProfit);
	bracketOrder.Add(stopLoss);
	return bracketOrder;
}

List<Order> bracket = OrderSamples.BracketOrder(nextOrderId++, "BUY", 100, 30, 40, 20);
foreach (Order o in bracket)
	client.placeOrder(o.OrderId, ContractSamples.EuropeanStock(), o);

 

'This will be our main Or "parent" order
Dim parent As Order = New Order
parent.OrderId = parentOrderId
parent.Action = action
parent.OrderType = "LMT"
parent.TotalQuantity = quantity
parent.LmtPrice = limitPrice
'The parent And children orders will need this attribute set to false to prevent accidental executions.
'The LAST CHILD will have it set to true, 
parent.Transmit = False
Dim takeProfit As Order = New Order
'
takeProfit.OrderId = parent.OrderId + 1
If action.Equals("BUY") Then takeProfit.Action = "SELL" Else takeProfit.Action = "BUY"
takeProfit.OrderType = "LMT"
takeProfit.TotalQuantity = quantity
takeProfit.LmtPrice = takeProfitLimitPrice
takeProfit.ParentId = parentOrderId
takeProfit.Transmit = False
Dim stopLoss As Order = New Order
stopLoss.OrderId = parent.OrderId + 2
If action.Equals("BUY") Then stopLoss.Action = "SELL" Else stopLoss.Action = "BUY"
stopLoss.OrderType = "STP"
'Stop trigger price
stopLoss.AuxPrice = stopLossPrice
stopLoss.TotalQuantity = quantity
stopLoss.ParentId = parentOrderId
'In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to true 
'to activate all its predecessors
stopLoss.Transmit = True
Dim orders As List(Of Order) = New List(Of Order)
orders.Add(parent)
orders.Add(takeProfit)
orders.Add(stopLoss)

Dim bracket As List(Of Order) = OrderSamples.BracketOrder(increment(nextOrderId), "BUY", 100, 30, 40, 20)
For Each o As Order In bracket
	client.placeOrder(o.OrderId, ContractSamples.EuropeanStock(), o)
Next

 

One Cancels All

The One-Cancels All (OCA) order type allows an investor to place multiple and possibly unrelated orders assigned to a group. The aim is to complete just one of the orders, which in turn will cause TWS to cancel the remaining orders. The investor may submit several orders aimed at taking advantage of the most desirable price within the group. Completion of one piece of the group order causes cancellation of the remaining group orders while partial completion causes the group to re-balance. An investor might desire to sell 1000 shares of only ONE of three positions held above prevailing market prices. The OCA order group allows the investor to enter prices at specified target levels and if one is completed, the other two will automatically cancel. Alternatively, an investor may wish to take a LONG position in eMini S&P stock index futures in a falling market or else SELL US treasury futures at a more favorable price. Grouping the two orders using an OCA order type offers the investor two chances to enter a similar position, while only running the risk of taking on a single position.

More on One-Cancels All orders

@staticmethod
def OneCancelsAll(ocaGroup:str, ocaOrders:ListOfOrder, ocaType:int):
    for o in ocaOrders: 
        o.ocaGroup = ocaGroup
        o.ocaType = ocaType         
    return ocaOrders
ocaOrders = [OrderSamples.LimitOrder("BUY", 1, 10), OrderSamples.LimitOrder("BUY", 1, 11), OrderSamples.LimitOrder("BUY", 1, 12)]
OrderSamples.OneCancelsAll("TestOCA_" + str(self.nextValidOrderId), ocaOrders, 2)
for o in ocaOrders:
self.placeOrder(self.nextOrderId(), ContractSamples.USStockAtSmart(), o)
public static List<Order> OneCancelsAll(String ocaGroup, List<Order> ocaOrders, int ocaType) {
    for (Order o : ocaOrders) {
        o.ocaGroup(ocaGroup);
        o.ocaType(ocaType);
    }
    return ocaOrders;
}
List<Order> OcaOrders = new ArrayList<>();
OcaOrders.add(OrderSamples.LimitOrder("BUY", Decimal.ONE, 10));
OcaOrders.add(OrderSamples.LimitOrder("BUY", Decimal.ONE, 11));
OcaOrders.add(OrderSamples.LimitOrder("BUY", Decimal.ONE, 12));
OcaOrders = OrderSamples.OneCancelsAll("TestOCA_" + nextOrderId, OcaOrders, 2);
for (Order o : OcaOrders) {
    client.placeOrder(nextOrderId++, ContractSamples.USStock(), o);
}
void OrderSamples::OneCancelsAll(std::string ocaGroup, Order& ocaOrder, int ocaType){
        ocaOrder.ocaGroup = ocaGroup;
        ocaOrder.ocaType = ocaType;
}
std::vector<Order> ocaOrders;
ocaOrders.push_back(OrderSamples::LimitOrder("BUY", stringToDecimal("1"), 10));
ocaOrders.push_back(OrderSamples::LimitOrder("BUY", stringToDecimal("1"), 11));
ocaOrders.push_back(OrderSamples::LimitOrder("BUY", stringToDecimal("1"), 12));
for(unsigned int i = 0; i < ocaOrders.size(); i++){
    OrderSamples::OneCancelsAll("TestOca", ocaOrders[i], 2);
    m_pClient->placeOrder(m_orderId++, ContractSamples::USStock(), ocaOrders[i]);
}

 

public static List<Order> OneCancelsAll(string ocaGroup, List<Order> ocaOrders, int ocaType)
{
    foreach (Order o in ocaOrders)
    {
        o.OcaGroup = ocaGroup;
        o.OcaType = ocaType;
    }
    return ocaOrders;
}
List<Order> ocaOrders = new List<Order>();
ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 10));
ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 11));
ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 12));
OrderSamples.OneCancelsAll("TestOCA_" + nextOrderId, ocaOrders, 2);
foreach (Order o in ocaOrders)
    client.placeOrder(nextOrderId++, ContractSamples.USStock(), o);

 

For Each o As Order In ocaOrders
    o.OcaGroup = ocaGroup
    o.OcaType = ocaType
    'Same as with Bracket orders. To prevent accidental executions, set all orders' transmit flag to false.
    'This will tell the TWS Not to send the orders, allowing your program to send them all first.
    o.Transmit = False
Next o

'Telling the TWS to transmit the last order in the OCA will also cause the transmission of its predecessors.
ocaOrders.Item(ocaOrders.Count - 1).Transmit = True
Dim ocaOrders As List(Of Order) = New List(Of Order)
ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 10))
ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 11))
ocaOrders.Add(OrderSamples.LimitOrder("BUY", 1, 12))
OrderSamples.OneCancelsAll("TestOCA_" + nextOrderId, ocaOrders, 2)
For Each o As Order In ocaOrders
    client.placeOrder(increment(nextOrderId), ContractSamples.USStock(), o)
Next

 

OCA Types

Via the IBApi.Order.OcaType attribute, the way in which remaining orders should be handled after an execution can be configured as indicated in the table.

Value Description
1 Cancel all remaining orders with block.*
2 Remaining orders are proportionately reduced in size with block.*
3 Remaining orders are proportionately reduced in size with no block.

Note*: if you use a value “with block” it gives the order overfill protection. This means that only one order in the group will be routed at a time to remove the possibility of an overfill. Click here for further discussion of OCA orders.

More on OCA Orders

More on the IBApi.Order.OcaType attribute

Adjustable Stops

You can attach one-time adjustments to stop, stop limit, trailing stop and trailing stop limit orders. When you attach an adjusted order, you set a trigger price that triggers a modification of the original (or parent) order, instead of triggering order transmission.

Adjusted to Stop

# Attached order is a conventional STP order in opposite direction
order = OrderSamples.Stop("SELL" if parent.action == "BUY" else "BUY", parent.totalQuantity, attachedOrderStopPrice)
order.parentId = parent.orderId
#When trigger price is penetrated
order.triggerPrice = triggerPrice
#The parent order will be turned into a STP order
order.adjustedOrderType = "STP"
#With the given STP price
order.adjustedStopPrice = adjustStopPrice

 

Order order = new Order();
//Attached order is a conventional STP order in opposite direction
order.action("BUY".equals(parent.getAction()) ? "SELL" : "BUY");
order.totalQuantity(parent.totalQuantity());
order.auxPrice(attachedOrderStopPrice);
order.parentId(parent.orderId());
//When trigger price is penetrated
order.triggerPrice(triggerPrice);
//The parent order will be turned into a STP order
order.adjustedOrderType(OrderType.STP);
//With the given STP price
order.adjustedStopPrice(adjustStopPrice);

 

//Attached order is a conventional STP order in opposite direction
Order order;
order.action = (parent.action == "BUY") ? "SELL": "BUY";
order.orderType = "STP";
order.totalQuantity = parent.totalQuantity;
order.auxPrice = attachedOrderStopPrice;
order.parentId = parent.orderId;
//When trigger price is penetrated
order.triggerPrice = triggerPrice;
//The parent order will be turned into a STP order
order.adjustedOrderType = "STP";
//With the given STP price
order.adjustedStopPrice = adjustStopPrice;

 

//Attached order is a conventional STP order in opposite direction
Order order = Stop(parent.Action.Equals("BUY") ? "SELL" : "BUY", parent.TotalQuantity, attachedOrderStopPrice);
order.ParentId = parent.OrderId;
//When trigger price is penetrated
order.TriggerPrice = triggerPrice;
//The parent order will be turned into a STP order
order.AdjustedOrderType = "STP";
//With the given STP price
order.AdjustedStopPrice = adjustStopPrice;

 

'Attached order Is a conventional STP order in opposite direction
Dim action As String = "BUY"
If (parent.Action.Equals("BUY")) Then
    action = "SELL"
End If
Dim order As Order = StopOrder(action, parent.TotalQuantity, attachedOrderStopPrice)
order.ParentId = parent.OrderId
'When trigger price Is penetrated
order.TriggerPrice = triggerPrice
'The parent order will be turned into a STP order
order.AdjustedOrderType = "STP"
'With the given STP price
order.AdjustedStopPrice = adjustStopPrice

 

Adjusted to Stop Limit

#Attached order is a conventional STP order
order = OrderSamples.Stop("SELL" if parent.action == "BUY" else "BUY", parent.totalQuantity, attachedOrderStopPrice)
order.parentId = parent.orderId
#When trigger price is penetrated
order.triggerPrice = triggerPrice
#The parent order will be turned into a STP LMT order
order.adjustedOrderType = "STP LMT"
#With the given stop price
order.adjustedStopPrice = adjustedStopPrice
#And the given limit price
order.adjustedStopLimitPrice = adjustedStopLimitPrice

 

 Order order = new Order();
//Attached order is a conventional STP order
order.action("BUY".equals(parent.getAction()) ? "SELL" : "BUY");
order.totalQuantity(parent.totalQuantity());
order.auxPrice(attachedOrderStopPrice);
order.parentId(parent.orderId());
//When trigger price is penetrated
order.triggerPrice(triggerPrice);
//The parent order will be turned into a STP LMT order
order.adjustedOrderType(OrderType.STP_LMT);
//With the given stop price
order.adjustedStopPrice(adjustStopPrice);
//And the given limit price
order.adjustedStopLimitPrice(adjustedStopLimitPrice);

 

//Attached order is a conventional STP order
Order order;
order.action = (parent.action == "BUY") ? "SELL": "BUY";
order.orderType = "STP";
order.totalQuantity = parent.totalQuantity;
order.auxPrice = attachedOrderStopPrice;
order.parentId = parent.orderId;
//When trigger price is penetrated
order.triggerPrice = triggerPrice;
//The parent order will be turned into a STP LMT order
order.adjustedOrderType = "STP LMT";
//With the given stop price
order.adjustedStopPrice = adjustStopPrice;
//And the given limit price
order.adjustedStopLimitPrice = adjustedStopLimitPrice;

 

//Attached order is a conventional STP order
Order order = Stop(parent.Action.Equals("BUY") ? "SELL" : "BUY", parent.TotalQuantity, attachedOrderStopPrice);
order.ParentId = parent.OrderId;
//When trigger price is penetrated
order.TriggerPrice = triggerPrice;
//The parent order will be turned into a STP LMT order
order.AdjustedOrderType = "STP LMT";
//With the given stop price
order.AdjustedStopPrice = adjustedStopPrice;
//And the given limit price
order.AdjustedStopLimitPrice = adjustedStopLimitPrice;

 

'Attached order Is a conventional STP order
Dim action As String = "BUY"
If (parent.Action.Equals("BUY")) Then
    action = "SELL"
End If
Dim order As Order = StopOrder(action, parent.TotalQuantity, attachedOrderStopPrice)
order.ParentId = parent.OrderId
'When trigger price Is penetrated
order.TriggerPrice = triggerPrice
'The parent order will be turned into a STP LMT order
order.AdjustedOrderType = "STP LMT"
'With the given stop price
order.AdjustedStopPrice = adjustedStopPrice
'And the given limit price
order.AdjustedStopLimitPrice = adjustedStopLimitPrice

 

Adjusted to Trail

#Attached order is a conventional STP order
order = OrderSamples.Stop("SELL" if parent.action == "BUY" else "BUY", parent.totalQuantity, attachedOrderStopPrice)
order.parentId = parent.orderId
#When trigger price is penetrated
order.triggerPrice = triggerPrice
#The parent order will be turned into a TRAIL order
order.adjustedOrderType = "TRAIL"
#With a stop price of...
order.adjustedStopPrice = adjustedStopPrice
#traling by and amount (0) or a percent (100)...
order.adjustableTrailingUnit = trailUnit
#of...
order.adjustedTrailingAmount = adjustedTrailAmount

 

Order order = new Order();
//Attached order is a conventional STP order
order.action("BUY".equals(parent.getAction()) ? "SELL" : "BUY");
order.totalQuantity(parent.totalQuantity());
order.auxPrice(attachedOrderStopPrice);
order.parentId(parent.orderId());
//When trigger price is penetrated
order.triggerPrice(triggerPrice);
//The parent order will be turned into a TRAIL order
order.adjustedOrderType(OrderType.TRAIL);
//With a stop price of...
order.adjustedStopPrice(adjustStopPrice);
//trailing by and amount (0) or a percent (100)...
order.adjustableTrailingUnit(trailUnit);
//of...
order.adjustedTrailingAmount(adjustedTrailAmount);

 

//Attached order is a conventional STP order
Order order;
order.action = (parent.action == "BUY") ? "SELL": "BUY";
order.orderType = "STP";
order.totalQuantity = parent.totalQuantity;
order.auxPrice = attachedOrderStopPrice;
order.parentId = parent.orderId;
//When trigger price is penetrated
order.triggerPrice = triggerPrice;
//The parent order will be turned into a TRAIL order
order.adjustedOrderType = "TRAIL";
//With a stop price of...
order.adjustedStopPrice = adjustStopPrice;
//traling by and amount (0) or a percent (100)...
order.adjustableTrailingUnit = trailUnit;
//of...
order.adjustedTrailingAmount = adjustedTrailAmount;

 

//Attached order is a conventional STP order
Order order = Stop(parent.Action.Equals("BUY") ? "SELL" : "BUY", parent.TotalQuantity, attachedOrderStopPrice);
order.ParentId = parent.OrderId;
//When trigger price is penetrated
order.TriggerPrice = triggerPrice;
//The parent order will be turned into a TRAIL order
order.AdjustedOrderType = "TRAIL";
//With a stop price of...
order.AdjustedStopPrice = adjustedStopPrice;
//traling by and amount (0) or a percent (100)...
order.AdjustableTrailingUnit = trailUnit;
//of...
order.AdjustedTrailingAmount = adjustedTrailAmount;

 

'Attached order Is a conventional STP order
Dim action As String = "BUY"
If (parent.Action.Equals("BUY")) Then
    action = "SELL"
End If
Dim order As Order = StopOrder(action,parent.TotalQuantity, attachedOrderStopPrice)
order.ParentId = parent.OrderId
'When trigger price Is penetrated
order.TriggerPrice = triggerPrice
'The parent order will be turned into a TRAIL order
order.AdjustedOrderType = "TRAIL"
'With a stop price of...
order.AdjustedStopPrice = adjustedStopPrice
'traling by And amount (0) Or a percent (100)...
order.AdjustableTrailingUnit = trailUnit
'of...
order.AdjustedTrailingAmount = adjustedTrailAmount

 

Order Conditioning

Conditions allow to activate orders given a certain criteria …

 

 

 

 

mkt = OrderSamples.MarketOrder("BUY", 100)
# Order will become active if conditioning criteria is met
mkt.conditions.append(OrderSamples.PriceCondition(
PriceCondition.TriggerMethodEnum.Default,208813720, "SMART", 600, False, False))
mkt.conditions.append(OrderSamples.ExecutionCondition("EUR.USD", "CASH", "IDEALPRO", True))
mkt.conditions.append(OrderSamples.MarginCondition(30, True, False))
mkt.conditions.append(OrderSamples.PercentageChangeCondition(15.0, 208813720, "SMART", True, True))
mkt.conditions.append(OrderSamples.TimeCondition("20160118 23:59:59 US/Eastern", True, False))
mkt.conditions.append(OrderSamples.VolumeCondition(208813720, "SMART", False, 100, True))
self.placeOrder(self.nextOrderId(), ContractSamples.EuropeanStock(), mkt)

 

Order mkt = OrderSamples.MarketOrder("BUY", Decimal.ONE_HUNDRED);
//Order will become active if conditioning criteria is met
mkt.conditions().add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false));
mkt.conditions().add(OrderSamples.ExecutionCondition("EUR.USD", "CASH", "IDEALPRO", true));
mkt.conditions().add(OrderSamples.MarginCondition(30, true, false));
mkt.conditions().add(OrderSamples.PercentageChangeCondition(15.0, 208813720, "SMART", true, true));
mkt.conditions().add(OrderSamples.TimeCondition("20220909 10:00:00 US/Eastern", true, false));
mkt.conditions().add(OrderSamples.VolumeCondition(208813720, "SMART", false, 100, true));
client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), mkt);

 

 Order lmt = OrderSamples::LimitOrder("BUY", stringToDecimal("100"), 10);
//Order will become active if conditioning criteria is met
PriceCondition* priceCondition = dynamic_cast<PriceCondition *>(OrderSamples::Price_Condition(208813720, "SMART", 600, false, false));
ExecutionCondition* execCondition = dynamic_cast<ExecutionCondition *>(OrderSamples::Execution_Condition("EUR.USD", "CASH", "IDEALPRO", true));
MarginCondition* marginCondition = dynamic_cast<MarginCondition *>(OrderSamples::Margin_Condition(30, true, false));
PercentChangeCondition* pctChangeCondition = dynamic_cast<PercentChangeCondition *>(OrderSamples::Percent_Change_Condition(15.0, 208813720, "SMART", true, true));
TimeCondition* timeCondition = dynamic_cast<TimeCondition *>(OrderSamples::Time_Condition("20220808 10:00:00 US/Eastern", true, false));
VolumeCondition* volumeCondition = dynamic_cast<VolumeCondition *>(OrderSamples::Volume_Condition(208813720, "SMART", false, 100, true));
lmt.conditions.push_back(std::shared_ptr<PriceCondition>(priceCondition));
lmt.conditions.push_back(std::shared_ptr<ExecutionCondition>(execCondition));
lmt.conditions.push_back(std::shared_ptr<MarginCondition>(marginCondition));
lmt.conditions.push_back(std::shared_ptr<PercentChangeCondition>(pctChangeCondition));
lmt.conditions.push_back(std::shared_ptr<TimeCondition>(timeCondition));
lmt.conditions.push_back(std::shared_ptr<VolumeCondition>(volumeCondition));
m_pClient->placeOrder(m_orderId++, ContractSamples::USStock(),lmt);

 

Order mkt = OrderSamples.MarketOrder("BUY", 100);
//Order will become active if conditioning criteria is met
mkt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false));
mkt.Conditions.Add(OrderSamples.ExecutionCondition("EUR.USD", "CASH", "IDEALPRO", true));
mkt.Conditions.Add(OrderSamples.MarginCondition(30, true, false));
mkt.Conditions.Add(OrderSamples.PercentageChangeCondition(15.0, 208813720, "SMART", true, true));
mkt.Conditions.Add(OrderSamples.TimeCondition("20160118 23:59:59 US/Eastern", true, false));
mkt.Conditions.Add(OrderSamples.VolumeCondition(208813720, "SMART", false, 100, true));
client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), mkt);

 

Dim mkt As Order = OrderSamples.MarketOrder("BUY", 100)
'Order will become active if conditioning criteria Is met
mkt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, False, False))
mkt.Conditions.Add(OrderSamples.ExecutionCondition("EUR.USD", "CASH", "IDEALPRO", True))
mkt.Conditions.Add(OrderSamples.MarginCondition(30, True, False))
mkt.Conditions.Add(OrderSamples.PercentageChangeCondition(15.0, 208813720, "SMART", True, True))
mkt.Conditions.Add(OrderSamples.TimeCondition("20160118 23:59:59 US/Eastern", True, False))
mkt.Conditions.Add(OrderSamples.VolumeCondition(208813720, "SMART", False, 100, True))
client.placeOrder(increment(nextOrderId), ContractSamples.EuropeanStock(), mkt)

 

Or cancel them.

lmt = OrderSamples.LimitOrder("BUY", 100, 20)
# The active order will be cancelled if conditioning criteria is met
lmt.conditionsCancelOrder = True
lmt.conditions.append(OrderSamples.PriceCondition(  PriceCondition.TriggerMethodEnum.Last,208813720, "SMART", 600, False, False))
self.placeOrder(self.nextOrderId(), ContractSamples.EuropeanStock(), lmt)

 

Order lmt = OrderSamples.LimitOrder("BUY", Decimal.ONE_HUNDRED, 20);
//The active order will be cancelled if conditioning criteria is met
lmt.conditionsCancelOrder(true);
lmt.conditions().add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false));
client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), lmt);

 

 Order lmt2 = OrderSamples::LimitOrder("BUY", stringToDecimal("100"), 20);
//The active order will be cancelled if conditioning criteria is met
lmt2.conditionsCancelOrder = true;
PriceCondition* priceCondition2 = dynamic_cast<PriceCondition *>(OrderSamples::Price_Condition(208813720, "SMART", 600, false, false));
lmt2.conditions.push_back(std::shared_ptr<PriceCondition>(priceCondition2));
m_pClient->placeOrder(m_orderId++, ContractSamples::EuropeanStock(), lmt2);

 

Order lmt = OrderSamples.LimitOrder("BUY", 100, 20);
//The active order will be cancelled if conditioning criteria is met
lmt.ConditionsCancelOrder = true;
lmt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false));
client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), lmt);

 

Dim lmt As Order = OrderSamples.LimitOrder("BUY", 100, 20)
'The active order will be cancelled if conditioning criteria Is met
lmt.ConditionsCancelOrder = True
lmt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, False, False))
client.placeOrder(increment(nextOrderId), ContractSamples.EuropeanStock(), lmt)

 

Price Conditions

 #Conditions have to be created via the OrderCondition.create 
priceCondition = order_condition.Create(OrderCondition.Price)
#When this contract...
priceCondition.conId = conId
#traded on this exchange
priceCondition.exchange = exchange
#has a price above/below
priceCondition.isMore = isMore
priceCondition.triggerMethod = triggerMethod
#this quantity
priceCondition.price = price
#AND | OR next condition (will be ignored if no more conditions are added)
priceCondition.isConjunctionConnection = isConjunction

 

//Conditions have to be created via the OrderCondition.Create
PriceCondition priceCondition = (PriceCondition)OrderCondition.create(OrderConditionType.Price);
//When this contract...
priceCondition.conId(conId);
//traded on this exchange
priceCondition.exchange(exchange);
//has a price above/below
priceCondition.isMore(isMore);
//this quantity
priceCondition.price(price);
//AND | OR next condition (will be ignored if no more conditions are added)
priceCondition.conjunctionConnection(isConjunction);

 

//Conditions have to be created via the OrderCondition.Create 
PriceCondition* priceCondition = dynamic_cast<PriceCondition *>(OrderCondition::create(OrderCondition::OrderConditionType::Price));
//When this contract...
priceCondition->conId(conId);
//traded on this exchange
priceCondition->exchange(exchange);
//has a price above/below
priceCondition->isMore(isMore);
//this quantity
priceCondition->price(price);
//AND | OR next condition (will be ignored if no more conditions are added)
priceCondition->conjunctionConnection(isConjunction);

 

//Conditions have to be created via the OrderCondition.Create 
PriceCondition priceCondition = (PriceCondition)OrderCondition.Create(OrderConditionType.Price);
//When this contract...
priceCondition.ConId = conId;
//traded on this exchange
priceCondition.Exchange = exchange;
//has a price above/below
priceCondition.IsMore = isMore;
//this quantity
priceCondition.Price = price;
//AND | OR next condition (will be ignored if no more conditions are added)
priceCondition.IsConjunctionConnection = isConjunction;

 

'Conditions have to be created via the OrderCondition.Create 
Dim _priceCondition As PriceCondition = OrderCondition.Create(OrderConditionType.Price) 'cast to priceCondition
'When this contract...
_priceCondition.ConId = conId
'traded on this exchange
_priceCondition.Exchange = exchange
'has a price above/below
_priceCondition.IsMore = isMore
'this quantity
_priceCondition.Price = price
'And | Or next condition (will be ignored if no more conditions are added)
_priceCondition.IsConjunctionConnection = isConjunction

 

Execution Conditions

execCondition = order_condition.Create(OrderCondition.Execution)
#When an execution on symbol
execCondition.symbol = symbol
#at exchange
execCondition.exchange = exchange
#for this secType
execCondition.secType = secType
#AND | OR next condition (will be ignored if no more conditions are added)
execCondition.isConjunctionConnection = isConjunction

 

 ExecutionCondition execCondition = (ExecutionCondition)OrderCondition.create(OrderConditionType.Execution);
//When an execution on symbol
execCondition.symbol(symbol);
//at exchange
execCondition.exchange(exchange);
//for this secType
execCondition.secType(secType);
//AND | OR next condition (will be ignored if no more conditions are added)
execCondition.conjunctionConnection(isConjunction);

 

 ExecutionCondition* execCondition = dynamic_cast<ExecutionCondition *>(OrderCondition::create(OrderCondition::OrderConditionType::Execution));
//When an execution on symbol
execCondition->symbol(symbol);
//at exchange
execCondition->exchange(exchange);
//for this secType
execCondition->secType(secType);
//AND | OR next condition (will be ignored if no more conditions are added)
execCondition->conjunctionConnection(isConjunction);

 

ExecutionCondition execCondition = (ExecutionCondition)OrderCondition.Create(OrderConditionType.Execution);
//When an execution on symbol
execCondition.Symbol = symbol;
//at exchange
execCondition.Exchange = exchange;
//for this secType
execCondition.SecType = secType;
//AND | OR next condition (will be ignored if no more conditions are added)
execCondition.IsConjunctionConnection = isConjunction;

 

Dim execCondition As ExecutionCondition = OrderCondition.Create(OrderConditionType.Execution) ' cast to (ExecutionCondition)
'When an execution on symbol
execCondition.Symbol = symbol
'at exchange
execCondition.Exchange = exchange
'for this secType
execCondition.SecType = secType
'And | Or next condition (will be ignored if no more conditions are added)
execCondition.IsConjunctionConnection = isConjunction

 

Margin Conditions

marginCondition = order_condition.Create(OrderCondition.Margin)
#If margin is above/below
marginCondition.isMore = isMore
#given percent
marginCondition.percent = percent
#AND | OR next condition (will be ignored if no more conditions are added)
marginCondition.isConjunctionConnection = isConjunction

 

MarginCondition marginCondition = (MarginCondition)OrderCondition.create(OrderConditionType.Margin);
//If margin is above/below
marginCondition.isMore(isMore);
//given percent
marginCondition.percent(percent);
//AND | OR next condition (will be ignored if no more conditions are added)
marginCondition.conjunctionConnection(isConjunction);

 

MarginCondition* marginCondition = dynamic_cast<MarginCondition *>(OrderCondition::create(OrderCondition::OrderConditionType::Margin));
//If margin is above/below
marginCondition->percent(percent);
//given percent
marginCondition->isMore(isMore);
//AND | OR next condition (will be ignored if no more conditions are added)
marginCondition->conjunctionConnection(isConjunction);

 

MarginCondition marginCondition = (MarginCondition)OrderCondition.Create(OrderConditionType.Margin);
//If margin is above/below
marginCondition.IsMore = isMore;
//given percent
marginCondition.Percent = percent;
//AND | OR next condition (will be ignored if no more conditions are added)
marginCondition.IsConjunctionConnection = isConjunction;

 

Dim _MarginCondition As MarginCondition = OrderCondition.Create(OrderConditionType.Margin) ' cast to (MarginCondition)
'If margin Is above/below
_MarginCondition.IsMore = isMore
'given percent
_MarginCondition.Percent = percent
'And | Or next condition (will be ignored if no more conditions are added)
_MarginCondition.IsConjunctionConnection = isConjunction

 

Percentage Conditions

 pctChangeCondition = order_condition.Create(OrderCondition.PercentChange)
#If there is a price percent change measured against last close price above or below...
pctChangeCondition.isMore = isMore
#this amount...
pctChangeCondition.changePercent = pctChange
#on this contract
pctChangeCondition.conId = conId
#when traded on this exchange...
pctChangeCondition.exchange = exchange
#AND | OR next condition (will be ignored if no more conditions are added)
pctChangeCondition.isConjunctionConnection = isConjunction

 

PercentChangeCondition pctChangeCondition = (PercentChangeCondition)OrderCondition.create(OrderConditionType.PercentChange);
//If there is a price percent change measured against last close price above or below...
pctChangeCondition.isMore(isMore);
//this amount...
pctChangeCondition.changePercent(pctChange);
//on this contract
pctChangeCondition.conId(conId);
//when traded on this exchange...
pctChangeCondition.exchange(exchange);
//AND | OR next condition (will be ignored if no more conditions are added)
pctChangeCondition.conjunctionConnection(isConjunction);

 

PercentChangeCondition* pctChangeCondition = dynamic_cast<PercentChangeCondition *>(OrderCondition::create(OrderCondition::OrderConditionType::PercentChange));
//If there is a price percent change measured against last close price above or below...
pctChangeCondition->isMore(isMore);
//this amount...
pctChangeCondition->changePercent(pctChange);
//on this contract
pctChangeCondition->conId(conId);
//when traded on this exchange...
pctChangeCondition->exchange(exchange);
//AND | OR next condition (will be ignored if no more conditions are added)
pctChangeCondition->conjunctionConnection(isConjunction);

 

PercentChangeCondition pctChangeCondition = (PercentChangeCondition)OrderCondition.Create(OrderConditionType.PercentCange);
//If there is a price percent change measured against last close price above or below...
pctChangeCondition.IsMore = isMore;
//this amount...
pctChangeCondition.ChangePercent = pctChange;
//on this contract
pctChangeCondition.ConId = conId;
//when traded on this exchange...
pctChangeCondition.Exchange = exchange;
//AND | OR next condition (will be ignored if no more conditions are added)
pctChangeCondition.IsConjunctionConnection = isConjunction;

 

Dim pctChangeCondition As PercentChangeCondition = OrderCondition.Create(OrderConditionType.PercentCange) 'cast (PercentChangeCondition)
'If there Is a price percent change measured against last close price above Or below...
pctChangeCondition.IsMore = isMore
'this amount...
pctChangeCondition.ChangePercent = pctChange
'on this contract
pctChangeCondition.ConId = conId
'when traded on this exchange...
pctChangeCondition.Exchange = exchange
'And | Or next condition (will be ignored if no more conditions are added)
pctChangeCondition.IsConjunctionConnection = isConjunction

 

Time Conditions

timeCondition = order_condition.Create(OrderCondition.Time)
#Before or after...
timeCondition.isMore = isMore
#this time..
timeCondition.time = time
#AND | OR next condition (will be ignored if no more conditions are added)     
timeCondition.isConjunctionConnection = isConjunction

 

TimeCondition timeCondition = (TimeCondition)OrderCondition.create(OrderConditionType.Time);
//Before or after...
timeCondition.isMore(isMore);
//this time...
timeCondition.time(time);
//AND | OR next condition (will be ignored if no more conditions are added)
timeCondition.conjunctionConnection(isConjunction);

 

TimeCondition* timeCondition = dynamic_cast<TimeCondition *>(OrderCondition::create(OrderCondition::OrderConditionType::Time));
//Before or after...
timeCondition->isMore(isMore);
//this time..
timeCondition->time(time);
//AND | OR next condition (will be ignored if no more conditions are added)  
timeCondition->conjunctionConnection(isConjunction);

 

TimeCondition timeCondition = (TimeCondition)OrderCondition.Create(OrderConditionType.Time);
//Before or after...
timeCondition.IsMore = isMore;
//this time..
timeCondition.Time = time;
//AND | OR next condition (will be ignored if no more conditions are added)     
timeCondition.IsConjunctionConnection = isConjunction;

 

Dim _TimeCondition As TimeCondition = OrderCondition.Create(OrderConditionType.Time) 'cast (timeCondition)
'Before Or after...
_TimeCondition.IsMore = isMore
'this time..
_TimeCondition.Time = time
'And | Or next condition (will be ignored if no more conditions are added)     
_TimeCondition.IsConjunctionConnection = isConjunction

 

Volume Conditions

volCond = order_condition.Create(OrderCondition.Volume)
#Whenever contract...
volCond.conId = conId
#When traded at
volCond.exchange = exchange
#reaches a volume higher/lower
volCond.isMore = isMore
#than this...
volCond.volume = volume
#AND | OR next condition (will be ignored if no more conditions are added)
volCond.isConjunctionConnection = isConjunction

 

VolumeCondition volCon = (VolumeCondition)OrderCondition.create(OrderConditionType.Volume);
//Whenever contract...
volCon.conId(conId);
//When traded at
volCon.exchange(exchange);
//reaches a volume higher/lower
volCon.isMore(isMore);
//than this...
volCon.volume(volume);
//AND | OR next condition (will be ignored if no more conditions are added)
volCon.conjunctionConnection(isConjunction);

 

VolumeCondition* volCondition = dynamic_cast<VolumeCondition *>(OrderCondition::create(OrderCondition::OrderConditionType::Volume));
//Whenever contract...
volCondition->conId(conId);
//When traded at
volCondition->exchange(exchange);
//reaches a volume higher/lower
volCondition->isMore(isMore);
//than this...
volCondition->volume(volume);
//AND | OR next condition (will be ignored if no more conditions are added)
volCondition->conjunctionConnection(isConjunction);

 

VolumeCondition volCond = (VolumeCondition)OrderCondition.Create(OrderConditionType.Volume);
//Whenever contract...
volCond.ConId = conId;
//When traded at
volCond.Exchange = exchange;
//reaches a volume higher/lower
volCond.IsMore = isMore;
//than this...
volCond.Volume = volume;
//AND | OR next condition (will be ignored if no more conditions are added)
volCond.IsConjunctionConnection = isConjunction;

 

 Dim volCond As VolumeCondition = OrderCondition.Create(OrderConditionType.Volume) 'cast (VolumeCondition)
'Whenever contract...
volCond.ConId = conId
'When traded at
volCond.Exchange = exchange
'reaches a volume higher/lower
volCond.IsMore = isMore
'than this...
volCond.Volume = volume
'And | Or next condition (will be ignored if no more conditions are added)
volCond.IsConjunctionConnection = isConjunction

 

IBKRATS Order Types

Customers can direct non-marketable U.S. stock orders to the IBKRATS destination to add liquidity. Orders directed to IBKRATS are tagged as “not held” orders, and are posted in IBKR’s order book where incoming SmartRouted orders from other IBKR customers are eligible to take liquidity by trading against them.
To route an order to IBKRATS via the API, you need to set the IBApi::Contract::Exchange field to “IBKRATS” and IBApi::Order::NotHeld to True.

More on IBKRATS Orders

Note: The order must have the NotHeld field set to True, or you may receive a rejection with the reason; “IBKRAts order must be a not-held”. When submitting via the TWS UI, this is set automatically.

Pegged-to-Best

order = Order()
order.action = action
order.orderType = "PEG BEST"
order.lmtPrice = limitPrice
order.totalQuantity = quantity
order.notHeld = True
order.minTradeQty = minTradeQty
order.minCompeteSize = minCompeteSize
order.competeAgainstBestOffset = competeAgainstBestOffset

 

Order order = new Order();
order.action(action);
order.orderType("PEG BEST");
order.lmtPrice(limitPrice);
order.totalQuantity(quantity);
order.notHeld(true);
order.minTradeQty(minTradeQty);
order.minCompeteSize(minCompeteSize);
order.competeAgainstBestOffset(competeAgainstBestOffset);

 

Order order;
order.action = action;
order.orderType = "PEG BEST";
order.lmtPrice = limitPrice;
order.totalQuantity = quantity;
order.notHeld = true;
order.minTradeQty = minTradeQty;
order.minCompeteSize = minCompeteSize;
order.competeAgainstBestOffset = competeAgainstBestOffset;

 

Order order = new Order();
order.Action = action;
order.OrderType = "PEG BEST";
order.LmtPrice = limitPrice;
order.TotalQuantity = quantity;
order.NotHeld = true;
order.MinTradeQty = minTradeQty;
order.MinCompeteSize = minCompeteSize;
order.CompeteAgainstBestOffset = competeAgainstBestOffset;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "PEG BEST"
order.LmtPrice = limitPrice
order.TotalQuantity = quantity
order.NotHeld = True
order.MinTradeQty = minTradeQty
order.MinCompeteSize = minCompeteSize
order.CompeteAgainstBestOffset = competeAgainstBestOffset

 

Pegged-to-Best offset difference

order = Order()
order.action = action
order.orderType = "PEG BEST"
order.lmtPrice = limitPrice
order.totalQuantity = quantity
order.notHeld = True
order.minTradeQty = minTradeQty
order.minCompeteSize = minCompeteSize
order.competeAgainstBestOffset = COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID
order.midOffsetAtWhole = midOffsetAtWhole
order.midOffsetAtHalf = midOffsetAtHalf

 

Order order = new Order();
order.action(action);
order.orderType("PEG BEST");
order.lmtPrice(limitPrice);
order.totalQuantity(quantity);
order.notHeld(true);
order.minTradeQty(minTradeQty);
order.minCompeteSize(minCompeteSize);
order.competeAgainstBestOffset(Order.COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID);
order.midOffsetAtWhole(midOffsetAtWhole);
order.midOffsetAtHalf(midOffsetAtHalf);

 

Order order;
order.action = action;
order.orderType = "PEG BEST";
order.lmtPrice = limitPrice;
order.totalQuantity = quantity;
order.notHeld = true;
order.minTradeQty = minTradeQty;
order.minCompeteSize = minCompeteSize;
order.competeAgainstBestOffset = COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID;
order.midOffsetAtWhole = midOffsetAtWhole;
order.midOffsetAtHalf = midOffsetAtHalf;

 

Order order = new Order();
order.Action = action;
order.OrderType = "PEG BEST";
order.LmtPrice = limitPrice;
order.TotalQuantity = quantity;
order.NotHeld = true;
order.MinTradeQty = minTradeQty;
order.MinCompeteSize = minCompeteSize;
order.CompeteAgainstBestOffset = Order.COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID;
order.MidOffsetAtWhole = midOffsetAtWhole;
order.MidOffsetAtHalf = midOffsetAtHalf;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "PEG BEST"
order.LmtPrice = limitPrice
order.TotalQuantity = quantity
order.NotHeld = True
order.MinTradeQty = minTradeQty
order.MinCompeteSize = minCompeteSize
order.CompeteAgainstBestOffset = Order.COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID
order.MidOffsetAtWhole = midOffsetAtWhole
order.MidOffsetAtHalf = midOffsetAtHalf

 

Pegged-to-Midpoint

order = Order()
order.action = action
order.orderType = "PEG MID"
order.lmtPrice = limitPrice
order.totalQuantity = quantity
order.notHeld = True
order.minTradeQty = minTradeQty
order.midOffsetAtWhole = midOffsetAtWhole
order.midOffsetAtHalf = midOffsetAtHalf

 

Order order = new Order();
order.action(action);
order.orderType("PEG MID");
order.lmtPrice(limitPrice);
order.totalQuantity(quantity);
order.notHeld(true);
order.minTradeQty(minTradeQty);
order.midOffsetAtWhole(midOffsetAtWhole);
order.midOffsetAtHalf(midOffsetAtHalf);

 

Order order;
order.action = action;
order.orderType = "PEG MID";
order.lmtPrice = limitPrice;
order.totalQuantity = quantity;
order.notHeld = true;
order.minTradeQty = minTradeQty;
order.midOffsetAtWhole = midOffsetAtWhole;
order.midOffsetAtHalf = midOffsetAtHalf;

 

Order order = new Order();
order.Action = action;
order.OrderType = "PEG MID";
order.LmtPrice = limitPrice;
order.TotalQuantity = quantity;
order.NotHeld = true;
order.MinTradeQty = minTradeQty;
order.MidOffsetAtWhole = midOffsetAtWhole;
order.MidOffsetAtHalf = midOffsetAtHalf;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "PEG MID"
order.LmtPrice = limitPrice
order.TotalQuantity = quantity
order.NotHeld = True
order.MinTradeQty = minTradeQty
order.MidOffsetAtWhole = midOffsetAtWhole
order.MidOffsetAtHalf = midOffsetAtHalf

 

Algorithmic Orders

Order types and algos may help limit risk, speed execution, provide price improvement, allow privacy, time the market and simplify the trading process through advanced trading functions.

This page is intended to provide assistance with creating algo orders in the API. For more information on what IB Algorithms can do, please visit our IBKR Order Types and Algos page.

In nearly all cases,  Algo orders are additional parameters that can be used in addition to a standing order. 

Because of this structure, we will be using our Limit Order sample as a baseline. The algos documented here will be attached to the same “order” variable as used here.

order = Order()
order.action = action
order.orderType = "LMT"
order.totalQuantity = quantity
order.lmtPrice = limitPrice

 

Order order = new Order();
order.action(action);
order.orderType("LMT");
order.totalQuantity(quantity);
order.lmtPrice(limitPrice);
order.tif(TimeInForce.DAY);

 

Order order;
order.action = action;
order.orderType = "LMT";
order.totalQuantity = quantity;
order.lmtPrice = limitPrice;

 

Order order = new Order();
order.Action = action;
order.OrderType = "LMT";
order.TotalQuantity = quantity;
order.LmtPrice = limitPrice;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "LMT"
order.TotalQuantity = quantity
order.LmtPrice = limitPrice

 

IB Algorithms

Accumulate/Distribute

The Accumulate/Distribute algo can help you to achieve the best price for a large volume order without being noticed in the market, and can be set up for high frequency trading. By slicing your order into smaller randomly-sized order increments that are released at random time intervals within a user-defined time period, the algo allows the trading of large blocks of stock and other instruments without being detected in the market. The algo allows limit, market, and relative order types. It is important to keep in mind the API A/D algo will not have all available parameters of the A/D algos that can be created in TWS.

Algo Strategy Value: AD

componentSize: int. Quantity of increment.
Valid Value/Format: Cannot exceed initial size

timeBetweenOrders: int. Time interval in seconds between each order.
Valid Value/Format: 30

randomizeTime20: bool. Randomize time period by +/- 20%.
Valid Value/Format: 1 (true) or 0 (false)

randomizeSize55: bool. Randomize size by +/- 55%.
Valid Value/Format: 1 (true) or 0 (false)

giveUp: int. Stop attempting to catch up to the size value if the conditions are not achieved.

catchUp: bool. Catch up in time.
Valid Value/Format: 1 (true) or 0 (false)

waitForFill: bool. Wait for current order to fill before submitting next order.
Valid Value/Format: 1 (true) or 0 (false)

activeTimeStart: String. Algorithm starting time.
Valid Value/Format: YYYYMMDD-hh:mm:ss TMZ

activeTimeEnd: String. Algorithm ending time.
Valid Value/Format: YYYYMMDD-hh:mm:ss TMZ

order.algoStrategy = "AD"
order.algoParams = []
order.algoParams.append(TagValue("componentSize", componentSize))
order.algoParams.append(TagValue("timeBetweenOrders", timeBetweenOrders))
order.algoParams.append(TagValue("randomizeTime20", int(randomizeTime20)))
order.algoParams.append(TagValue("randomizeSize55", int(randomizeSize55)))
order.algoParams.append(TagValue("giveUp", giveUp))
order.algoParams.append(TagValue("catchUp", int(catchUp)))
order.algoParams.append(TagValue("waitForFill", int(waitForFill)))
order.algoParams.append(TagValue("activeTimeStart", startTime))
order.algoParams.append(TagValue("activeTimeEnd", endTime))

 

order.algoStrategy("AD");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("componentSize", String.valueOf(componentSize)));
order.algoParams().add(new TagValue("timeBetweenOrders", String.valueOf(timeBetweenOrders)));
order.algoParams().add(new TagValue("randomizeTime20", randomizeTime20 ? "1" : "0"));
order.algoParams().add(new TagValue("randomizeSize55", randomizeSize55 ? "1" : "0"));
order.algoParams().add(new TagValue("giveUp", String.valueOf(giveUp)));
order.algoParams().add(new TagValue("catchUp", catchUp ? "1" : "0"));
order.algoParams().add(new TagValue("waitForFill", waitForFill ? "1" : "0"));
order.algoParams().add(new TagValue("activeTimeStart", startTime));
order.algoParams().add(new TagValue("activeTimeEnd", endTime));

 

order.algoStrategy = "AD";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("componentSize", std::to_string(componentSize)));
TagValueSPtr tag2(new TagValue("timeBetweenOrders",std::to_string(timeBetweenOrders)));
TagValueSPtr tag3(new TagValue("randomizeTime20", randomizeTime20 ? "1" : "0"));
TagValueSPtr tag4(new TagValue("randomizeSize55", randomizeSize55 ? "1" : "0"));
TagValueSPtr tag5(new TagValue("giveUp", std::to_string(giveUp)));
TagValueSPtr tag6(new TagValue("catchUp", catchUp ? "1" : "0"));
TagValueSPtr tag7(new TagValue("waitForFill", waitForFill ? "1" : "0"));
TagValueSPtr tag8(new TagValue("activeTimeStart", startTime));
TagValueSPtr tag9(new TagValue("activeTimeEnd", endTime));

order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);
order.algoParams->push_back(tag6);
order.algoParams->push_back(tag7);
order.algoParams->push_back(tag8);
order.algoParams->push_back(tag9);

 

order.AlgoStrategy = "AD";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("componentSize", componentSize.ToString()));
order.AlgoParams.Add(new TagValue("timeBetweenOrders", timeBetweenOrders.ToString()));
order.AlgoParams.Add(new TagValue("randomizeTime20", randomizeTime20 ? "1" : "0"));
order.AlgoParams.Add(new TagValue("randomizeSize55", randomizeSize55 ? "1" : "0"));
order.AlgoParams.Add(new TagValue("giveUp", giveUp.ToString()));
order.AlgoParams.Add(new TagValue("catchUp", catchUp ? "1" : "0"));
order.AlgoParams.Add(new TagValue("waitForFill", waitForFill ? "1" : "0"));
order.AlgoParams.Add(new TagValue("activeTimeStart", startTime));
order.AlgoParams.Add(new TagValue("activeTimeEnd", endTime));

 

order.AlgoStrategy = "AD"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("componentSize", componentSize.ToString()))
order.AlgoParams.Add(New TagValue("timeBetweenOrders", timeBetweenOrders.ToString()))
order.AlgoParams.Add(New TagValue("randomizeTime20", BooleantoString(randomizeTime20)))
order.AlgoParams.Add(New TagValue("randomizeSize55", BooleantoString(randomizeSize55)))
order.AlgoParams.Add(New TagValue("giveUp", giveUp.ToString()))
order.AlgoParams.Add(New TagValue("catchUp", BooleantoString(catchUp)))
order.AlgoParams.Add(New TagValue("waitForFill", BooleantoString(waitForFill)))
order.AlgoParams.Add(New TagValue("activeTimeStart", startTime))
order.AlgoParams.Add(New TagValue("activeTimeEnd", endTime))

 

Accumulate/Distribute (Alt.)

The “AccuDistr” variant of the Accumulate/Distribute Algo is conceptually the same as the pre-existing “AD”. However, “AccuDistr” introduces the ability to close existing Trader Workstation sessions while still allowing the algo to continue working. In addition to the underlying behavior change, “AccuDistr” appears visually different while viewed from Trader Workstation, offering a new menu under the “IB ALGO” tab.

It is important to note that “AccuDistr” has removed the ability to use the “giveUp” field. As such, users who require “giveUp” for their strategy MUST continue utilizing the “AD” variant for the Accumulate/Distribute algo.

Algo Strategy Value: AccuDistr

componentSize: int. Quantity of increment.
Valid Value/Format: Cannot exceed initial size

timeBetweenOrders: int. Time interval in seconds between each order.
Valid Value/Format: 30

randomizeTime20: bool. Randomize time period by +/- 20%.
Valid Value/Format: 1 (true) or 0 (false)

randomizeSize55: bool. Randomize size by +/- 55%.
Valid Value/Format: 1 (true) or 0 (false)

catchUp: bool. Catch up in time.
Valid Value/Format: 1 (true) or 0 (false)

waitForFill: bool. Wait for current order to fill before submitting next order.
Valid Value/Format: 1 (true) or 0 (false)

activeTimeStart: String. Algorithm starting time.
Valid Value/Format: YYYYMMDD-hh:mm:ss TMZ

activeTimeEnd: String. Algorithm ending time.
Valid Value/Format: YYYYMMDD-hh:mm:ss TMZ

order.algoStrategy = "AccuDistr"
order.algoParams = []
order.algoParams.append(TagValue("componentSize", componentSize))
order.algoParams.append(TagValue("timeBetweenOrders", timeBetweenOrders))
order.algoParams.append(TagValue("randomizeTime20", int(randomizeTime20)))
order.algoParams.append(TagValue("randomizeSize55", int(randomizeSize55)))
order.algoParams.append(TagValue("catchUp", int(catchUp)))
order.algoParams.append(TagValue("waitForFill", int(waitForFill)))
order.algoParams.append(TagValue("activeTimeStart", startTime))
order.algoParams.append(TagValue("activeTimeEnd", endTime))

 

order.algoStrategy("AccuDistr");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("componentSize", String.valueOf(componentSize)));
order.algoParams().add(new TagValue("timeBetweenOrders", String.valueOf(timeBetweenOrders)));
order.algoParams().add(new TagValue("randomizeTime20", randomizeTime20 ? "1" : "0"));
order.algoParams().add(new TagValue("randomizeSize55", randomizeSize55 ? "1" : "0"));
order.algoParams().add(new TagValue("catchUp", catchUp ? "1" : "0"));
order.algoParams().add(new TagValue("waitForFill", waitForFill ? "1" : "0"));
order.algoParams().add(new TagValue("activeTimeStart", startTime));
order.algoParams().add(new TagValue("activeTimeEnd", endTime));

 

order.algoStrategy = "AccuDistr";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("componentSize", std::to_string(componentSize)));
TagValueSPtr tag2(new TagValue("timeBetweenOrders",std::to_string(timeBetweenOrders)));
TagValueSPtr tag3(new TagValue("randomizeTime20", randomizeTime20 ? "1" : "0"));
TagValueSPtr tag4(new TagValue("randomizeSize55", randomizeSize55 ? "1" : "0"));
TagValueSPtr tag5(new TagValue("giveUp", std::to_string(catchUp)));
TagValueSPtr tag6(new TagValue("waitForFill", waitForFill ? "1" : "0"));
TagValueSPtr tag7(new TagValue("activeTimeStart", startTime));
TagValueSPtr tag8(new TagValue("activeTimeEnd", endTime));

order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);
order.algoParams->push_back(tag6);
order.algoParams->push_back(tag7);
order.algoParams->push_back(tag8);

 

order.AlgoStrategy = "AccuDistr";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("componentSize", componentSize.ToString()));
order.AlgoParams.Add(new TagValue("timeBetweenOrders", timeBetweenOrders.ToString()));
order.AlgoParams.Add(new TagValue("randomizeTime20", randomizeTime20 ? "1" : "0"));
order.AlgoParams.Add(new TagValue("randomizeSize55", randomizeSize55 ? "1" : "0"));
order.AlgoParams.Add(new TagValue("catchUp", catchUp ? "1" : "0"));
order.AlgoParams.Add(new TagValue("waitForFill", waitForFill ? "1" : "0"));
order.AlgoParams.Add(new TagValue("activeTimeStart", startTime));
order.AlgoParams.Add(new TagValue("activeTimeEnd", endTime));

 

order.AlgoStrategy = "AccuDistr"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("componentSize", componentSize.ToString()))
order.AlgoParams.Add(New TagValue("timeBetweenOrders", timeBetweenOrders.ToString()))
order.AlgoParams.Add(New TagValue("randomizeTime20", BooleantoString(randomizeTime20)))
order.AlgoParams.Add(New TagValue("randomizeSize55", BooleantoString(randomizeSize55)))
order.AlgoParams.Add(New TagValue("catchUp", BooleantoString(catchUp)))
order.AlgoParams.Add(New TagValue("waitForFill", BooleantoString(waitForFill)))
order.AlgoParams.Add(New TagValue("activeTimeStart", startTime))
order.AlgoParams.Add(New TagValue("activeTimeEnd", endTime))

 

Adaptive Algo

The Adaptive Algo combines IB’s Smart routing capabilities with user-defined priority settings in an effort to achieve further cost efficiency at the point of execution. Using the Adaptive algo leads to better execution prices on average than for regular limit or market orders.

Algo Strategy Value: Adaptive

adaptivePriority: String. The ‘Priority’ selector determines the time taken to scan for better execution prices. The ‘Urgent’ setting scans only briefly, while the ‘Patient’ scan works more slowly and has a higher chance of achieving a better overall fill for your order.
Valid Value/Format: Urgent > Normal > Patient

order.algoStrategy = "Adaptive"
order.algoParams = []
order.algoParams.append(TagValue("adaptivePriority", priority))

 

order.algoStrategy("Adaptive");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("adaptivePriority", priority));

 

order.algoStrategy = "Adaptive";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("adaptivePriority", priority));
order.algoParams->push_back(tag1);

 

order.AlgoStrategy = "Adaptive";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("adaptivePriority", priority));

 

order.AlgoStrategy = "Adaptive"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("adaptivePriority", priority))

 

ArrivalPrice

The Arrival Price algorithmic order type will attempt to achieve, over the course of the order, the bid/ask midpoint at the time the order is submitted. The Arrival Price algo is designed to keep hidden orders that will impact a high percentage of the average daily volume (ADV). The pace of execution is determined by the user-assigned level of risk aversion and the user-defined target percent of average daily volume. How quickly the order is submitted during the day is determined by the level of urgency: the higher the urgency the faster it will execute but will expose it to a greater market impact. Market impact can be lessened by assigning lesser urgency, which is likely to lengthen the duration of the order. The user can set the max percent of ADV from 1 to 50%. The order entry screen allows the user to determine when the order will start and end regardless of whether or not the full amount of the order has been filled. By checking the box marked Allow trading past end time the algo will continue to work past the specified end time in an effort to fill the remaining portion of the order.

Algo Strategy Value: ArrivalPx

maxPctVol: double. Maximum percentage of ADV
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

riskAversion: String. Urgency/risk aversion
Valid Value/Format: Get Done, Aggressive, Neutral, Passive

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

allowPastEndTime: bool. Allow trading past end time
Valid Value/Format: 1 (true) or 0 (false)

forceCompletion: bool. Attempt completion by the end of the day
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "ArrivalPx"
order.algoParams = []
order.algoParams.append(TagValue("maxPctVol", maxPctVol))
order.algoParams.append(TagValue("riskAversion", riskAversion))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("forceCompletion", int(forceCompletion)))
order.algoParams.append(TagValue("allowPastEndTime", int(allowPastTime)))

 

order.algoStrategy("ArrivalPx");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("maxPctVol", String.valueOf(maxPctVol)));
order.algoParams().add(new TagValue("riskAversion", riskAversion));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));
order.algoParams().add(new TagValue("allowPastEndTime", allowPastTime ? "1" : "0"));

 

order.algoStrategy = "ArrivalPx";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("maxPctVol", std::to_string(maxPctVol)));
TagValueSPtr tag2(new TagValue("riskAversion", riskAversion));
TagValueSPtr tag3(new TagValue("startTime", startTime));
TagValueSPtr tag4(new TagValue("endTime", endTime));
TagValueSPtr tag5(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));
TagValueSPtr tag6(new TagValue("allowPastEndTime", allowPastTime ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);
order.algoParams->push_back(tag6);

 

order.AlgoStrategy = "ArrivalPx";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("maxPctVol", maxPctVol.ToString()));
order.AlgoParams.Add(new TagValue("riskAversion", riskAversion));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));
order.AlgoParams.Add(new TagValue("allowPastEndTime", allowPastTime ? "1" : "0"));

 

order.AlgoStrategy = "ArrivalPx"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("maxPctVol", maxPctVol.ToString()))
order.AlgoParams.Add(New TagValue("riskAversion", riskAversion))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("forceCompletion", BooleantoString(forceCompletion)))
order.AlgoParams.Add(New TagValue("allowPastEndTime", BooleantoString(allowPastTime)))

 

Balance Impact Risk

The Balance Impact Risk balances the market impact of trading the option with the risk of price change over the time horizon of the order. This strategy considers the user-assigned level of risk aversion to define the pace of the execution, along with the user-defined target percent of volume.

Algo Strategy Value: BalanceImpactRisk

maxPctVol: double. Maximum percentage of ADV
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

riskAversion: String. Urgency/risk aversion
Valid Value/Format: Get Done, Aggressive, Neutral, Passive

forceCompletion: bool. Attempt completion by the end of the day
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "BalanceImpactRisk"
order.algoParams = []
order.algoParams.append(TagValue("maxPctVol", maxPctVol))
order.algoParams.append(TagValue("riskAversion", riskAversion))
order.algoParams.append(TagValue("forceCompletion", int(forceCompletion)))

 

order.algoStrategy("BalanceImpactRisk");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("maxPctVol", String.valueOf(maxPctVol)));
order.algoParams().add(new TagValue("riskAversion", riskAversion));
order.algoParams().add(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));

 

order.algoStrategy = "BalanceImpactRisk";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("maxPctVol", std::to_string(maxPctVol)));
TagValueSPtr tag2(new TagValue("riskAversion", riskAversion));
TagValueSPtr tag3(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);

 

order.AlgoStrategy = "BalanceImpactRisk";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("maxPctVol", maxPctVol.ToString()));
order.AlgoParams.Add(new TagValue("riskAversion", riskAversion));
order.AlgoParams.Add(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));

 

order.AlgoStrategy = "BalanceImpactRisk"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("maxPctVol", maxPctVol.ToString()))
order.AlgoParams.Add(New TagValue("riskAversion", riskAversion))
order.AlgoParams.Add(New TagValue("forceCompletion", BooleantoString(forceCompletion)))

 

Close Price

Investors submitting market or limit orders into the closing auction may adversely affect the closing price, especially when the size of the order is large relative to the average close auction volume. In order to help investors attempting to execute towards the end of the trading session we have developed the Close Price algo Strategy. This algo breaks down large order amounts and determines the timing of order entry so that it will continuously execute in order to minimize slippage. The start and pace of execution are determined by the user who assigns a level of market risk and specifies the target percentage of volume, while the algo considers the prior volatility of the stock.

Algo Strategy Value: ClosePx

maxPctVol: double. Maximum percentage of ADV
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

riskAversion: String. Urgency/risk aversion
Valid Value/Format: Get Done, Aggressive, Neutral, Passive

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

forceCompletion: bool. Attempt completion by the end of the day
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "ClosePx"
order.algoParams = []
order.algoParams.append(TagValue("maxPctVol", maxPctVol))
order.algoParams.append(TagValue("riskAversion", riskAversion))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("forceCompletion", int(forceCompletion)))

 

order.algoStrategy("ClosePx");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("maxPctVol", String.valueOf(maxPctVol)));
order.algoParams().add(new TagValue("riskAversion", riskAversion));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));

 

order.algoStrategy = "ClosePx";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("maxPctVol", std::to_string(maxPctVol)));
TagValueSPtr tag2(new TagValue("riskAversion",riskAversion));
TagValueSPtr tag3(new TagValue("startTime", startTime));
TagValueSPtr tag4(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);

 

order.AlgoStrategy = "ClosePx";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("maxPctVol", maxPctVol.ToString()));
order.AlgoParams.Add(new TagValue("riskAversion", riskAversion));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("forceCompletion", forceCompletion ? "1" : "0"));

 

order.AlgoStrategy = "ClosePx"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("maxPctVol", maxPctVol.ToString()))
order.AlgoParams.Add(New TagValue("riskAversion", riskAversion))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("forceCompletion", BooleantoString(forceCompletion)))

 

DarkIce

The Dark Ice order type develops the concept of privacy adopted by orders such as Iceberg or Reserve, using a proprietary algorithm to further hide the volume displayed to the market by the order. Clients can determine the timeframe an order remains live and have the option to allow trading past end time in the event it is unfilled by the stated end time. In order to minimize market impact in the event of large orders, users can specify a display size to be shown to the market different from the actual order size. Additionally, the Dark Ice algo randomizes the display size +/- 50% based upon the probability of the price moving favorably. Further, using calculated probabilities, the algo decides whether to place the order at the limit price or one tick lower than the current offer for buy orders and one tick higher than the current bid for sell orders.

Algo Strategy Value: DarkIce

displaySize: double. Order size to be displayed
Valid Value/Format: 100

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

allowPastEndTime: bool. Allow trading past end time
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "DarkIce"
order.algoParams = []
order.algoParams.append(TagValue("displaySize", displaySize))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("allowPastEndTime", int(allowPastEndTime)))

 

order.algoStrategy("DarkIce");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("displaySize", String.valueOf(displaySize)));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));

 

order.algoStrategy = "DarkIce";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("displaySize", std::to_string(displaySize)));
TagValueSPtr tag2(new TagValue("startTime", startTime));
TagValueSPtr tag3(new TagValue("endTime", endTime));
TagValueSPtr tag4(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);

 

order.AlgoStrategy = "DarkIce";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("displaySize", displaySize.ToString()));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));

 

order.AlgoStrategy = "DarkIce"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("displaySize", displaySize.ToString()))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("allowPastEndTime", BooleantoString(allowPastEndTime)))

 

Midprice

Midprice order is designed to split the difference between the bid and ask prices, and fill at the current midpoint of the NBBO or better. Set an optional price cap to define the highest price (for a buy order) or the lowest price (for a sell order) you are willing to accept. Smart-routing to US stocks only.

  • Products: US STK
  • Exchanges: Smart-routing only

Set OrderType to “MIDPRICE”.

No algo params or strategy required.

order = Order()
order.action = action
order.orderType = "MIDPRICE"
order.totalQuantity = quantity
order.lmtPrice = priceCap

 

curl --insecure https://localhost:5000/v1/api/iserver/account/{{accountId}}/orders 
--request POST 
--header 'Content-Type:application/json' 
--data '{
    "orders":[
        {
            "conid": {{ conid }},
            "orderType": "MIDPRICE",
            "price": {{ price }},
            "quantity": {{ quantity }},
            "side": {{ side }},
            "tif": {{ tif }}
        }
    ]
}'

For the Client Portal API, a price must be included. If no price cap is desired, ‘”price”: 0’ should be included.

Order order = new Order();
order.action(action);
order.orderType("MIDPRICE");
order.totalQuantity(quantity);
order.lmtPrice(priceCap); 

 

Order order;
order.action = action;
order.orderType = "MIDPRICE";
order.totalQuantity = quantity;
order.lmtPrice = priceCap; 

 

Order order = new Order();
order.Action = action;
order.OrderType = "MIDPRICE";
order.TotalQuantity = quantity;
order.LmtPrice = priceCap;

 

Dim order As Order = New Order
order.Action = action
order.OrderType = "MIDPRICE"
order.TotalQuantity = quantity
order.LmtPrice = priceCap  ' optional

 

Minimise Impact

The Minimise Impact algo minimises market impact by slicing the order over time to achieve a market average without going over the given maximum percentage value.

Algo Strategy Value: MinImpact

maxPctVol: double. Maximum percentage of ADV
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

order.algoStrategy = "MinImpact"
order.algoParams = []
order.algoParams.append(TagValue("maxPctVol", maxPctVol))

 

order.algoStrategy("BalanceImpactRisk");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("maxPctVol", String.valueOf(maxPctVol)));

 

order.algoStrategy = "MinImpact";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("maxPctVol", std::to_string(maxPctVol)));
order.algoParams->push_back(tag1);

 

order.AlgoStrategy = "MinImpact";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("maxPctVol", maxPctVol.ToString()));

 

order.AlgoStrategy = "MinImpact"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("maxPctVol", maxPctVol.ToString()))

 

Percentage of Volume

The Percent of Volume algo can limit the contribution of orders to overall average daily volume in order to minimize impact. Clients can set a value between 1-50% to control their participation between stated start and end times. Order quantity and volume distribution over the day is determined using the target percent of volume you entered along with continuously updated volume forecasts calculated from TWS market data. In addition, the algo can be set to avoid taking liquidity, which may help avoid liquidity-taker fees and could result in liquidity-adding rebates. By checking the Attempt to never take liquidity box, the algo is discouraged from hitting the bid or lifting the offer if possible. However, this may also result in greater deviations from the benchmark, and in partial fills, since the posted bid/offer may not always get hit as the price moves up/down. IB will use best efforts not to take liquidity when this box is checked, however, there will be times that it cannot be avoided.

Algo Strategy Value: PctVol

pctVol: double. Total percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

noTakeLiq: bool. Attempt to never take liquidity
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "PctVol"
order.algoParams = []
order.algoParams.append(TagValue("pctVol", pctVol))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("noTakeLiq", int(noTakeLiq)))

 

order.algoStrategy("PctVol");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("pctVol", String.valueOf(pctVol)));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.algoStrategy = "PctVol";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("pctVol", std::to_string(pctVol)));
TagValueSPtr tag2(new TagValue("startTime", startTime));
TagValueSPtr tag3(new TagValue("endTime", endTime));
TagValueSPtr tag4(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);

 

order.AlgoStrategy = "PctVol";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("pctVol", pctVol.ToString()));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.AlgoStrategy = "PctVol"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("pctVol", pctVol.ToString()))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("noTakeLiq", BooleantoString(noTakeLiq)))

 

Price Variant Percentage

Price Variant Percentage of Volume Strategy – This algo allows you to participate in volume at a user-defined rate that varies over time depending on the market price of the security. This algo allows you to buy more aggressively when the price is low and be more passive as the price increases, and just the opposite for sell orders. The order quantity and volume distribution over the time during which the order is active is determined using the target percent of volume you entered along with continuously updated volume forecasts calculated from TWS market data.

Algo Strategy Value: PctVolPx

pctVol: double. Total percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

deltaPctVol: double. Target Percentage Change Rate
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

minPctVol4Px: double. Minimum Target Percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

maxPctVol4Px: double. Maximum Target Percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

noTakeLiq: bool. Attempt to never take liquidity
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "PctVolPx"
order.algoParams = []
order.algoParams.append(TagValue("pctVol", pctVol))
order.algoParams.append(TagValue("deltaPctVol", deltaPctVol))
order.algoParams.append(TagValue("minPctVol4Px", minPctVol4Px))
order.algoParams.append(TagValue("maxPctVol4Px", maxPctVol4Px))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("noTakeLiq", int(noTakeLiq)))

 

order.algoStrategy("PctVolPx");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("pctVol", String.valueOf(pctVol)));
order.algoParams().add(new TagValue("deltaPctVol", String.valueOf(deltaPctVol)));
order.algoParams().add(new TagValue("minPctVol4Px", String.valueOf(minPctVol4Px)));
order.algoParams().add(new TagValue("maxPctVol4Px", String.valueOf(maxPctVol4Px)));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.algoStrategy = "PctVolPx";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("pctVol", std::to_string(pctVol)));
TagValueSPtr tag2(new TagValue("deltaPctVol", std::to_string(deltaPctVol)));
TagValueSPtr tag3(new TagValue("minPctVol4Px", std::to_string(minPctVol4Px)));
TagValueSPtr tag4(new TagValue("maxPctVol4Px", std::to_string(maxPctVol4Px)));
TagValueSPtr tag5(new TagValue("startTime", startTime));
TagValueSPtr tag6(new TagValue("endTime", endTime));
TagValueSPtr tag7(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);
order.algoParams->push_back(tag6);
order.algoParams->push_back(tag7);

 

order.AlgoStrategy = "PctVolPx";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("pctVol", pctVol.ToString()));
order.AlgoParams.Add(new TagValue("deltaPctVol", deltaPctVol.ToString()));
order.AlgoParams.Add(new TagValue("minPctVol4Px", minPctVol4Px.ToString()));
order.AlgoParams.Add(new TagValue("maxPctVol4Px", maxPctVol4Px.ToString()));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.AlgoStrategy = "PctVolPx"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("pctVol", pctVol.ToString()))
order.AlgoParams.Add(New TagValue("deltaPctVol", deltaPctVol.ToString()))
order.AlgoParams.Add(New TagValue("minPctVol4Px", minPctVol4Px.ToString()))
order.AlgoParams.Add(New TagValue("maxPctVol4Px", maxPctVol4Px.ToString()))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("noTakeLiq", BooleantoString(noTakeLiq)))

 

Size Variant Percentage

Size Variant Percentage of Volume Strategy – This algo allows you to participate in volume at a user-defined rate that varies over time depending on the remaining size of the order. Define the target percent rate at the start time (Initial Participation Rate) and at the end time (Terminal Participation Rate), and the algo calculates the participation rate over time between the two based on the remaining order size. This allows the order to be more aggressive initially and less aggressive toward the end, or vice versa.

Algo Strategy Value: PctVolSz

startPctVol: double. Initial Target Percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

endPctVol: double. Terminal Target Percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

noTakeLiq: bool. Attempt to never take liquidity
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "PctVolSz"
order.algoParams = []
order.algoParams.append(TagValue("startPctVol", startPctVol))
order.algoParams.append(TagValue("endPctVol", endPctVol))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("noTakeLiq", int(noTakeLiq)))

 

order.algoStrategy("PctVolSz");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("startPctVol", String.valueOf(startPctVol)));
order.algoParams().add(new TagValue("endPctVol", String.valueOf(endPctVol)));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.algoStrategy = "PctVolSz";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("startPctVol", std::to_string(startPctVol)));
TagValueSPtr tag2(new TagValue("endPctVol", std::to_string(endPctVol)));
TagValueSPtr tag3(new TagValue("startTime", startTime));
TagValueSPtr tag4(new TagValue("endTime", endTime));
TagValueSPtr tag5(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);

 

order.AlgoStrategy = "PctVolSz";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("startPctVol", startPctVol.ToString()));
order.AlgoParams.Add(new TagValue("endPctVol", endPctVol.ToString()));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.AlgoStrategy = "PctVolSz"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("startPctVol", startPctVol.ToString()))
order.AlgoParams.Add(New TagValue("endPctVol", endPctVol.ToString()))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("noTakeLiq", BooleantoString(noTakeLiq)))

 

Time Variant Percentage

Time Variant Percentage of Volume Strategy – This algo allows you to participate in volume at a user-defined rate that varies with time. Define the target percent rate at the start time and at the end time, and the algo calculates the participation rate over time between the two. This allows the order to be more aggressive initially and less aggressive toward the end, or vice versa.

Algo Strategy Value: PctVolTm

startPctVol: double. Initial Target Percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

endPctVol: double. Terminal Target Percentage
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

noTakeLiq: bool. Attempt to never take liquidity
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "PctVolTm"
order.algoParams = []
order.algoParams.append(TagValue("startPctVol", startPctVol))
order.algoParams.append(TagValue("endPctVol", endPctVol))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("noTakeLiq", int(noTakeLiq)))

 

order.algoStrategy("PctVolTm");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("startPctVol", String.valueOf(startPctVol)));
order.algoParams().add(new TagValue("endPctVol", String.valueOf(endPctVol)));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.algoStrategy = "PctVolTm";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("startPctVol", std::to_string(startPctVol)));
TagValueSPtr tag2(new TagValue("endPctVol", std::to_string(endPctVol)));
TagValueSPtr tag3(new TagValue("startTime", startTime));
TagValueSPtr tag4(new TagValue("endTime", endTime));
TagValueSPtr tag5(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);

 

order.AlgoStrategy = "PctVolTm";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("startPctVol", startPctVol.ToString()));
order.AlgoParams.Add(new TagValue("endPctVol", endPctVol.ToString()));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));

 

order.AlgoStrategy = "PctVolTm"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("startPctVol", startPctVol.ToString()))
order.AlgoParams.Add(New TagValue("endPctVol", endPctVol.ToString()))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("noTakeLiq", BooleantoString(noTakeLiq)))

 

TWAP

The TWAP algo aims to achieve the time-weighted average price calculated from the time you submit the order to the time it completes. Incomplete orders at the end of the stated completion time will continue to fill if the box ‘allow trading past end time’ is checked. Users can set the order to trade only when specified conditions are met. Those user-defined inputs include when the order is marketable, when the midpoint matches the required price, when the same side (buy or sell) matches to make the order marketable or when the last traded price would make the order marketable. For the TWAP algo, the average price calculation is calculated from the order entry time through the close of the market and will only attempt to execute when the criterion is met. The order may not fill throughout its stated duration and so the order is not guaranteed. TWAP is available for all US equities.

Algo Strategy Value: Twap

strategyType: String. Trade strategy
Valid Value/Format: Marketable, Matching, Midpoint, Matching Same Side, Matching Last

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

allowPastEndTime: bool. Allow trading past end time
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "Twap"
order.algoParams = []
order.algoParams.append(TagValue("strategyType", strategyType))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("allowPastEndTime", int(allowPastEndTime)))

 

order.algoStrategy("Twap");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("strategyType", strategyType));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));

 

order.algoStrategy = "Twap";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("strategyType", strategyType));
TagValueSPtr tag2(new TagValue("startTime", startTime));
TagValueSPtr tag3(new TagValue("endTime", endTime));
TagValueSPtr tag4(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);

 

order.AlgoStrategy = "Twap";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("strategyType", strategyType));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));

 

order.AlgoStrategy = "Twap"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("strategyType", strategyType))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("allowPastEndTime", BooleantoString(allowPastEndTime)))

 

VWAP

IB’s best-efforts VWAP algo seeks to achieve the Volume-Weighted Average price (VWAP), calculated from the time you submit the order to the close of the market.

Best-efforts VWAP algo is a lower-cost alternative to the Guaranteed VWAP (no longer supported) that enables the user to attempt never to take liquidity while also trading past the end time. Because the order may not be filled on the bid or at the ask prices, there is a trade-off with this algo. The order may not fully fill if the user is attempting to avoid liquidity-taking fees and/or maximize liquidity-adding rebates, and may miss the benchmark by asking to stay on the bid or ask. The user can determine the maximum percentage of average daily volume (up to 50%) his order will comprise. The system will generate the VWAP from the time the order is entered through the close of trading, and the order can be limited to trading over a pre-determined period. The user can request the order to continue beyond its stated end time if unfilled at the end of the stated period. The best-efforts VWAP algo is available for all US equities.

Algo Strategy Value: Vwap

maxPctVol: double. Maximum percentage of ADV
Valid Value/Format: 0.1 (10%) – 0.5 (50%)

startTime: String. Algorithm starting time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

endTime: String. Algorithm ending time
Valid Value/Format: hh:mm:ss TMZ or YYYYMMDD-hh:mm:ss TMZ

allowPastEndTime: bool. Allow trading past end time
Valid Value/Format: 1 (true) or 0 (false)

noTakeLiq: bool. Attempt to never take liquidity
Valid Value/Format: 1 (true) or 0 (false)

speedUp: bool. Compensate for the decreased fill rate due to presence of limit price.
Valid Value/Format: 1 (true) or 0 (false)

order.algoStrategy = "Vwap"
order.algoParams = []
order.algoParams.append(TagValue("maxPctVol", maxPctVol))
order.algoParams.append(TagValue("startTime", startTime))
order.algoParams.append(TagValue("endTime", endTime))
order.algoParams.append(TagValue("allowPastEndTime", int(allowPastEndTime)))
order.algoParams.append(TagValue("noTakeLiq", int(noTakeLiq)))

 

order.algoStrategy("Vwap");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("maxPctVol", String.valueOf(maxPctVol)));
order.algoParams().add(new TagValue("startTime", startTime));
order.algoParams().add(new TagValue("endTime", endTime));
order.algoParams().add(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));
order.algoParams().add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));
order.algoParams().add(new TagValue("speedUp", speedUp ? "1" : "0"));

 

order.algoStrategy = "Vwap";
order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("maxPctVol", std::to_string(maxPctVol)));
TagValueSPtr tag2(new TagValue("startTime", startTime));
TagValueSPtr tag3(new TagValue("endTime", endTime));
TagValueSPtr tag4(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));
TagValueSPtr tag5(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));
TagValueSPtr tag6(new TagValue("speedUp", speedUp ? "1" : "0"));
order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);
order.algoParams->push_back(tag6);

 

order.AlgoStrategy = "Vwap";
order.AlgoParams = new List();
order.AlgoParams.Add(new TagValue("maxPctVol", maxPctVol.ToString()));
order.AlgoParams.Add(new TagValue("startTime", startTime));
order.AlgoParams.Add(new TagValue("endTime", endTime));
order.AlgoParams.Add(new TagValue("allowPastEndTime", allowPastEndTime ? "1" : "0"));
order.AlgoParams.Add(new TagValue("noTakeLiq", noTakeLiq ? "1" : "0"));
order.AlgoParams.Add(new TagValue("speedUp", speedUp ? "1" : "0"));

 

order.AlgoStrategy = "Vwap"
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(New TagValue("maxPctVol", maxPctVol.ToString()))
order.AlgoParams.Add(New TagValue("startTime", startTime))
order.AlgoParams.Add(New TagValue("endTime", endTime))
order.AlgoParams.Add(New TagValue("allowPastEndTime", BooleantoString(allowPastEndTime)))
order.AlgoParams.Add(New TagValue("noTakeLiq", BooleantoString(noTakeLiq)))
order.AlgoParams.Add(New TagValue("speedUp", BooleantoString(speedUp)))

 

Quantitative Brokers Algorithms

It is recommended to first try to create the QBAlgo in TWS to see the most current available field values.

QBAlgos are only available in live accounts.

Some fields have default values and are optional in TWS but must be explicitly specified in the API.

Bolt

Algo Strategy Value: Bolt

StartTime: String. Start Time.
Valid Value/Format: hh:mm:ss tmz

EndTime: String.Must be on the same date as Start Time. Takes precedence over Duration.
Valid Value/Format: hh:mm:ss tmz

Duration: double. Alternative order end time specifier. This value is a number of minutes that the order should be worked.
Valid Value/Format: 10. A value of -99 will specify that the end time should be the exchange close time.

Mode: String. Mode
Valid Value/Format: Passive, Normal, Aggressive

PercentVolume: double. Volume %
Valid Value/Format: 0 <= PercentVolume <= 1

EventPause: String. Event Pause
Valid Value/Format: Attempt_To_Complete, Pause_Trading, Trade_Through

NoCleanup: bool. No Cleanup
Valid Value/Format: “0” (false) or “1” (true)

LiquidityAggressThreshold: double. Liquidity Aggressiveness Threshold
Valid Value/Format: 0 <= LiquidityAggressThreshold <= 1

order.algoStrategy = "Bolt"
order.algoParams = []
order.algoParams.append(TagValue("StartTime", StartTime))
order.algoParams.append(TagValue("EndTime", EndTime))
order.algoParams.append(TagValue("Duration", Duration))
order.algoParams.append(TagValue("Mode", Mode))
order.algoParams.append(TagValue("PercentVolume", PercentVolume))
order.algoParams.append(TagValue("EventPause", EventPause))
order.algoParams.append(TagValue("NoCleanup", NoCleanup))
order.algoParams.append(TagValue("LiquidityAggressThreshold", liqAggThreshold))

 

order.algoStrategy("Bolt");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("StartTime", startTime));
order.algoParams().add(new TagValue("EndTime", endTime));
order.algoParams().add(new TagValue("Duration", Duration));
order.algoParams().add(new TagValue("Mode", Mode));
order.algoParams().add(new TagValue("PercentVolume", PercentVolume));
order.algoParams().add(new TagValue("EventPause", EventPause));
order.algoParams().add(new TagValue("NoCleanup", NoCleanup));
order.algoParams().add(new TagValue("LiquidityAggressThreshold", liqAggThreshold));

 

order.algoStrategy = "Bolt";

order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("StartTime", StartTime));
TagValueSPtr tag2(new TagValue("EndTime", endTime));
TagValueSPtr tag3(new TagValue("Duration", Duration));
TagValueSPtr tag4(new TagValue("Mode", std::to_string(Mode)));
TagValueSPtr tag5(new TagValue("PercentVolume", std::to_string(PercentVolume)));
TagValueSPtr tag6(new TagValue("EventPause", std::to_string(EventPause)));
TagValueSPtr tag7(new TagValue("NoCleanup", std::to_string(NoCleanup)));
TagValueSPtr tag8(new TagValue("LiquidityAggressThreshold", std::to_string(LiquidityAggressThreshold)));

order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);
order.algoParams->push_back(tag6);
order.algoParams->push_back(tag7);
order.algoParams->push_back(tag8);

 

order.AlgoStrategy("Bolt");
order.AlgoParams(new ArrayList());
order.AlgoParams.Add(new TagValue("StartTime", startTime));
order.AlgoParams.Add(new TagValue("EndTime", endTime));
order.AlgoParams.Add(new TagValue("Duration", Duration));
order.AlgoParams.Add(new TagValue("Mode", Mode));
order.AlgoParams.Add(new TagValue("PercentVolume", PercentVolume));
order.AlgoParams.Add(new TagValue("EventPause", EventPause));
order.AlgoParams.Add(new TagValue("NoCleanup", NoCleanup));
order.AlgoParams.Add(new TagValue("LiquidityAggressThreshold", liqAggThreshold));

 

order.AlgoStrategy("Bolt");
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(new TagValue("StartTime", startTime))
order.AlgoParams.Add(new TagValue("EndTime", endTime))
order.AlgoParams.Add(new TagValue("Duration", Duration))
order.AlgoParams.Add(new TagValue("Mode", Mode))
order.AlgoParams.Add(new TagValue("PercentVolume", PercentVolume))
order.AlgoParams.Add(new TagValue("EventPause", EventPause))
order.AlgoParams.Add(new TagValue("NoCleanup", NoCleanup))
order.AlgoParams.Add(new TagValue("LiquidityAggressThreshold", liqAggThreshold))

 

Closer

Algo Strategy Value: Closer

No parameters should be attached. Only the strategy needs to be specified as Closer.

order.algoStrategy = "Closer"

 

order.algoStrategy("Closer");

 

order.algoStrategy = "Closer";

 

order.AlgoStrategy = "Closer";

 

order.AlgoStrategy = "Closer"

 

Octane

Algo Strategy Value: Octane

StartTime: String. Start Time.
Valid Value/Format: hh:mm:ss tmz

EndTime: String.Must be on the same date as Start Time. Takes precedence over Duration.
Valid Value/Format: hh:mm:ss tmz

Duration: double. Alternative order end time specifier. This value is a number of minutes that the order should be worked.
Valid Value/Format: 10. A value of -99 will specify that the end time should be the exchange close time.

Urgency: String. Fill urgency
Valid Value/Format: High, Ultra_High

order.algoStrategy = "Octane"
order.algoParams = []
order.algoParams.append(TagValue("StartTime", StartTime))
order.algoParams.append(TagValue("EndTime", EndTime))
order.algoParams.append(TagValue("Duration", Duration))
order.algoParams.append(TagValue("Urgency", Urgency))

 

order.algoStrategy("Octane");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("StartTime", startTime));
order.algoParams().add(new TagValue("EndTime", endTime));
order.algoParams().add(new TagValue("Duration", Duration));
order.algoParams().add(new TagValue("Urgency", Urgency));

 

order.algoStrategy = "Octane";

order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("StartTime", StartTime));
TagValueSPtr tag2(new TagValue("EndTime", endTime));
TagValueSPtr tag3(new TagValue("Duration", Duration));
TagValueSPtr tag4(new TagValue("Urgency", std::to_string(Urgency)));

order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);

 

order.AlgoStrategy("Octane");
order.AlgoParams(new ArrayList());
order.AlgoParams.Add(new TagValue("StartTime", startTime));
order.AlgoParams.Add(new TagValue("EndTime", endTime));
order.AlgoParams.Add(new TagValue("Duration", Duration));
order.AlgoParams.Add(new TagValue("Urgency", Urgency));

 

order.AlgoStrategy("Octane");
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(new TagValue("StartTime", startTime))
order.AlgoParams.Add(new TagValue("EndTime", endTime))
order.AlgoParams.Add(new TagValue("Duration", Duration))
order.AlgoParams.Add(new TagValue("Urgency", Urgency))

 

Strobe

Algo Strategy Value: Strobe

StartTime: String. Start Time.
Valid Value/Format: hh:mm:ss tmz

EndTime: String.Must be on the same date as Start Time. Takes precedence over Duration.
Valid Value/Format: hh:mm:ss tmz

Duration: double. Alternative order end time specifier. This value is a number of minutes that the order should be worked.
Valid Value/Format: 10. A value of -99 will specify that the end time should be the exchange close time.

Benchmark: String. Benchmark
Valid Value/Format: TWAP, VWAP

PercentVolume: double. Volume %
Valid Value/Format: 0 <= PercentVolume <= 1

NoCleanup: bool. No Cleanup
Valid Value/Format: “0” (false) or “1” (true)

order.algoStrategy = "Strobe"
order.algoParams = []
order.algoParams.append(TagValue("StartTime", StartTime))
order.algoParams.append(TagValue("EndTime", EndTime))
order.algoParams.append(TagValue("Duration", Duration))
order.algoParams.append(TagValue("Benchmark", Benchmark))
order.algoParams.append(TagValue("PercentVolume", PercentVolume))
order.algoParams.append(TagValue("NoCleanup", NoCleanup))

 

order.algoStrategy("Strobe");
order.algoParams(new ArrayList());
order.algoParams().add(new TagValue("StartTime", startTime));
order.algoParams().add(new TagValue("EndTime", endTime));
order.algoParams().add(new TagValue("Duration", Duration));
order.algoParams().add(new TagValue("Benchmark", Benchmark));
order.algoParams().add(new TagValue("PercentVolume", PercentVolume));
order.algoParams().add(new TagValue("NoCleanup", NoCleanup));

 

order.algoStrategy = "Strobe";

order.algoParams.reset(new TagValueList());
TagValueSPtr tag1(new TagValue("StartTime", StartTime));
TagValueSPtr tag2(new TagValue("EndTime", endTime));
TagValueSPtr tag3(new TagValue("Duration", Duration));
TagValueSPtr tag4(new TagValue("Benchmark", std::to_string(Benchmark)));
TagValueSPtr tag5(new TagValue("PercentVolume", std::to_string(PercentVolume)));
TagValueSPtr tag6(new TagValue("NoCleanup", std::to_string(NoCleanup)));

order.algoParams->push_back(tag1);
order.algoParams->push_back(tag2);
order.algoParams->push_back(tag3);
order.algoParams->push_back(tag4);
order.algoParams->push_back(tag5);
order.algoParams->push_back(tag6);

 

order.AlgoStrategy("Strobe");
order.AlgoParams(new ArrayList());
order.AlgoParams.Add(new TagValue("StartTime", startTime));
order.AlgoParams.Add(new TagValue("EndTime", endTime));
order.AlgoParams.Add(new TagValue("Duration", Duration));
order.AlgoParams.Add(new TagValue("Benchmark", Benchmark));
order.AlgoParams.Add(new TagValue("PercentVolume", PercentVolume));
order.AlgoParams.Add(new TagValue("NoCleanup", NoCleanup));

 

order.AlgoStrategy("Strobe");
order.AlgoParams = New List(Of TagValue)
order.AlgoParams.Add(new TagValue("StartTime", startTime))
order.AlgoParams.Add(new TagValue("EndTime", endTime))
order.AlgoParams.Add(new TagValue("Duration", Duration))
order.AlgoParams.Add(new TagValue("Benchmark", Benchmark))
order.AlgoParams.Add(new TagValue("PercentVolume", PercentVolume))
order.AlgoParams.Add(new TagValue("NoCleanup", NoCleanup))

 

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.