{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/alpaca/json-schema/alpaca-create-order-request-schema.json",
  "title": "CreateOrderRequest",
  "description": "Represents a request to create an order.",
  "x-generated": "2026-11-05",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/alpaca-us-trading-api-openapi.yml#/components/schemas/CreateOrderRequest",
  "properties": {
    "advanced_instructions": {
      "$ref": "#/$defs/AdvancedInstructions"
    },
    "client_order_id": {
      "description": "A unique identifier for the order. Automatically generated if not sent. (<= 128 characters)",
      "maxLength": 128,
      "type": "string"
    },
    "extended_hours": {
      "description": "(default) false. If true, order will be eligible for execution in the pre-market, after-hours, and overnight sessions. Only works with type `limit` and time_in_force set to either `day` or `gtc`",
      "type": "boolean"
    },
    "legs": {
      "description": "list of order legs (<= 4)",
      "items": {
        "$ref": "#/$defs/MLegOrderLeg"
      },
      "maxItems": 4,
      "type": "array"
    },
    "limit_price": {
      "description": "Required if type is `limit` or `stop_limit`.\nIn case of `mleg`, the limit_price parameter is expressed with the following notation:\n- A positive value indicates a debit, representing a cost or payment to be made.\n- A negative value signifies a credit, reflecting an amount to be received.",
      "type": "string"
    },
    "notional": {
      "description": "dollar amount to trade. Cannot work with `qty`. Can only work for market order types and day for time in force.",
      "type": "string"
    },
    "order_class": {
      "$ref": "#/$defs/OrderClass"
    },
    "position_intent": {
      "$ref": "#/$defs/PositionIntent"
    },
    "qty": {
      "description": "number of shares to trade. Can be fractionable for only market and day order types. Required for `mleg` order class, represents the number of units to trade of this strategy.",
      "type": "string"
    },
    "side": {
      "$ref": "#/$defs/OrderSide"
    },
    "stop_loss": {
      "description": "Takes in string/number values for stop_price and limit_price",
      "properties": {
        "limit_price": {
          "format": "decimal",
          "type": "string"
        },
        "stop_price": {
          "format": "decimal",
          "type": "string"
        }
      },
      "type": "object"
    },
    "stop_price": {
      "description": "required if type is `stop` or `stop_limit`",
      "type": "string"
    },
    "symbol": {
      "description": "symbol, asset ID, or currency pair to identify the asset to trade, required for all order classes except for `mleg`.",
      "type": "string"
    },
    "take_profit": {
      "description": "Takes in a string/number value for limit_price",
      "properties": {
        "limit_price": {
          "format": "decimal",
          "type": "string"
        }
      },
      "type": "object"
    },
    "time_in_force": {
      "$ref": "#/$defs/TimeInForce"
    },
    "trail_percent": {
      "description": "this or `trail_price` is required if type is `trailing_stop`",
      "type": "string"
    },
    "trail_price": {
      "description": "this or `trail_percent` is required if type is `trailing_stop`",
      "type": "string"
    },
    "type": {
      "$ref": "#/$defs/OrderType"
    }
  },
  "required": [
    "type",
    "time_in_force"
  ],
  "type": "object",
  "$defs": {
    "AdvancedInstructions": {
      "description": "Advanced instructions for Elite Smart Router: https://docs.alpaca.markets/docs/alpaca-elite-smart-router",
      "properties": {
        "algorithm": {
          "description": "The advanced routing algorithm to use for the order",
          "enum": [
            "DMA",
            "TWAP",
            "VWAP"
          ],
          "type": "string"
        },
        "destination": {
          "description": "Target exchange for order execution",
          "enum": [
            "NYSE",
            "NASDAQ",
            "ARCA",
            "IEX",
            "MEMX"
          ],
          "type": "string"
        },
        "display_qty": {
          "description": "Maximum shares/contracts displayed on the exchange at any time. Must be in round lot increments",
          "format": "decimal",
          "type": "string"
        },
        "end_time": {
          "description": "When the algorithm is to be done executing. Must be within current market trading hours",
          "format": "date-time",
          "type": "string"
        },
        "max_percentage": {
          "description": "Maximum percentage of the ticker's period volume this order might participate in. Must be 0 < max_percentage < 1, with up to 3 decimal points precision.",
          "format": "decimal",
          "type": "string"
        },
        "start_time": {
          "description": "When the algorithm is to start executing. Must be within current market trading hours",
          "format": "date-time",
          "type": "string"
        }
      },
      "title": "AdvancedInstructions",
      "type": "object"
    },
    "MLegOrderLeg": {
      "description": "Represents an individual leg of a multi-leg options order.",
      "properties": {
        "position_intent": {
          "$ref": "#/$defs/PositionIntent"
        },
        "ratio_qty": {
          "description": "proportional quantity of this leg in relation to the overall multi-leg order qty",
          "type": "string"
        },
        "side": {
          "$ref": "#/$defs/OrderSide"
        },
        "symbol": {
          "description": "symbol or asset ID to identify the asset to trade",
          "type": "string"
        }
      },
      "required": [
        "symbol",
        "ratio_qty"
      ],
      "title": "MLegOrderLeg",
      "type": "object"
    },
    "OrderClass": {
      "description": "The order classes supported by Alpaca vary based on the order's security type. The following provides a comprehensive breakdown of the supported order classes for each category:\n  - Equity trading: simple (or \"\"), oco, oto, bracket.\n  - Options trading:\n    - simple (or \"\")\n    - mleg (required for multi-leg complex option strategies)\n  - Crypto trading: simple (or \"\").",
      "enum": [
        "simple",
        "bracket",
        "oco",
        "oto",
        "mleg",
        ""
      ],
      "title": "OrderClass",
      "type": "string"
    },
    "OrderSide": {
      "description": "Represents which side this order was on:\n- buy\n- sell\nRequired for all order classes except for mleg.",
      "enum": [
        "buy",
        "sell"
      ],
      "title": "OrderSide",
      "type": "string"
    },
    "OrderType": {
      "description": "The order types supported by Alpaca vary based on the order's security type. The following provides a comprehensive breakdown of the supported order types for each category:\n - Equity trading: market, limit, stop, stop_limit, trailing_stop.\n - Options trading: market, limit, stop, stop_limit.\n - Multileg Options trading: market, limit.\n - Crypto trading: market, limit, stop_limit.",
      "enum": [
        "market",
        "limit",
        "stop",
        "stop_limit",
        "trailing_stop"
      ],
      "title": "OrderType",
      "type": "string"
    },
    "PositionIntent": {
      "description": "Represents the desired position strategy.",
      "enum": [
        "buy_to_open",
        "buy_to_close",
        "sell_to_open",
        "sell_to_close"
      ],
      "title": "PositionIntent",
      "type": "string"
    },
    "TimeInForce": {
      "description": "The Time-In-Force values supported by Alpaca vary based on the order's security type. Here is a breakdown of the supported TIFs for each specific security type:\n- Equity trading: day, gtc, opg, cls, ioc, fok.\n- Options trading: day, gtc.\n- Crypto trading: gtc, ioc.\n\nBelow are the descriptions of each TIF:\n- day:\n  A day order is eligible for execution only on the day it is live. By default, the order is only valid during Regular Trading Hours (9:30am - 4:00pm ET). If unfilled after the closing auction, it is automatically canceled. If submitted after the close, it is queued and submitted the following trading day. However, if marked as eligible for extended hours, the order can also execute during supported extended hours.\n\n- gtc:\n  The order is good until canceled. Non-marketable GTC limit orders are subject to price adjustments to offset corporate actions affecting the issue. We do not currently support Do Not Reduce (DNR) orders to opt out of such price adjustments.\n\n- opg:\n  Use this TIF with a market/limit order type to submit \"market on open\" (MOO) and \"limit on open\" (LOO) orders. This order is eligible to execute only in the market opening auction. Any unfilled orders after the open will be cancelled. OPG orders submitted after 9:28am but before 7:00pm ET will be rejected. OPG orders submitted after 7:00pm will be queued and routed to the following day's opening auction. On open/on close orders are routed to the primary exchange. Such orders do not necessarily execute exactly at 9:30am / 4:00pm ET but execute per the exchange's auction rules.\n\n- cls:\n  Use this TIF with a market/limit order type to submit \"market on close\" (MOC) and \"limit on close\" (LOC) orders. This order is eligible to execute only in the market closing auction. Any unfilled orders after the close will be cancelled. CLS orders submitted after 3:50pm but before 7:00pm ET will be rejected. CLS orders submitted after 7:00pm will be queued and routed to the following day's closing auction. Only available with API v2.\n\n- ioc:\n  An Immediate Or Cancel (IOC) order requires all or part of the order to be executed immediately. Any unfilled portion of the order is canceled. Only available with API v2. Most market makers who receive IOC orders will attempt to fill the order on a principal basis only, and cancel any unfilled balance. On occasion, this can result in the entire order being cancelled if the market maker does not have any existing inventory of the security in question.\n\n- fok:\n  A Fill or Kill (FOK) order is only executed if the entire order quantity can be filled, otherwise the order is canceled. Only available with API v2.",
      "enum": [
        "day",
        "gtc",
        "opg",
        "cls",
        "ioc",
        "fok"
      ],
      "title": "TimeInForce",
      "type": "string"
    }
  }
}