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.

How to Code an IB Algo Order in the Web API

API

Interactive Brokers offers several algorithmic order types that are designed to include user-defined settings to your trades. The endpoint /iserver/contract/{conid}/algos can be used to identify the available strategies for a given contract.

GET  /iserver/contract/{conid}/algos

Request inline:

  • String          addDescription       Whether or not to add algo description to response. Set to 1 for yes, 0 for no        required: false

  • String          addParams              Whether or not to show algo parameters. Set to 1 for yes, 0 for no                           required: false

  • String          algos                         List of algo ids delimited by “;” to filter by. Max of 8 algo ids can be specified.         required: false

Response:

  • Returns an array of algos

    • string                  name   

    • string                  description

    • string                  id

    • string    parameters

      • string                  id                                       The algo parameter

      • boolean              required                           If true a value must be entered

      • string                   name                                Descriptive name of the parameter

      • string                   valueClassName             Format of the parameter, Enum: double, string, time, Boolean

      • number              minValue                          Smallest value, only applies to parameters with valueClassName=Double

      • number              maxValue                         Largest value, only applies to parameters with valueClassnName=Double

      • boolean              defaultValue                    User configured preset for this parameter

      • string                   legalStrings                      The list of choices, example: “ALL:Get Done”, “ALL:Aggressive”, “ALL:Neutral”, “ALL:Passive”

      • string                   description                       Detailed description of the parameter.

      • number               guiRank                             The order in the UI, used when building dynamic UI so that more important parameter are presented first.

      • boolean              priceMarketRule             If true, must specify parameter using market rule format. Only applies to parameters with valueClassName=Double

      • string                   enabledConditions         The rules that UI should apply to algo parameters depending on chosen order type, Enum: MKT:speedup=:no, LMT:strategyType:<>:empty, MKT:strategyType:=:Marketable
                                                                                MKT:speedup=:no  –  hide SpeedUp param when MKT is chosen for order type.
                                                                                LMT:strategyType:<>:empty  –  strategyType param cannot be empty when LMT is chosen for order type.
                                                                                MKT:strategyType:=:Marketable  –  set strategyType parm to Marketable and disable (no other choice) when MKT is chosen for order type.

First we’ll send the endpoint /algos for the corresponding conid to receive a list of all available algo names

Please be sure to authenticate first in order to resolve the below URLs.
For authentication details, visit https://www.interactivebrokers.com/en/trading/ib-api.php.

Request:

GET https://localhost:5000/v1/api/iserver/contract/8314/algos

Response:

{
   “algos”: [
    {
     “name”: “Adaptive”,
     “id”: “Adaptive”
    },
    {
      “name”: “Arrival Price”,
     “id”: “ArrivalPx”
     },
    {
      “name”: “Close Price”,
     “id”: “ClosePx”
     },
     {
      “name”: “DarkIce”,
      “id”: “DarkIce”
     },
     {
      “name”: “Percentage of Volume”,
      “id”: “PctVol”
    },
     {
      “name”: “Price Variant Percentage of Volume”,
      “id”: “PctVolPx”
     },
    {
     “name”: “Size Variant Percentage of Volume”,
      “id”: “PctVolSz”
     },
    {
      “name”: “TWAP”,
      “id”: “Twap”
     },
     {
      “name”: “Time Variant Percentage of Volume”,
      “id”: “PctVolTm”
     },
     {
      “name”: “VWAP”,
     “id”: “Vwap”
     }
   ]
}

Now that we know the available algo strategies we’ll send the endpoint /algos again with additional parameters inline:

Request:

GET https://localhost:5000/v1/api/iserver/contract/8314/algos?addDescription=1&addParams=1&algos=PctVolTm

Response:

{

 “algos”: [
   {
    “name”: “Time Variant Percentage of Volume”,
    “description”: “Algo that lets you participate in volume at a user-defined rate that varies with time.”,
    “id”: “PctVolTm”,
    “parameters”: [
    {
     “guiRank”: 5,
      “defaultValue”: false,
      “name”: “Attempt to never take liquidity”,
      “id”: “noTakeLiq”,
      “valueClassName”: “Boolean”
     },
     {
      “guiRank”: 1,
      “minValue”: 0.01,
      “maxValue”: 50,
      “name”: “Target Percentage at Start Time”,
      “description”: “from 0.01 to 50.0”,
      “id”: “startPctVol”,
      “required”: “true”,
      “valueClassName”: “Double”
    },
     {
     “guiRank”: 2,
      “minValue”: 0.01,
      “maxValue”: 50,
     “name”: “Target Percentage at End Time”,
      “description”: “from 0.01 to 50.0”,
      “id”: “endPctVol”,
      “required”: “true”,
      “valueClassName”: “Double”
     },
     {
      “guiRank”: 6,
      “defaultValue”: false,
      “name”: “Attempt to match block trading volume”,
      “id”: “includeBlockTrades”,
      “valueClassName”: “Boolean”
     },
     {
“guiRank”: 7,
      “name”: “Trade when price is more aggressive than:”,
      “description”: “evaluates with bid for buy order and ask for sell order”,
      “id”: “conditionalPrice”,
      “valueClassName”: “Double”
     },
     {
      “guiRank”: 3,
      “name”: “Start Time”,
      “description”: “defaults to start of market trading”,
      “id”: “startTime”,
      “valueClassName”: “Time”
     },
     {
      “guiRank”: 4,
      “name”: “End Time”,
      “description”: “defaults to end of market trading”,
      “id”: “endTime”,
      “valueClassName”: “Time”
     }
    ]
  }
  ]
}

Now we can send the endpoint /iserver/account/{accountId}/orders with the included id of the algo strategy and the list of algo strategyParameters

POST https://localhost:5000/v1/api/iserver/account/DU26214/orders

Payload Request:

conid: 8314,
secType: “8314:STK”,
cOId: “testAlgoOrder”,
orderType: “LMT”,
price: 127,
side: “BUY”,
tif: “DAY”,
quantity: 1,
strategy: “PctVolTm”
strategyParameters: {
noTakeLiq: false,
monetaryValue: 200,
includeBlockTrades: false,
conditionalPrice: 128,
startTime: 20210412,
endTime: 20210413,
startPctVol: 0.1,
endPctVol: 0.2
}

If you have any further questions or issues sending IB Algo Orders please reach out to the API Group, ref: https://www.interactivebrokers.com/en/index.php?f=47047.

Visit the IBKR API Center for Downloads, Resources, and Technical Details:
https://www.interactivebrokers.com/en/trading/ib-api.php.

See the previous installment in this series: Tutorial: Web API – Connect to Brokerage Session.

Disclosure: Interactive Brokers

The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

trading top