tastytradeDeveloper Docs
Legacy ↗

API Reference / Orders

Submit Complex Order

postAccountsAccountNumberComplexOrders
post/accounts/{account_number}/complex-ordersMoney-moving

Money-moving. Dry-run first, send an ext-client-order-id, and confirm before submitting. See Idempotency & retries.

Base URL: https://api.cert.tastyworks.com (Sandbox) · https://api.tastyworks.com (Production)

Submits a new complex (bracket) order from the supplied parameters. Supported strategies are `OTOCO`, `OCO`, `OTO`, and `PAIRS` (`BLAST` is deprecated and unsupported). OTOCO and OTO orders include a `trigger-order` that routes immediately; the remaining `orders` stay in `Contingent` status until the trigger order fills. Run the dry-run endpoint first to validate the order.

Code samples

curl -X POST 'https://api.cert.tastyworks.com/accounts/5WX01234/complex-orders' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'User-Agent: tastytrade-docs-example/1.0' \
  -H 'Content-Type: application/json' \
  -d '{
  "orders": [
    {
      "gtc-date": "2024-01-15",
      "order-type": "Limit",
      "time-in-force": "Day",
      "stop-trigger": "string",
      "price": "100.00",
      "price-effect": "Credit",
      "value": "100.00",
      "value-effect": "Credit",
      "automated-source": true,
      "external-identifier": "string",
      "max-value-per-liquidity-allocation-fill": "100.00",
      "partition-key": "string",
      "preflight-id": "abc123",
      "source": "string",
      "legs": [
        {
          "action": "Allocate",
          "instrument-type": "Cryptocurrency",
          "quantity": "1",
          "symbol": "AAPL"
        }
      ],
      "rules": {
        "cancel-at": "2024-01-15T14:30:00.000Z",
        "conditions": [
          {
            "action": "cancel",
            "instrument-type": "Equity",
            "symbol": "AAPL",
            "comparator": "gte",
            "indicator": "last",
            "threshold": "string",
            "price-components": []
          }
        ],
        "route-after": "2024-01-15T14:30:00.000Z"
      },
      "advanced-instructions": {
        "strict-position-effect-validation": true
      }
    }
  ],
  "trigger-order": {
    "gtc-date": "2024-01-15",
    "order-type": "Limit",
    "time-in-force": "Day",
    "stop-trigger": "string",
    "price": "100.00",
    "price-effect": "Credit",
    "value": "100.00",
    "value-effect": "Credit",
    "automated-source": true,
    "external-identifier": "string",
    "max-value-per-liquidity-allocation-fill": "100.00",
    "partition-key": "string",
    "preflight-id": "abc123",
    "source": "string",
    "legs": [
      {
        "action": "Allocate",
        "instrument-type": "Cryptocurrency",
        "quantity": "1",
        "symbol": "AAPL"
      }
    ],
    "rules": {
      "cancel-at": "2024-01-15T14:30:00.000Z",
      "conditions": [
        {
          "action": "cancel",
          "instrument-type": "Equity",
          "symbol": "AAPL",
          "comparator": "gte",
          "indicator": "last",
          "threshold": "string",
          "price-components": [
            {}
          ]
        }
      ],
      "route-after": "2024-01-15T14:30:00.000Z"
    },
    "advanced-instructions": {
      "strict-position-effect-validation": true
    }
  },
  "type": "OTOCO",
  "ratio-price-comparator": "lte",
  "ratio-price-is-threshold-based-on-notional": true,
  "ratio-price-threshold": "1.25",
  "source": "my-api-code"
}'

Parameters

NameInTypeDescription
account_number*pathstring
e.g. "5WX01234"

Request bodyrequiredapplication/json

Example

{
  "orders": [
    {
      "gtc-date": "2024-01-15",
      "order-type": "Limit",
      "time-in-force": "Day",
      "stop-trigger": "string",
      "price": "100.00",
      "price-effect": "Credit",
      "value": "100.00",
      "value-effect": "Credit",
      "automated-source": true,
      "external-identifier": "string",
      "max-value-per-liquidity-allocation-fill": "100.00",
      "partition-key": "string",
      "preflight-id": "abc123",
      "source": "string",
      "legs": [
        {
          "action": "Allocate",
          "instrument-type": "Cryptocurrency",
          "quantity": "1",
          "symbol": "AAPL"
        }
      ],
      "rules": {
        "cancel-at": "2024-01-15T14:30:00.000Z",
        "conditions": [
          {
            "action": "cancel",
            "instrument-type": "Equity",
            "symbol": "AAPL",
            "comparator": "gte",
            "indicator": "last",
            "threshold": "string",
            "price-components": []
          }
        ],
        "route-after": "2024-01-15T14:30:00.000Z"
      },
      "advanced-instructions": {
        "strict-position-effect-validation": true
      }
    }
  ],
  "trigger-order": {
    "gtc-date": "2024-01-15",
    "order-type": "Limit",
    "time-in-force": "Day",
    "stop-trigger": "string",
    "price": "100.00",
    "price-effect": "Credit",
    "value": "100.00",
    "value-effect": "Credit",
    "automated-source": true,
    "external-identifier": "string",
    "max-value-per-liquidity-allocation-fill": "100.00",
    "partition-key": "string",
    "preflight-id": "abc123",
    "source": "string",
    "legs": [
      {
        "action": "Allocate",
        "instrument-type": "Cryptocurrency",
        "quantity": "1",
        "symbol": "AAPL"
      }
    ],
    "rules": {
      "cancel-at": "2024-01-15T14:30:00.000Z",
      "conditions": [
        {
          "action": "cancel",
          "instrument-type": "Equity",
          "symbol": "AAPL",
          "comparator": "gte",
          "indicator": "last",
          "threshold": "string",
          "price-components": [
            {}
          ]
        }
      ],
      "route-after": "2024-01-15T14:30:00.000Z"
    },
    "advanced-instructions": {
      "strict-position-effect-validation": true
    }
  },
  "type": "OTOCO",
  "ratio-price-comparator": "lte",
  "ratio-price-is-threshold-based-on-notional": true,
  "ratio-price-threshold": "1.25",
  "source": "my-api-code"
}

Schema

  • ordersrequiredarray<object>

    Array of orders for OCO/BLAST orders

    • gtc-datestring <date>

      The date in which a GTD order will expire. Can only be provided if time-in-force is GTD.

    • order-typerequiredstring

      The type of order in regards to the price. i.e. `Limit`, `Liquidity Allocation`, `Market`, `Marketable Limit`, `Notional Market`, `Stop` or `Stop Limit`

      enum: Limit, Liquidity Allocation, Market, Marketable Limit, Notional Market, Stop, Stop Limit

    • time-in-forcerequiredstring

      The length in time before the order expires. i.e. `Day`, `Ext`, `Ext Overnight`, `GTC`, `GTC Ext`, `GTC Ext Overnight`, `GTD` or `IOC`

      enum: Day, Ext, Ext Overnight, GTC, GTC Ext, GTC Ext Overnight, GTD, IOC

    • stop-triggerrequiredstring <decimal>

      The price trigger at which a stop or stop-limit order becomes valid. Decimal value serialized as a JSON string (e.g. "150.25").

    • pricestring <decimal>

      The price of the Order. Required for limit and stop-limit orders. Decimal value serialized as a JSON string (e.g. "150.25").

    • price-effectrequiredstring

      If pay or receive payment for placing the order. i.e. `Credit` or `Debit`

      enum: Credit, Debit

    • valuestring <decimal>

      The notional value of the Order, required for notional market orders. Decimal value serialized as a JSON string (e.g. "150.25").

    • value-effectrequiredstring

      If pay or receive payment for placing the notional market order. i.e. `Credit` or `Debit`

      enum: Credit, Debit

    • automated-sourceboolean

      If the order was placed from an automated source

    • external-identifierstring

      External identifier for the order

    • max-value-per-liquidity-allocation-fillstring <decimal>

      Max value per liquidity allocation fill Decimal value serialized as a JSON string (e.g. "150.25").

    • partition-keystring

      Account partition key

    • preflight-idstring

      Transient order identifier used for matching preflight errors to an individual order

    • sourcestring

      The source the order is coming from

    • legsrequiredarray<object>{4 fields}
    • rulesobject{3 fields}
    • advanced-instructionsobject{1 fields}
  • trigger-orderobject

    Initial live order for OTO based orders

    • gtc-datestring <date>

      The date in which a GTD order will expire. Can only be provided if time-in-force is GTD.

    • order-typerequiredstring

      The type of order in regards to the price. i.e. `Limit`, `Liquidity Allocation`, `Market`, `Marketable Limit`, `Notional Market`, `Stop` or `Stop Limit`

      enum: Limit, Liquidity Allocation, Market, Marketable Limit, Notional Market, Stop, Stop Limit

    • time-in-forcerequiredstring

      The length in time before the order expires. i.e. `Day`, `Ext`, `Ext Overnight`, `GTC`, `GTC Ext`, `GTC Ext Overnight`, `GTD` or `IOC`

      enum: Day, Ext, Ext Overnight, GTC, GTC Ext, GTC Ext Overnight, GTD, IOC

    • stop-triggerrequiredstring <decimal>

      The price trigger at which a stop or stop-limit order becomes valid. Decimal value serialized as a JSON string (e.g. "150.25").

    • pricestring <decimal>

      The price of the Order. Required for limit and stop-limit orders. Decimal value serialized as a JSON string (e.g. "150.25").

    • price-effectrequiredstring

      If pay or receive payment for placing the order. i.e. `Credit` or `Debit`

      enum: Credit, Debit

    • valuestring <decimal>

      The notional value of the Order, required for notional market orders. Decimal value serialized as a JSON string (e.g. "150.25").

    • value-effectrequiredstring

      If pay or receive payment for placing the notional market order. i.e. `Credit` or `Debit`

      enum: Credit, Debit

    • automated-sourceboolean

      If the order was placed from an automated source

    • external-identifierstring

      External identifier for the order

    • max-value-per-liquidity-allocation-fillstring <decimal>

      Max value per liquidity allocation fill Decimal value serialized as a JSON string (e.g. "150.25").

    • partition-keystring

      Account partition key

    • preflight-idstring

      Transient order identifier used for matching preflight errors to an individual order

    • sourcestring

      The source the order is coming from

    • legsrequiredarray<object>{4 fields}
    • rulesobject{3 fields}
    • advanced-instructionsobject{1 fields}
  • typerequiredstring

    The type of stragegy for the complex order i.e. `BLAST`, `OCO`, `OTO`, `OTOCO` or `PAIRS`

    enum: BLAST, OCO, OTO, OTOCO, PAIRS

    example: "OTOCO"

  • ratio-price-comparatorstring

    How to compare against the ratio price. \ Supports `gte` (Greater than or Equal To) or `lte` (Less than or Equal to)

    enum: gte, lte

    example: "lte"

  • ratio-price-is-threshold-based-on-notionalboolean

    If comparison is in notional value instead of price.

  • ratio-price-thresholdstring <decimal>

    Ratio price for a PAIRS trade Decimal value serialized as a JSON string (e.g. "150.25").

    example: "1.25"

  • sourcestring

    The source the order is coming from

    example: "my-api-code"

Responses

201The complex order was accepted. The response contains the overall complex order id plus an id for each component order, along with the buying-power and fee impact.application/json

Example response

{
  "data": {
    "buying-power-effect": {
      "change-in-margin-requirement": "300.0",
      "change-in-margin-requirement-effect": "Debit",
      "change-in-buying-power": "102.302",
      "change-in-buying-power-effect": "Debit",
      "current-buying-power": "8995981.2613",
      "current-buying-power-effect": "Credit",
      "new-buying-power": "8995878.9593",
      "new-buying-power-effect": "Credit",
      "isolated-order-margin-requirement": "300.0",
      "isolated-order-margin-requirement-effect": "Debit",
      "is-spread": true,
      "impact": "102.302",
      "effect": "Debit"
    },
    "closing-fee-calculation": "string",
    "complex-order": {
      "id": "abc123",
      "account-number": "5WX01234",
      "ratio-price-comparator": "100.00",
      "ratio-price-is-threshold-based-on-notional": true,
      "ratio-price-threshold": "100.00",
      "terminal-at": "2024-01-15T14:30:00.000Z",
      "type": "string",
      "related-orders": [
        {
          "id": "abc123",
          "complex-order-id": "abc123",
          "complex-order-tag": "string",
          "replaces-order-id": "abc123",
          "replacing-order-id": "abc123",
          "status": "string"
        }
      ],
      "orders": [
        {
          "id": "abc123",
          "account-number": "5WX01234",
          "cancel-user-id": "abc123",
          "cancel-username": "string",
          "cancellable": true,
          "cancelled-at": "2024-01-15T14:30:00.000Z",
          "complex-order-id": "abc123",
          "complex-order-tag": "string",
          "confirmation-status": "string",
          "contingent-status": "string",
          "editable": true,
          "edited": true,
          "external-identifier": "string",
          "global-request-id": "abc123",
          "gtc-date": "2024-01-15",
          "in-flight-at": "2024-01-15T14:30:00.000Z",
          "liquidity-pool-instrument-type": "Equity",
          "live-at": "2024-01-15T14:30:00.000Z",
          "max-value-per-liquidity-allocation-fill": "100.00",
          "order-type": "string",
          "preflight-id": "abc123",
          "price": "100.00",
          "price-effect": "100.00",
          "received-at": "2024-01-15T14:30:00.000Z",
          "reject-reason": "string",
          "replaces-order-id": "abc123",
          "replacing-order-id": "abc123",
          "size": "string",
          "source": "string",
          "status": "string",
          "stop-trigger": "string",
          "terminal-at": "2024-01-15T14:30:00.000Z",
          "time-in-force": "string",
          "underlying-instrument-type": "Equity",
          "underlying-symbol": "AAPL",
          "updated-at": "2024-01-15T14:30:00.000Z",
          "user-id": "abc123",
          "username": "string",
          "value": "100.00",
          "value-effect": "100.00",
          "legs": [
            {}
          ],
          "order-rule": {
            "cancel-at": "2024-01-15T14:30:00.000Z",
            "cancelled-at": "2024-01-15T14:30:00.000Z",
            "route-after": "2024-01-15T14:30:00.000Z",
            "routed-at": "2024-01-15T14:30:00.000Z",
            "order-conditions": []
          }
        }
      ],
      "trigger-order": {
        "id": "abc123",
        "account-number": "5WX01234",
        "cancel-user-id": "abc123",
        "cancel-username": "string",
        "cancellable": true,
        "cancelled-at": "2024-01-15T14:30:00.000Z",
        "complex-order-id": "abc123",
        "complex-order-tag": "string",
        "confirmation-status": "string",
        "contingent-status": "string",
        "editable": true,
        "edited": true,
        "external-identifier": "string",
        "global-request-id": "abc123",
        "gtc-date": "2024-01-15",
        "in-flight-at": "2024-01-15T14:30:00.000Z",
        "liquidity-pool-instrument-type": "Equity",
        "live-at": "2024-01-15T14:30:00.000Z",
        "max-value-per-liquidity-allocation-fill": "100.00",
        "order-type": "string",
        "preflight-id": "abc123",
        "price": "100.00",
        "price-effect": "100.00",
        "received-at": "2024-01-15T14:30:00.000Z",
        "reject-reason": "string",
        "replaces-order-id": "abc123",
        "replacing-order-id": "abc123",
        "size": "string",
        "source": "string",
        "status": "string",
        "stop-trigger": "string",
        "terminal-at": "2024-01-15T14:30:00.000Z",
        "time-in-force": "string",
        "underlying-instrument-type": "Equity",
        "underlying-symbol": "AAPL",
        "updated-at": "2024-01-15T14:30:00.000Z",
        "user-id": "abc123",
        "username": "string",
        "value": "100.00",
        "value-effect": "100.00",
        "legs": [
          {
            "action": "string",
            "instrument-type": "Equity",
            "quantity": "1",
            "remaining-quantity": "1",
            "symbol": "AAPL",
            "fills": []
          }
        ],
        "order-rule": {
          "cancel-at": "2024-01-15T14:30:00.000Z",
          "cancelled-at": "2024-01-15T14:30:00.000Z",
          "route-after": "2024-01-15T14:30:00.000Z",
          "routed-at": "2024-01-15T14:30:00.000Z",
          "order-conditions": [
            {}
          ]
        }
      }
    },
    "errors": [
      {
        "code": "string",
        "message": "string",
        "preflight-id": "abc123"
      }
    ],
    "fee-calculation": {
      "regulatory-fees": "0.102",
      "regulatory-fees-effect": "Debit",
      "clearing-fees": "0.2",
      "clearing-fees-effect": "Debit",
      "commission": "2.0",
      "commission-effect": "Debit",
      "proprietary-index-option-fees": "0.0",
      "proprietary-index-option-fees-effect": "Debit",
      "total-fees": "2.302",
      "total-fees-effect": "Debit"
    },
    "notes": [
      {
        "code": "string",
        "message": "string",
        "preflight-id": "abc123",
        "url": "string"
      }
    ],
    "order": {
      "id": "abc123",
      "account-number": "5WX01234",
      "cancel-user-id": "abc123",
      "cancel-username": "string",
      "cancellable": true,
      "cancelled-at": "2024-01-15T14:30:00.000Z",
      "complex-order-id": "abc123",
      "complex-order-tag": "string",
      "confirmation-status": "string",
      "contingent-status": "string",
      "editable": true,
      "edited": true,
      "external-identifier": "string",
      "global-request-id": "abc123",
      "gtc-date": "2024-01-15",
      "in-flight-at": "2024-01-15T14:30:00.000Z",
      "liquidity-pool-instrument-type": "Equity",
      "live-at": "2024-01-15T14:30:00.000Z",
      "max-value-per-liquidity-allocation-fill": "100.00",
      "order-type": "string",
      "preflight-id": "abc123",
      "price": "100.00",
      "price-effect": "100.00",
      "received-at": "2024-01-15T14:30:00.000Z",
      "reject-reason": "string",
      "replaces-order-id": "abc123",
      "replacing-order-id": "abc123",
      "size": "string",
      "source": "string",
      "status": "string",
      "stop-trigger": "string",
      "terminal-at": "2024-01-15T14:30:00.000Z",
      "time-in-force": "string",
      "underlying-instrument-type": "Equity",
      "underlying-symbol": "AAPL",
      "updated-at": "2024-01-15T14:30:00.000Z",
      "user-id": "abc123",
      "username": "string",
      "value": "100.00",
      "value-effect": "100.00",
      "legs": [
        {
          "action": "string",
          "instrument-type": "Equity",
          "quantity": "1",
          "remaining-quantity": "1",
          "symbol": "AAPL",
          "fills": [
            {}
          ]
        }
      ],
      "order-rule": {
        "cancel-at": "2024-01-15T14:30:00.000Z",
        "cancelled-at": "2024-01-15T14:30:00.000Z",
        "route-after": "2024-01-15T14:30:00.000Z",
        "routed-at": "2024-01-15T14:30:00.000Z",
        "order-conditions": [
          {
            "id": "abc123",
            "action": "string",
            "comparator": "string",
            "indicator": "string",
            "instrument-type": "Equity",
            "is-threshold-based-on-notional": true,
            "symbol": "AAPL",
            "threshold": "string",
            "triggered-at": "2024-01-15T14:30:00.000Z",
            "triggered-value": "100.00",
            "price-components": []
          }
        ]
      }
    },
    "warnings": [
      {
        "code": "string",
        "message": "string",
        "preflight-id": "abc123"
      }
    ]
  },
  "context": "/accounts/{account_number}/complex-orders"
}

Schema

  • datarequiredobject (PlacedOrderResponse)

    The response returned when placing, editing, or dry-running an order or complex order. Contains the resulting `order` (or `complex-order`), the `buying-power-effect`, the `fee-calculation`, and any `warnings`, `errors`, or `notes` produced by the preflight checks.

    • buying-power-effectobject{13 fields}

      Details of the order's impact on the account's buying power, including the change in buying power and its direction. A JSON object (upstream types this field as a string; attested responses return this object, with decimal values serialized as JSON strings).

    • closing-fee-calculationstring

      An estimate of the fees to expect when later closing the position this order would open. Provided as a convenience; not applied to this order.

    • complex-orderobject{10 fields}
    • errorsarray<object>{3 fields}

      Preflight errors explaining why the order failed validation, each with a `code`, `message`, and `preflight-id`.

    • fee-calculationobject{10 fields}

      An estimate of the fees the order would incur if filled, broken into regulatory, clearing, commission, and other categories and totaled at the end. A JSON object (upstream types this field as a string; attested responses return this object, with decimal values serialized as JSON strings).

    • notesarray<object>{4 fields}

      Informational notes about the order, each optionally including a `url` for more detail.

    • orderobject{42 fields}
    • warningsarray<object>{3 fields}

      Informational warnings produced by a dry-run or submission. A warning may indicate the order would be rejected if routed, or that the market is closed.

  • contextrequiredstring

    example: "/accounts/{account_number}/complex-orders"

401Missing or expired access token, or a missing/malformed `User-Agent` header.application/json

Example response

{
  "error": {
    "code": "unauthorized",
    "message": "No valid access token was provided; access tokens expire after 15 minutes."
  }
}

Schema

  • errorrequiredobject
    • coderequiredstring

      Machine-readable error code (see the Error reference).

    • messagerequiredstring

      Human-readable explanation.

    • errorsarray<object>{3 fields}

      Present for multi-error / validation failures; one entry per problem.

403The token's scope or the account authority does not permit placing orders on this account.application/json

Example response

{
  "error": {
    "code": "not_permitted",
    "message": "User not permitted access"
  }
}

Schema

  • errorrequiredobject
    • coderequiredstring

      Machine-readable error code (see the Error reference).

    • messagerequiredstring

      Human-readable explanation.

    • errorsarray<object>{3 fields}

      Present for multi-error / validation failures; one entry per problem.

404The account number does not exist or is not accessible with this token.application/json

Example response

{
  "error": {
    "code": "string",
    "message": "string",
    "errors": [
      {
        "code": "string",
        "message": "string",
        "domain": "string"
      }
    ]
  }
}

Schema

  • errorrequiredobject
    • coderequiredstring

      Machine-readable error code (see the Error reference).

    • messagerequiredstring

      Human-readable explanation.

    • errorsarray<object>{3 fields}

      Present for multi-error / validation failures; one entry per problem.

422The complex order failed preflight validation. The response JSON's `error.message` (and `errors[]`) explain the rejection reason, for example a contingent leg with no existing position to close.application/json

Example response

{
  "error": {
    "code": "preflight_check_failure",
    "message": "One or more preflight checks failed",
    "errors": [
      {
        "code": "preflight_check_failure",
        "message": "A specific validation failed for this order."
      }
    ]
  }
}

Schema

  • errorrequiredobject
    • coderequiredstring

      Machine-readable error code (see the Error reference).

    • messagerequiredstring

      Human-readable explanation.

    • errorsarray<object>{3 fields}

      Present for multi-error / validation failures; one entry per problem.

429Request rate exceeded. Back off exponentially and reduce your request rate.application/json

Example response

{
  "error": {
    "code": "string",
    "message": "string",
    "errors": [
      {
        "code": "string",
        "message": "string",
        "domain": "string"
      }
    ]
  }
}

Schema

  • errorrequiredobject
    • coderequiredstring

      Machine-readable error code (see the Error reference).

    • messagerequiredstring

      Human-readable explanation.

    • errorsarray<object>{3 fields}

      Present for multi-error / validation failures; one entry per problem.

Related

Agents: this page is also Markdown (with the embedded OpenAPI definition) — append .md or send Accept: text/markdown. Index at /llms.txt.