{
  "openapi": "3.0.3",
  "info": {
    "title": "Connect Trade API",
    "description": "# Getting Started\nWelcome to the Connect Trade API.\n\nHere you’ll find the technical details for our endpoints, data models, and authentication flows needed to integrate broker trading and account access into your platform.\n",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.connecttrade.com"
    }
  ],
  "security": [
    {
      "client-id": [],
      "client-secret": []
    }
  ],
  "tags": [
    {
      "name": "Users",
      "description": "Create and manage end users for your platform. User management operations are: Create, Get, Delete users and Rotate manage user secrets."
    },
    {
      "name": "Connections",
      "description": "A connection represents a user's authenticated link to a broker. Each connection is tied to a single broker login and may include one or more broker accounts. Use the API to create, validate, and manage the lifecycle of these connections."
    },
    {
      "name": "Accounts",
      "description": "Access broker account details for a connected user."
    },
    {
      "name": "Balances",
      "description": "Retrieve balance details for a connected broker account."
    },
    {
      "name": "Orders",
      "description": "Create new broker orders, retrieve existing orders, and cancel open orders for a connected broker account"
    },
    {
      "name": "Positions",
      "description": "Retrieve current positions for a connected broker account."
    },
    {
      "name": "Transactions",
      "description": "Retrieve transaction history and activity details for a connected broker account."
    },
    {
      "name": "Streaming Broker API",
      "description": "Connect Trade provides a WebSocket streaming API for receiving order, position and balance updates.\n\nWebSocket API is available at `wss://stream.connecttrade.com` and requires JSON encoded messages.\n\nAfter connecting, client has to authenticate (using `client_id` and `client_secret`). Following successful authentication, client must `subscribe` to topics of interest and `subscribe_user` for each platform user whose updates the session should receive. Updates for a user are delivered only while at least one session is subscribed to that user.\n\nClient implementation needs to incorporate re-connection logic for re-establishing subscriptions in the event of a disconnection.\n\nThis document describes version `v1.0` of the Stream API. There is a sample python implementation (`sample_stream_api_client`) available using asyncio.\n\n## Session workflow\n\n1. Connect to `wss://stream.connecttrade.com`\n2. Send an `authenticate` message. Connection will be terminated if client is not authenticated within 30 seconds from establishing connection.\n3. Send a `subscribe` message for subscribing to topics of interest.\n4. Send a `subscribe_user` message for each platform user whose updates the session should receive. Updates for a user are delivered only while at least one session is subscribed to that user.\n5. Receive unsolicited updates for the topics subscribed.\n\n## Welcome message\n\nUpon establishing a WebSocket connection, server will emit a `welcome` message. This message, **with one striking exception**, is intended to be read by humans. Its schema is subject to change and you shouldn't be expected to use it, parse it or respond to it.\n\nThe only property out of the `welcome` message that is of interest is `session_id`. Session ID can be useful for uniquely identifying a session when contacting Connect Trade support and is otherwise not used anywhere else.\n\n```json\n{\n    \"type\": \"welcome\", \n    \"session_id\": \"1e04d508-7795-4a5e-8693-2423e957061d\", \n    \"message\": \"Connected to Connect Trade WebSocket API. Please authenticate within 30 seconds or connection will be closed. If you encounter an issue during this session make sure you include value of session_id property when contacting support.\", \n    \"timeout_seconds\": 30, \n    \"required_steps\": \n    [\n        \"1. Send authentication message with your client credentials\", \n        \"2. Once authenticated, you can subscribe to data feeds at anytime\"\n    ]\n}\n```\n\n## Authentication\n\nAn `authenticate` message is the only allowed message type for newly established connections. Any other message type will be ignored at this phase.\n\nAuthentication needs to occur within the first 30 seconds of a newly established connection. Server will terminate unauthenticated connections after this period.\n\nFor authenticating, you need to provide your `client_id` and `client_secret`.\n\nThe same `client_id`/`client_secret` pair may be used by more than one session at a time, up to a per-`client_id` concurrent-session cap (currently **10**). Each WebSocket connection has its own per-session user-subscription limit (see [User-subscription limit](#section/Streaming-Brokerage-Data-API/User-subscription-limit)), so opening additional sessions is the supported way to scale beyond it.\n\nAuthentication attempts beyond the concurrent-session cap are rejected with:\n\n```json\n{\n    \"type\": \"auth_error\",\n    \"message\": \"Concurrent session limit (10) reached for this client_id\"\n}\n```\n\nAuthenticate message\n\n```json\n{\n    \"action\": \"authenticate\", \n    \"client_id\": \"your-client-id\", \n    \"client_secret\": \"your-client-secret\", \n    \"version\": \"v1.0\"\n}\n```\n- `action` - (Required) - Needs to be `\"authenticate\"`.\n- `client_id` - (Required) - Your client ID.\n- `client_secret` - (Required) - Your client secret.\n- `version` - (Optional) - The desired protocol version. If provided, server will try to match requested version of the API. Provided for backwards compatibility. Currently, only supported value is `\"v1.0\"`.\n\nSuccessful authentication\n\n```json\n{\n    \"type\": \"auth_success\", \n    \"message\": \"Authentication successful\", \n    \"version\": \"v1.0\"\n}\n```\n\nUnsuccessful authentication\n\n```json\n{\n    \"type\": \"auth_error\",\n    \"message\": \"<Failure reason>\"\n}\n```\n\nTrying to authenticate a second time, after session has already been authenticated successfully will result in a non-fatal error:\n```json\n{\n    \"type\": \"auth_error\",\n    \"message\": \"Session is already authenticated\",\n}\n```\n\n## Subscribing\n\nSubscribing to topics is possible only after successfully authenticating. Available topics are;\n- `orders`\n- `positions`\n- `balances`\n\nDepending on your account, or your platform, or other reasons, not all topics might be available for you, or not all topics might emit updates.\n\nYour client implementation can (and should) subscribe to more than one topic at the same time.\n\nSubscribe message\n\n```json\n{\n    \"action\": \"subscribe\", \n    \"topics\": [\"orders\", \"positions\", \"balances\"]\n}\n```\n\n- `action` - (Required) - Needs to be `\"subscribe\"`.\n- `topics` - (Required) - A list of topics of interest. Each topic can only be referenced once (no multiple copies allowed). Topic names are case-sensitive and need to match the available topic names listed above.\n\nYou can alternatively set `topics` equal to `[ \"all\" ]`. This will get your session subscribed to all available topics. You need to be careful when using `[ \"all\" ]` (especially if also not requesting a specific `version` during `authenticate`) as it might result in unexpected behaviour from your client if/when new topics are introduced.\n\nSuccessful subscription\n\n```json\n{\n    \"type\": \"subscribed\", \n    \"subscription_id\": \"518f11fa-1b8e-485f-a7a4-c485437149e8\", \n    \"topics\": [\"orders\", \"positions\", \"balances\"]\n}\n```\n\nUnsuccessful subscription\n\n```json\n{\n    \"type\": \"subscription_failed\",\n    \"message\": \"Error message\"\n}\n```\n\n## Per-user subscriptions\n\nA per-user subscription enables update delivery for a specific platform user. Updates for a user are delivered only while at least one session is subscribed to that user; delivery stops when the last subscribing session unsubscribes or disconnects.\n\nPer-user subscriptions are required to receive update messages. The two steps work together:\n- `subscribe` (topics) selects which message types this session is interested in.\n- `subscribe_user` selects which platform users this session receives updates for.\n\nA session may subscribe to multiple users.\n\n### Subscribing a user\n\n```json\n{\n    \"action\": \"subscribe_user\",\n    \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\"\n}\n```\n\n- `action` - (Required) - Needs to be `\"subscribe_user\"`.\n- `user_id` - (Required) - The user ID to subscribe.\n\nSuccessful response\n\n```json\n{\n    \"type\": \"user_subscribed\",\n    \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\"\n}\n```\n\nSubscribing the same `(session, user_id)` pair more than once is a no-op and is not counted twice against the user-subscription limit.\n\n### Unsubscribing a user\n\n```json\n{\n    \"action\": \"unsubscribe_user\",\n    \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\"\n}\n```\n\n- `action` - (Required) - Needs to be `\"unsubscribe_user\"`.\n- `user_id` - (Required) - The user ID to unsubscribe.\n\nSuccessful response\n\n```json\n{\n    \"type\": \"user_unsubscribed\",\n    \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\"\n}\n```\n\nUnsubscribing a `(session, user_id)` pair that is not currently subscribed is a no-op.\n\n### Automatic cleanup on disconnect\n\nWhen a session disconnects, all of its per-user subscriptions are released as if `unsubscribe_user` had been called for each one. If a user has been subscribed by multiple sessions, update delivery for that user continues until the last subscribing session releases it.\n\n### User-subscription limit\n\nEach WebSocket session can subscribe to up to **500** distinct platform users via `subscribe_user`. Attempting to subscribe a user beyond this limit fails with a `subscription_failed` response.\n\nIf you need to receive updates for more than 500 users concurrently, open additional WebSocket connections (the same `client_id`/`client_secret` pair may be used by multiple sessions) and split your `subscribe_user` calls across them. Each session has its own independent limit.\n\n### Failures\n\nFailed requests (e.g., missing `user_id`, unknown `user_id` on this platform, unauthenticated session, or user-subscription limit reached) are reported with:\n\n```json\n{\n    \"type\": \"subscription_failed\",\n    \"message\": \"Error message\"\n}\n```\n\n## Testing connection state\n\nThe API allows probing the state of a connection using `ping` messages. Server will respond to `ping` messages with `pong` messages. Server will not emit `ping` messages itself.\n\nSample client implementation (ab)uses `ping` messages for measuring round-trip latency (RRT) with the server.\n\nPing message (client request)\n\n```json\n{\n    \"action\": \"ping\", \n    \"seq\": 1\n}\n```\n- `action` - (Required) - Always `\"ping\"`.\n- `seq` - (Optional) - An integer. Server will copy value of `seq` on respective `pong` message. This allows client implementations to identify the original `ping` message the server-side emitted `pong` is a response for.\n\nPong message (server response)\n\n```json\n{\n    \"type\": \"pong\", \n    \"seq\": 1\n}\n```\n\n## Update examples\n\nPopulated properties of update messages depend upon your account, connection and platform of choice. Not all properties are available for every platform/connection.\n\nFind some example messages below.\n\nOrders update example\n```json\n{\n  \"type\": \"orders\",\n  \"data\": {\n    \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\",\n    \"connection_id\": \"70818856-5c26-4734-9cf9-9432ee644ccd\",\n    \"account_id\": \"68ce9067-dcdc-4015-a3fa-2e17dfc265a5\",\n    \"order_id\": \"c22c26ed-9e67-437c-8a92-c7654d5ca444\",\n    \"account_number\": \"ABC123456\",\n    \"cl_order_id\": \"79b8b876-fd66-4fa5-af0e-b6039c90\",\n    \"platform\": \"alpaca\",\n    \"broker\": \"alpaca\",\n    \"normalized_status\": \"filled\",\n    \"broker_status\": \"filled\",\n    \"side\": \"BUY\",\n    \"order_qty\": \"2\",\n    \"order_notional\": null,\n    \"order_type\": \"MKT\",\n    \"broker_order_type\": \"market\",\n    \"order_tif\": \"DAY\",\n    \"order_limit_price\": \"0\",\n    \"symbol\": \"AAPL\",\n    \"instrument\": \"STK\",\n    \"exec_dest\": null,\n    \"entry_time\": \"2025-06-30T16:16:17.237884Z\",\n    \"last_exec_time\": \"2025-06-30T16:16:17.805369Z\",\n    \"last_modified_time\": \"2025-06-30T16:16:17.806936Z\",\n    \"stop_price\": null,\n    \"fills\": [\n      {\n        \"time\": \"2025-06-30T16:16:17.805369Z\",\n        \"quantity\": \"1\",\n        \"price\": \"200.37\",\n        \"fill_id\": \"9e00788d-f76e-4a17-b610-94270fadeef3\",\n        \"exec_dest\": null\n      }\n    ],\n    \"legs\": null,\n    \"system_time\": \"2025-06-30T16:16:18.032588Z\"\n  }\n}\n```\n\nPositions update example\n```json\n{\n  \"type\": \"positions\",\n  \"data\": [\n    {\n      \"connection_id\": \"70818856-5c26-4734-9cf9-9432ee644ccd\",\n      \"account_id\": \"68ce9067-dcdc-4015-a3fa-2e17dfc265a5\",\n      \"account_number\": \"ABC123456\",\n      \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\",\n      \"symbol\": \"AAPL\",\n      \"quantity\": \"624\",\n      \"last_price\": \"200.365\",\n      \"position_average_price\": \"201.728542\",\n      \"unrealized_pl\": \"-850.850001\",\n      \"realized_pl\": null,\n      \"daily_pl\": \"-446.16\",\n      \"total_pl\": \"-850.850001\",\n      \"system_time\": \"2025-06-30T16:16:36.032044Z\"\n    },\n    {\n      \"connection_id\": \"70818856-5c26-4734-9cf9-9432ee644ccd\",\n      \"account_id\": \"68ce9067-dcdc-4015-a3fa-2e17dfc265a5\",\n      \"account_number\": \"ABC123456\",\n      \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\",\n      \"symbol\": \"TSLA\",\n      \"quantity\": \"9\",\n      \"last_price\": \"322.26\",\n      \"position_average_price\": \"325.918889\",\n      \"unrealized_pl\": \"-32.93\",\n      \"realized_pl\": null,\n      \"daily_pl\": \"-12.33\",\n      \"total_pl\": \"-32.93\",\n      \"system_time\": \"2025-06-30T16:16:36.032251Z\"\n    }\n  ]\n}\n```\n\nBalance update example\n```json\n{\n  \"type\": \"balances\",\n  \"data\": {\n    \"account_number\": \"ABC123456\",\n    \"connection_id\": \"e7a6cff6-51ed-4559-9439-26c12bcff8cc\",\n    \"account_id\": \"2ef4c1f3-3105-41cb-87ab-c5051cf56512\",\n    \"user_id\": \"newuse011\",\n    \"currency_code\": \"USD\",\n    \"cash\": \"-89868.27\",\n    \"buying_power\": \"10078.6\",\n    \"initial_margin\": \"94907.57\",\n    \"maintenance_margin\": \"57234.38\",\n    \"reg_t_buying_power\": \"10078.6\",\n    \"system_time\": \"2025-06-30T16:14:15.312567Z\"\n  }\n}\n```\n"
    },
    {
      "name": "Streaming Market Data API",
      "description": "Connect Trade provides a WebSocket Market Data API for retrieving real-time and historical market data.\n\nThe Market Data API is available at `wss://mdstream.connecttrade.com` and uses JSON-encoded messages for communication.\n\n**Important**: Authentication for the Market Data API is per user and per user connection. Each connection represents a \nuser's authenticated link to a specific broker that provides market data to the user. The `connection_id` specifies which\nbroker the market data will be retrieved from. The platform requests market data on behalf of the user by first obtaining \nan access token for a specific connection, then uses that token to authenticate the WebSocket connection for retrieving\nmarket data.\n\nAfter opening the websocket connection, the client must authenticate using the previously acquired access token. Following \nsuccessful authentication, the client can then `subscribe` to market data feeds for receiving real-time market data updates, \nor send `snapshot` messages for retrieving historical market data.\n\n\n## Session workflow\n\n1. Obtain an access token for the user connection by calling `GET https://api.connecttrade.com/connections/{connection_id}/token`\n2. Connect to `wss://mdstream.connecttrade.com`\n3. Send an `authenticate` message using the access token. The connection will be terminated if the client is not authenticated within 30 seconds of establishing the connection.\n4. Send a `subscribe` message to subscribe to market data streams, or a `snapshot` message to retrieve historical market data.\n5. Receive updates for the subscribed symbols or responses to historical market data requests.\n\n## Authentication\n\nAn `authenticate` message is the only allowed message type for newly established connections. Any other message type will be rejected during this phase.\n\nAuthentication must occur within the first 30 seconds of establishing a connection. The server will terminate unauthenticated connections after this period.\n\nTo authenticate, you need to provide an `access_token` obtained from the connections token endpoint.\n\n## Obtaining an access token\n\nBefore connecting to the Market Data API WebSocket, obtain an access token for the specific user and connection by calling the following REST endpoint:\n\n```\nGET https://api.connecttrade.com/connections/{connection_id}/token\n```\n\nThe following headers must be provided:\n- `client-id`\n- `client-secret`\n- `user-id`\n- `user-secret`\n\nThis endpoint returns an access token that can be used to authenticate WebSocket connections on behalf of the user for retrieving market data from the \nbroker associated with the specified connection. Generated access token is valid for 24 hours and a new one must be obtained after (or before) it expires. \nGenerating a new token invalidates all previously generated tokens.\n\nWhile generating a new token invalidates any previously generated tokens (they cannot any more be used for authenticating further websocket connections), it \ndoes not invalidate (force disconnection of) currently established websocket connections/subscriptions that authenticated using a previously generated access \ntoken.\n\nInstead, any currently authenticated (and still running) websocket connections, which authenticated using a now outdated access token, will be forcefully \ndisconnected by the server upon the first use of the newly generated access token. This behaviour enables the platform to obtain and distribute the new \naccess token, without disrupting existing websocket connections in the process. Previously established websocket connections will be forcefully terminated \nonly after the new access token is used for the first time, allowing for a smoother end-user experience.\n\n**Important**: A platform user with more than one broker connections can have as many valid and non-expired access tokens as the broker connections available. \nHowever, only one of his access tokens can be in use at any one time. Each user, regardless of the count of available broker connections, can only be \nactively consuming market data originating from a single source/broker. Every time a user authenticates using an access token, the server forcefully disconnects\nany websocket connections that use a different access token, even if that other access token is still valid, non-expired and still usable.\n\n\n## Authenticate message\n\nOnce you have acquired an access token, use it to authenticate the WebSocket connection:\n\n```json\n{\n    \"action\": \"authenticate\", \n    \"access_token\": \"user-access-token\", \n    \"request_id\": \"unique-request-id\",\n    \"version\": \"v1.0\"\n}\n```\n- `action` - (Required) - Needs to be `\"authenticate\"`.\n- `access_token` - (Required) - The access token obtained from the connections token endpoint.\n- `request_id` - (Required) - A unique identifier for this request, useful for tracking and debugging.\n- `version` - (Optional) - The desired protocol version. If provided, server will try to match requested version of the API. Provided for backwards compatibility. Currently, only supported value is `\"v1.0\"`.\n\n**Important**: A platform user can have multiple websocket connections established, using the same access token. However, all connections must \noriginate from the same IP address. Every time a user authenticates from an IP address, the server forcefully disconnects any other websocket \nconnections of the user that originate from a different IP address.\n\n\nSuccessful authentication\n\n```json\n{\n    \"type\": \"auth_success\", \n    \"message\": \"Authentication successful\", \n    \"request_id\": \"unique-request-id\",\n    \"session_id\": \"1e04d508-7795-4a5e-8693-2423e957061d\",\n    \"version\": \"v1.0\"\n}\n```\n\nUnsuccessful authentication\n\n```json\n{\n    \"type\": \"error\",\n    \"error_code\": \"auth_error\",\n    \"request_id\": \"unique-request-id\",\n    \"message\": \"<Failure reason>\"\n}\n```\n\n## Subscribing\n\nSubscribing to market data channels is possible only after successful authentication.\n\nBars subscription message\n\n```json\n{\n    \"action\": \"subscribe\", \n    \"channel\": \"bars\",\n    \"symbol\": \"AAPL\",\n    \"interval\": \"1m\",\n    \"session\": \"USEqCore\",\n    \"request_id\": \"unique-request-id\",\n    \"backfill_nbars\": 60\n}\n```\n\nTrades subscription message\n\n```json\n{\n    \"action\": \"subscribe\", \n    \"channel\": \"trades\",\n    \"symbol\": \"AAPL\",\n    \"session\": \"USEqCore\",\n    \"request_id\": \"unique-request-id\",\n}\n```      \n\nQuotes subscription message\n\n```json\n{\n    \"action\": \"subscribe\", \n    \"channel\": \"quotes\",\n    \"symbol\": \"AAPL\",\n    \"request_id\": \"unique-request-id\",\n}\n```   \n\nDepth (Level 2) subscription message\n\n```json\n{\n    \"action\": \"subscribe\", \n    \"channel\": \"depth\",\n    \"symbol\": \"MSFT\",\n    \"n_levels\": 2,\n    \"request_id\": \"unique-request-id\",\n}\n```   \n\nOptions Chain subscription message\n\n```json\n{\n    \"action\": \"subscribe\", \n    \"channel\": \"options_chain\",\n    \"symbol\": \"AAPL\",\n    \"greeks\": true,\n    \"expiration\": \"2026-01-30\",\n    \"request_id\": \"unique-request-id\",\n}\n```   \n\n- `action` - (Required) - Needs to be `\"subscribe\"`.\n- `channel` - (Required) - The market data channel to subscribe to. Available values are `\"bars\"`, `\"trades\"`, `\"quotes\"`, `\"depth\"` and `\"options_chain\"`.\n- `symbol` - (Required) - The market symbol to receive data for.\n- `interval` - (Optional) - Required when `channel` is `\"bars\"`. The time interval for the data. Format is a number followed by a unit: `m` for minute, `d` for day, `M` for month, `y` for year. Examples: `\"1m\"`, `\"5m\"`, `\"1d\"`, `\"1M\"`, `\"1y\"`.\n- `session` - (Optional) - Available only for `\"bars\"` and `\"trades\"`. Market data session to subscribe to. Defaults to `\"BrokerDefault\"` if not provided. Ignored for non-equity symbols. \n  Available values are:\n  - `\"BrokerDefault\"`: Whatever session is the default for this broker.\n  - `\"USEqCore\"`: Core/cash session data only.\n  - `\"USEqPreMkt\"`: Pre-market and core/cash session data.\n  - `\"USEqPostMkt\"`: Core/cash and post-market session data.\n  - `\"USEqPreAndPostMkt\"`: Pre-market, core/cash and post-market session data.\n  - `\"USEq24Hour\"`: 24 hours data.\n- `request_id` - (Required) - A unique identifier for this request, useful for tracking and debugging.\n- `backfill_nbars` - (Optional) - Only available for `\"bars\"`. Number of past bars to return. Each broker has different limits on how many bars can be requested for the specified `interval` value.\n  Defaults to `0` if not specified.\n- `n_levels` - (Optional) - Only available for `\"depth\"`. Number of price levels to receive for both bid and ask sides. Must be between 1 and 10.\n  Defaults to `5` if not specified.\n- `greeks` - (Optional) - Only available for `\"options_chain\"`. When set to `true`, the response will include Greek values (delta, gamma, theta, vega, rho) for each option in the chain.\n  Defaults to `false` if not specified.\n- `expiration` - (Required) - Only available for `\"options_chain\"`. The expiration date of the options to include in the chain, in `YYYY-MM-DD` format.\n\n**Notes**:\n1. Not all brokers offer all possible `interval` combinations.\n2. Not all brokers offer all possible `session` values.\n\nSuccessful subscription response\n\n```json\n{\n    \"type\": \"subscription_success\",\n    \"message\": \"Subscription successful\",\n    \"broker\": \"alpaca\",\n    \"channel\": \"bars\",\n    \"symbol\": \"AAPL\",\n    \"interval\": \"1m\",\n    \"session\": \"USEqCore\",\n    \"request_id\": \"unique-request-id\",\n    \"sub_id\": \"1\"\n}\n```\n\n- `type` - Response type: `\"subscription_success\"`.\n- `message` - Confirmation text message.\n- `broker` - The broker for the subscription.\n- `channel` - The market data channel subscribed to.\n- `symbol` - The symbol subscribed to.\n- `interval` - The time interval for the subscription. Only populated when `channel` is `\"bars\"`.\n- `session` - The trading session this subscription will be providing data from. Only populated when `channel` is `\"bars\"` or `\"trades\"`.\n- `request_id` - The request ID from the original subscription request.\n- `sub_id` - Unique subscription identifier assigned by the server (auto-incremented integer).\n\n**Note**: `backfill_nbars` is not considered part of the subscription. It is not returned as part of the `subscription_success` message, nor is listed within `subscriptions_list` messages.\n\nAfter subscribing, you will start receiving real-time updates for the specified channel, symbol and interval (where applicable).\n\nBar update example\n```json\n{\n  \"o\": \"200.00\",\n  \"h\": \"201.00\",\n  \"l\": \"199.50\",\n  \"c\": \"200.37\",\n  \"v\": \"1500\",\n  \"ts\": \"1767991120000000000\",\n  \"st\": \"c\",\n  \"sub_id\": \"1\"\n}\n```\n\n- `o` - Open price.\n- `h` - High price.\n- `l` - Low price.\n- `c` - Close price.\n- `v` - Volume.\n- `ts` - Timestamp of the bar, in nanoseconds since Unix epoch.\n- `st` - Status of the bar: `\"c\"` for closed, `\"o\"` for open.\n- `sub_id` - The subscription identifier this update belongs to.\n\nTrade update example\n```json\n{\n  \"p\":\"221.12\",\n  \"s\":\"100\",\n  \"ts\":\"1767992118000000000\",\n  \"sub_id\":\"7\",\n  \"n\":\"\"\n}\n```\n\n- `p` - Trade price.\n- `s` - Trade size.\n- `n` - Venue of the trade. Not all brokers provide this information.\n- `ts` - Timestamp of the trade in the resolution provided by the broker, expressed as nanoseconds since Unix epoch.\n- `sub_id` - The subscription identifier this update belongs to.\n\nQuote update example\n```json\n{\n  \"bp\": \"213.05\",\n  \"bs\": \"100\",\n  \"ap\": \"213.38\",\n  \"as\": \"300\",\n  \"ts\": \"1767992399000000000\",\n  \"sub_id\": \"1\"\n}\n```\n\n- `bp` - Bid price.\n- `bs` - Bid size.\n- `ap` - Ask price.\n- `as` - Ask size.\n- `ts` - Timestamp of the trade in the resolution provided by the broker, expressed as nanoseconds since Unix epoch.\n- `sub_id` - The subscription identifier this update belongs to.\n\nDepth (Level 2) update example\n\n```json\n{\n  \"b\": [\n    [\"461.33\", \"40\", \"1\", \"ARCX\", \"1768478492000000000\"],\n    [\"461.25\", \"40\", \"1\", \"EDGX\", \"1768478454000000000\"],\n    [\"461.25\", \"3\", \"1\", \"NSDQ\", \"1768478414000000000\"]\n  ],\n  \"a\": [\n    [\"461.5\", \"40\", \"1\", \"ARCX\", \"1768478444000000000\"],\n    [\"461.5\", \"497\", \"1\", \"NSDQ\", \"1768478291000000000\"],\n    [\"461.62\", \"50\", \"1\", \"NSDQ\", \"1768478491000000000\"]\n  ],\n  \"sub_id\": \"1\"\n}\n```\n\n- `type` - Update type: `\"depth_update\"`.\n- `b` - Array of bid levels. Each level is an array containing:\n  - `[0]` - Price.\n  - `[1]` - Size (number of shares).\n  - `[2]` - Number of orders.\n  - `[3]` - Exchange code.\n  - `[4]` - Timestamp in nanoseconds since Unix epoch.\n- `a` - Array of ask levels. Same structure as bid levels.\n- `sub_id` - The subscription identifier this update belongs to.\n\nOptions Chain update example\n\n```json\n{\n  \"delta\": \"-0.2115\",\n  \"gamma\": \"0.0171\",\n  \"theta\": \"-0.1537\",\n  \"rho\": \"-0.0241\",\n  \"vega\": \"0.1545\",\n  \"iv\": \"0.3176\",\n  \"ask\": \"2.1\",\n  \"bid\": \"1.98\",\n  \"mid\": \"2.04\",\n  \"ask_size\": \"20\",\n  \"bid_size\": \"11\",\n  \"close\": \"2.23\",\n  \"high\": \"2.91\",\n  \"last\": \"2.23\",\n  \"low\": \"1.97\",\n  \"net_change\": \"0.12\",\n  \"net_change_pct\": \"0.0569\",\n  \"open\": \"2.33\",\n  \"previous_close\": \"2.11\",\n  \"volume\": \"121\",\n  \"side\": \"Put\",\n  \"legs\": [\n    {\n      \"sym\": \"AAPL 260130P247.5\",\n      \"strike_price\": \"247.5\",\n      \"expiration\": \"2026-01-30T00:00:00Z\",\n      \"option_type\": \"Put\",\n      \"asset_type\": \"StockOption\"\n    }\n  ],\n  \"sub_id\": \"1\"\n}\n```\n\n- `delta` - The rate of change of the option value with respect to changes in the underlying asset's price.\n- `gamma` - The rate of change in delta over time.\n- `theta` - The measure of time decay of the option.\n- `rho` - The rate of change of the option value with respect to interest rates.\n- `vega` - The measure of an option's sensitivity to volatility.\n- `iv` - Implied volatility.\n- `ask` - Ask price.\n- `bid` - Bid price.\n- `mid` - Mid price between bid and ask.\n- `ask_size` - Ask size.\n- `bid_size` - Bid size.\n- `close` - Closing price.\n- `high` - High price of the session.\n- `last` - Last traded price.\n- `low` - Low price of the session.\n- `net_change` - Net change from previous close.\n- `net_change_pct` - Net change percentage from previous close.\n- `open` - Opening price.\n- `previous_close` - Previous session's closing price.\n- `volume` - Trading volume.\n- `side` - Option side (`\"Put\"`, `\"Call\"` or `\"Both\"`).\n- `legs` - Array of option leg details.\n  - `sym` - Option symbol.\n  - `strike_price` - Strike price of the option.\n  - `expiration` - Expiration date and time in ISO 8601 format.\n  - `option_type` - Type of option (`\"Put\"` or `\"Call\"`).\n  - `asset_type` - Asset type.\n- `sub_id` - The subscription identifier this update belongs to.\n\n\n## List active subscriptions\n\nTo list your active subscriptions, send the following message:\n\n```json\n{\n    \"action\": \"list_subscriptions\", \n    \"request_id\": \"unique-request-id\"\n}\n```\n\n- `action` - (Required) - Needs to be `\"list_subscriptions\"`.\n- `request_id` - (Required) - A unique identifier for this request.\n\nSuccessful response\n\n```json\n{\n    \"type\": \"subscriptions_list\", \n    \"subscriptions\": [\n        {\n            \"broker\": \"TRADESTATION\",\n            \"channel\": \"bars\",\n            \"symbol\": \"AAPL\",\n            \"interval\": \"1m\",\n            \"session\": \"USEqCore\",\n            \"sub_id\": \"1\"\n        },\n        {\n            \"broker\": \"TRADESTATION\",\n            \"channel\": \"bars\",\n            \"symbol\": \"TSLA\",\n            \"interval\": \"5m\",\n            \"session\": \"USEqCore\",\n            \"sub_id\": \"2\"\n        },\n        {\n            \"broker\": \"TRADESTATION\",\n            \"channel\": \"trades\",\n            \"symbol\": \"AMD\",\n            \"interval\": \"\",\n            \"session\": \"USEq24Hour\",\n            \"sub_id\":\"3\"\n        },\n        {\n            \"broker\": \"TRADESTATION\",\n            \"channel\": \"quotes\",\n            \"symbol\": \"MSFT\",\n            \"interval\": \"\",\n            \"session\": \"\",\n            \"sub_id\":\"4\"\n        }              \n    ],\n    \"request_id\": \"unique-request-id\",\n    \"version\": \"v1.0\"\n}\n```\n\n- `type` - Response type: `\"subscriptions_list\"`.\n- `subscriptions` - Array of active subscriptions.\n  - `broker` - The broker for the subscription.\n  - `channel` - The market data channel (e.g., `\"bars\"`).\n  - `symbol` - The symbol being subscribed to.\n  - `interval` - The time interval for the subscription. Always empty for trade and quote subscriptions.\n  - `session` - The trading session this subscription provides data from. Always empty for quote subscriptions.\n  - `sub_id` - Unique subscription identifier (auto-incremented by server).\n- `request_id` - The request ID from the original request.\n- `version` - The API version.\n\n## Unsubscribing\n\nTo unsubscribe from a market data feed, send the following message:\n\n```json\n{\n    \"action\": \"unsubscribe\", \n    \"sub_id\": \"1\",\n    \"request_id\": \"unique-request-id\"\n}\n```\n\n- `action` - (Required) - Needs to be `\"unsubscribe\"`.\n- `sub_id` - (Required) - The subscription identifier assigned by the server to the subscription.\n- `request_id` - (Required) - A unique identifier for this request.\n\nSuccessful unsubscription\n\n```json\n{\n    \"type\": \"unsubscription_success\", \n    \"message\": \"Unsubscription successful\",\n    \"broker\": \"TRADESTATION\",\n    \"channel\": \"bars\",\n    \"symbol\": \"AAPL\",\n    \"interval\": \"1m\",\n    \"session\": \"USEqCore\",\n    \"request_id\": \"unique-request-id\",\n    \"sub_id\": \"1\"\n}\n```\n\n- `type` - Response type: `\"unsubscription_success\"`.\n- `message` - Confirmation message.\n- `broker` - The broker for the unsubscribed feed.\n- `channel` - The market data channel that was unsubscribed from.\n- `symbol` - The symbol that was unsubscribed from.\n- `interval` - The time interval that was unsubscribed from. Always empty for trade, quote and options_chain subscriptions.\n- `session` - The trading session the subscription provided data from. Always empty for quote and options_chain subscriptions.\n- `request_id` - The request ID from the original request.\n- `sub_id` - The subscription identifier that was removed (originally assigned by the server).\n\n## Requesting historical market data\n\nBars snapshot request\n\nTo retrieve historical bar data for a specific time range, send the following message:\n\n```json\n{\n    \"action\": \"snapshot\",\n    \"request_id\": \"unique-request-id\",\n    \"symbol\": \"AAPL\",\n    \"start_time\": \"2025-06-30T09:30:00Z\",\n    \"end_time\": \"2025-06-30T16:00:00Z\",\n    \"data_type\": \"bars\",\n    \"interval\": \"1m\"\n}\n```\n\n- `action` - (Required) - Needs to be `\"snapshot\"`.\n- `request_id` - (Required) - A unique identifier for this request.\n- `symbol` - (Required) - The market symbol to retrieve data for.\n- `start_time` - (Required) - The start time for the historical data range in ISO 8601 format (UTC).\n- `end_time` - (Required) - The end time for the historical data range in ISO 8601 format (UTC).\n- `data_type` - (Required) - The type of data to retrieve. Currently supported value is `\"bars\"`.\n- `interval` - (Required) - The time interval for the bars. Format is a number followed by a unit: `m` for minute, `d` for day, `M` for month, `y` for year.\n\nBars snapshot response\n\n```json\n{\n    \"type\": \"snapshot\",\n    \"action\": \"snapshot\",\n    \"request_id\": \"unique-request-id\",\n    \"symbol\": \"AAPL\",\n    \"data_type\": \"bars\",\n    \"interval\": \"1m\",\n    \"start_time\": \"2025-06-30T09:30:00Z\",\n    \"end_time\": \"2025-06-30T16:00:00Z\",\n    \"data\": [\n        {\n            \"ev\": \"b\",\n            \"o\": \"200.00\",\n            \"h\": \"201.00\",\n            \"l\": \"199.50\",\n            \"c\": \"200.37\",\n            \"v\": \"1500\",\n            \"ts\": \"1749807000000000000\",\n            \"st\": \"c\"\n        },\n        {\n            \"ev\": \"b\",\n            \"o\": \"200.37\",\n            \"h\": \"201.50\",\n            \"l\": \"200.00\",\n            \"c\": \"201.25\",\n            \"v\": \"2100\",\n            \"ts\": \"1749807060000000000\",\n            \"st\": \"c\"\n        }\n    ]\n}\n```\n\n- `type` - Response type: `\"snapshot\"`.\n- `action` - The action that was performed: `\"snapshot\"`.\n- `request_id` - The request ID from the original request.\n- `symbol` - The symbol for the returned data.\n- `data_type` - The type of data returned: `\"bars\"`.\n- `interval` - The time interval for the bars.\n- `start_time` - The start time of the requested range.\n- `end_time` - The end time of the requested range.\n- `data` - Array of historical bar data. Each bar contains:\n  - `ev` - Event type: `\"b\"` for bar.\n  - `o` - Open price.\n  - `h` - High price.\n  - `l` - Low price.\n  - `c` - Close price.\n  - `v` - Volume.\n  - `ts` - Timestamp of the bar.\n  - `st` - Status of the bar: `\"c\"` for closed.\n"
    },
    {
      "name": "Order examples",
      "description": "**Market order**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid1\",\n  \"broker\": \"LIGHTSPEED\",\n  \"side\": \"BUY\",\n  \"order_qty\": \"1\",\n  \"order_type\": \"MKT\",\n  \"order_tif\": \"DAY\",\n  \"instrument\": \"STK\",\n  \"symbol\": \"NOK\"\n}\n```\n\n**Limit order**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid2\",\n  \"broker\": \"LIGHTSPEED\",\n  \"side\": \"BUY\",\n  \"order_qty\": \"1\",\n  \"order_type\": \"LMT\",\n  \"order_limit_price\": \"4.75\",\n  \"order_tif\": \"DAY\",\n  \"instrument\": \"STK\",\n  \"symbol\": \"NOK\"\n}\n```\n\n**Stop limit order**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid3\",\n  \"broker\": \"TRADEZERO\",\n  \"side\": \"SELL\",\n  \"instrument\": \"STK\",\n  \"order_qty\": \"10\",\n  \"order_type\": \"STPLMT\",\n  \"order_limit_price\": \"6.50\",\n  \"stop_price\": \"6.60\",\n  \"order_tif\": \"DAY\",\n  \"symbol\": \"NOK\"\n}\n\n**GTC order**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid4\",\n  \"broker\": \"WEBULL\",\n  \"side\": \"BUY\",\n  \"instrument\": \"STK\",\n  \"order_qty\": \"1\",\n  \"order_type\": \"LMT\",\n  \"order_limit_price\": \"432.11\",\n  \"order_tif\": \"GTC\",\n  \"symbol\": \"TSLA\"\n}\n```\n\n**Single leg option order**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid5\",\n  \"broker\": \"WEBULL\",\n  \"side\": \"BUY_TO_OPEN\",\n  \"instrument\": \"OPT\",\n  \"order_qty\": \"1\",\n  \"order_type\": \"LMT\",\n  \"order_limit_price\": \"13.50\",\n  \"order_tif\": \"GTC\",\n  \"symbol\": \"TSLA251031C00437500\"\n}\n```\n\n## Multileg orders\n\n**Multileg order with a 2:1 ratio** \n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid6\",\n  \"broker\": \"ALPACA\",\n  \"order_type\": \"LMT\",\n  \"order_tif\": \"DAY\",\n  \"symbol\": null,\n  \"instrument\": \"MLEG_OPT\",\n  \"order_qty\": \"10\",\n  \"order_limit_price\": \"21.50\",\n  \"legs\": [\n    {\"symbol\": \"AAPL251121C00276500\", \"action\": \"BUY_TO_OPEN\", \"ratio\": \"2\"},\n    {\"symbol\": \"AAPL251128C00275000\", \"action\": \"BUY_TO_OPEN\", \"ratio\": \"1\"}\n  ]\n}\n```\n\n**Long Straddle**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid7\",\n  \"broker\": \"ALPACA\",\n  \"order_type\": \"LMT\",\n  \"order_tif\": \"DAY\",\n  \"symbol\": null,\n  \"instrument\": \"MLEG_OPT\",\n  \"order_qty\": \"10\",\n  \"order_limit_price\": \"2.50\",\n  \"legs\": [\n    {\"symbol\": \"AAPL241018C00190000\", \"action\": \"BUY_TO_OPEN\", \"ratio\": \"1\"},\n    {\"symbol\": \"AAPL241018P00190000\", \"action\": \"BUY_TO_OPEN\", \"ratio\": \"1\"}\n  ]\n}\n```\n\n**Bull Call Spread**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid8\",\n  \"broker\": \"TRADEZERO\",\n  \"order_type\": \"LMT\",\n  \"order_tif\": \"DAY\",\n  \"symbol\": null,\n  \"instrument\": \"MLEG_OPT\",\n  \"order_qty\": \"20\",\n  \"order_limit_price\": \"0.75\",\n  \"legs\": [\n    {\"symbol\": \"SPY241018C00430000\", \"action\": \"BUY_TO_OPEN\", \"ratio\": \"1\"},\n    {\"symbol\": \"SPY241018C00440000\", \"action\": \"SELL_TO_OPEN\", \"ratio\": \"1\"}\n  ]\n}\n```\n\n**Closing a Bull Call Spread**\n```json\n{\n  \"account_id\": \"ABC123\",\n  \"cl_order_id\": \"clordid9\",\n  \"broker\": \"TRADEZERO\",\n  \"order_type\": \"LMT\",\n  \"order_tif\": \"DAY\",\n  \"symbol\": null,\n  \"instrument\": \"MLEG_OPT\",\n  \"order_qty\": \"20\",\n  \"order_limit_price\": \"0.75\",\n  \"legs\": [\n    {\"symbol\": \"SPY241018C00430000\", \"action\": \"SELL_TO_CLOSE\", \"ratio\": \"1\"},\n    {\"symbol\": \"SPY241018C00440000\", \"action\": \"BUY_TO_CLOSE\", \"ratio\": \"1\"}\n  ]\n}\n```\n"
    }
  ],
  "paths": {
    "/users": {
      "get": {
        "tags": [
          [
            "Users"
          ]
        ],
        "summary": "Get users",
        "description": "Retrieves users with optional filtering, sorting, and cursor pagination.",
        "parameters": [
          {
            "in": "query",
            "name": "user_id",
            "schema": {
              "type": "string"
            },
            "description": "Return only the user with this user ID",
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          },
          {
            "in": "query",
            "name": "account_number",
            "schema": {
              "type": "string"
            },
            "description": "Return users connected to this broker account number",
            "example": "ABC123456"
          },
          {
            "in": "query",
            "name": "account_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Return users associated with this account ID",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          {
            "in": "query",
            "name": "connection_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Return users associated with this connection ID",
            "example": "1f99726b-26de-44b8-a634-213b34313344"
          },
          {
            "in": "query",
            "name": "start_time",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Return users created from this timestamp (ISO 8601 format)",
            "example": "2026-04-01T00:00:00Z"
          },
          {
            "in": "query",
            "name": "end_time",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Return users created up to this timestamp (ISO 8601 format)",
            "example": "2026-05-01T00:00:00Z"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 100
            },
            "description": "Maximum number of users to return",
            "example": 100
          },
          {
            "in": "query",
            "name": "next_cursor",
            "schema": {
              "type": "string"
            },
            "description": "Cursor for forward pagination. Pass the next_cursor value from the previous response to retrieve the next set of results. Mutually exclusive with prev_cursor—only one cursor parameter may be supplied per request.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          {
            "in": "query",
            "name": "prev_cursor",
            "schema": {
              "type": "string"
            },
            "description": "Cursor for backward pagination. Pass the prev_cursor value from the current response to retrieve the previous set of results. Mutually exclusive with next_cursor—only one cursor parameter may be supplied per request.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          {
            "in": "query",
            "name": "sort",
            "schema": {
              "type": "string",
              "default": "created_at:desc"
            },
            "description": "Sort parameter (field:direction). Only a single sort field is allowed at a time.\n\nSupported sorting fields are:\n  - \"created_at\" (the time the user was created)\n  - \"user_id\"\n",
            "example": "created_at:desc"
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/users?account_number=ABC123456&limit=50&sort=created_at:desc' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "List of users with pagination cursors",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserListResponse"
                },
                "example": {
                  "data": [
                    {
                      "user_id": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
                    }
                  ],
                  "next_cursor": "eyJjcmVhdGVkX2F0IjoiMjAyNi0wNC0xNVQxMjowMDowMCswMDowMCIsIl9pZCI6IjY2MWYwMDAwMDAwMDAwMDAwMDAwMDAwMCJ9",
                  "prev_cursor": null
                }
              }
            }
          },
          "400": {
            "description": "Bad request - Platform ID not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "422": {
            "description": "Validation error - invalid query parameter, cursor, or limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unsupported query parameter: active"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          [
            "Users"
          ]
        ],
        "summary": "Create a new user",
        "description": "Creates a new user and generates a user secret for authentication",
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request POST \\\n--url 'https://api.connecttrade.com/users' \\\n--header 'Content-Type: application/json' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--data '{\n  \"user_id\": \"76873239-50c7-4b1c-bb1f-7dc2c9a3af36\"\n}'\n"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User successfully created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserCreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - Invalid request data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Invalid request."
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "409": {
            "description": "Conflict - User already exists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "User already exists"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Failed to create user"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          [
            "Users"
          ]
        ],
        "summary": "Delete a user",
        "description": "Permanently delete a user from the platform using their unique identifier (hard delete).",
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request DELETE \\\n--url 'https://api.connecttrade.com/users/76873239-50c7-4b1c-bb1f-7dc2c9a3af36' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET'\n"
          }
        ],
        "parameters": [
          {
            "name": "user_id",
            "in": "path",
            "required": true,
            "description": "The unique identifier for the user in the external platform",
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          }
        ],
        "responses": {
          "200": {
            "description": "User successfully deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserDeleteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - Invalid user ID or user not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Failed to delete user"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Failed to delete user"
                }
              }
            }
          }
        }
      }
    },
    "/users/{user_id}/rotate-secret": {
      "post": {
        "tags": [
          [
            "Users"
          ]
        ],
        "summary": "Rotate user secret",
        "description": "Generates a new secret for the specified user",
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request POST \\\n--url 'https://api.connecttrade.com/users/76873239-50c7-4b1c-bb1f-7dc2c9a3af36/rotate-secret' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET'\n"
          }
        ],
        "parameters": [
          {
            "name": "user_id",
            "in": "path",
            "required": true,
            "description": "The unique identifier for the user in the external platform",
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          }
        ],
        "responses": {
          "200": {
            "description": "User secret successfully rotated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserSecretRotateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - Invalid user ID",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Invalid request."
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "User not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "User not found"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error."
                }
              }
            }
          }
        }
      }
    },
    "/connections": {
      "get": {
        "tags": [
          [
            "Connections"
          ]
        ],
        "summary": "Get all connections",
        "description": "Retrieves all connections for the authenticated platform",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/connections' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully retrieved connections",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ConnectionResponse"
                  }
                },
                "example": [
                  {
                    "connection_id": "7fe430be-4b21-4e34-b335-3480017a7165",
                    "user_id": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36",
                    "broker": "ALPACA",
                    "accounts": [
                      {
                        "account_id": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df",
                        "account_number": "ABC123456"
                      }
                    ],
                    "connection_type": "readonly",
                    "created_at": "2025-06-27T15:42:26.723000Z",
                    "updated_at": "2025-06-27T16:02:50.184000Z"
                  },
                  {
                    "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                    "user_id": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36",
                    "broker": "ALPACA",
                    "accounts": [
                      {
                        "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                        "account_number": "ABC123456"
                      }
                    ],
                    "connection_type": "trade",
                    "created_at": "2025-06-27T16:04:36.090000Z",
                    "updated_at": "2025-06-27T16:04:36.090000Z"
                  }
                ]
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          [
            "Connections"
          ]
        ],
        "summary": "Create a new connection url",
        "description": "Creates a new brokerage connection URL for a user. Use this URL to initiate the connection process.\n\nAfter a successful connection, the system redirects to the redirect_url and includes the newly created connection_id as a URL parameter.\n\nExample (success):\nhttps://example.com/callbacks/success?connection_id=7fe430be-4b21-4e34-b335-3480017a7165\n\nIf redirect_url is not provided, the user will remain on the Connect Trade platform.\n\nIf an error occurs, the system redirects to redirect_on_error_url (or to redirect_url if redirect_on_error_url is not provided) and includes error details as URL parameters.\n\nExample (error):\nhttps://example.com/callbacks/error?error=401&error_details=Unauthorized\n",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request POST \\\n--url 'https://api.connecttrade.com/connections' \\\n--header 'Content-Type: application/json' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET' \\\n--data '{\n  \"connection_type\": \"trade\",\n  \"redirect_url\": \"https://example.com/callbacks/alpaca\",\n  \"broker\": \"ALPACA\"\n}'\n"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConnectionCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection successfully created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionCreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - Invalid request data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Invalid request data"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "409": {
            "description": "Conflict - Connection already exists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Connection already exists"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Failed to create connection"
                }
              }
            }
          }
        }
      }
    },
    "/connections/{connection_id}": {
      "get": {
        "tags": [
          [
            "Connections"
          ]
        ],
        "summary": "Get a specific connection",
        "description": "Retrieves a specific connection by its ID",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "parameters": [
          {
            "name": "connection_id",
            "in": "path",
            "required": true,
            "description": "The unique identifier for the connection",
            "schema": {
              "type": "string"
            },
            "example": "7fe430be-4b21-4e34-b335-3480017a7165"
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/connections/7fe430be-4b21-4e34-b335-3480017a7165' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully retrieved connection",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionResponse"
                },
                "example": {
                  "connection_id": "7fe430be-4b21-4e34-b335-3480017a7165",
                  "user_id": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36",
                  "broker": "ALPACA",
                  "accounts": [
                    {
                      "account_id": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df",
                      "account_number": "ABC123456"
                    }
                  ],
                  "connection_type": "readonly",
                  "created_at": "2025-06-27T15:42:26.723000Z",
                  "updated_at": "2025-06-27T16:02:50.184000Z"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Connection not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Connection not found"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          [
            "Connections"
          ]
        ],
        "summary": "Delete a connection",
        "description": "Deletes a brokerage connection",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request DELETE \\\n--url 'https://api.connecttrade.com/connections/7fe430be-4b21-4e34-b335-3480017a7165' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "parameters": [
          {
            "name": "connection_id",
            "in": "path",
            "required": true,
            "description": "The unique identifier for the connection",
            "schema": {
              "type": "string"
            },
            "example": "c9ae2870-476c-465d-b583-8f00b09a2686"
          }
        ],
        "responses": {
          "200": {
            "description": "Connection successfully deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionDeleteResponse"
                },
                "example": {
                  "message": "Connection deleted successfully",
                  "connection_id": "c9ae2870-476c-465d-b583-8f00b09a2686"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Connection not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Connection not found"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Failed to delete connection"
                }
              }
            }
          }
        }
      }
    },
    "/accounts": {
      "get": {
        "tags": [
          [
            "Accounts"
          ]
        ],
        "summary": "Get all accounts",
        "description": "Retrieves all broker accounts associated with all of the authenticated user’s connections.",
        "parameters": [
          {
            "name": "connection_id",
            "in": "query",
            "required": false,
            "description": "Filter accounts by connection ID",
            "schema": {
              "type": "string"
            },
            "example": "1f99726b-26de-44b8-a634-213b34313344"
          },
          {
            "name": "broker",
            "in": "query",
            "required": false,
            "description": "Filter accounts by broker/institution name",
            "schema": {
              "$ref": "#/components/schemas/BrokerQueryParam"
            },
            "example": "alpaca"
          }
        ],
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/accounts' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully retrieved accounts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/AccountResponse"
                  }
                },
                "example": [
                  {
                    "account_id": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df",
                    "connection_id": "7fe430be-4b21-4e34-b335-3480017a7165",
                    "account_name": null,
                    "account_number": "ABC123456",
                    "institution_name": "ALPACA",
                    "created_at": "2025-06-27T15:42:26.754000Z",
                    "last_update_ts": "2025-06-27T15:42:26.754000Z",
                    "historical_data_sync_complete": true
                  },
                  {
                    "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                    "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                    "account_name": null,
                    "account_number": "ABC123456",
                    "institution_name": "ALPACA",
                    "created_at": "2025-06-27T16:04:36.092000Z",
                    "last_update_ts": "2025-06-27T16:04:36.092000Z",
                    "historical_data_sync_complete": false
                  }
                ]
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{account_id}": {
      "get": {
        "tags": [
          [
            "Accounts"
          ]
        ],
        "summary": "Get a specific account",
        "description": "Retrieves a specific account by account_id",
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "description": "The unique identifier for the account",
            "schema": {
              "type": "string"
            },
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          }
        ],
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/accounts/e48f7013-55b3-472b-b7c9-c85a0d6154c6' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully retrieved account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountResponse"
                },
                "example": {
                  "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                  "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                  "account_name": null,
                  "account_number": "ABC123456",
                  "institution_name": "ALPACA",
                  "created_at": "2025-06-27T16:04:36.092000Z",
                  "last_update_ts": "2025-06-27T16:04:36.092000Z",
                  "historical_data_sync_complete": true
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Account not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Account not found"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      }
    },
    "/balances": {
      "get": {
        "tags": [
          [
            "Balances"
          ]
        ],
        "summary": "Get all account balances",
        "description": "Retrieves balance information for all accounts associated with the authenticated platform for a connected broker account. Can be filtered by connection ID and/or account ID.",
        "parameters": [
          {
            "name": "connection_id",
            "in": "query",
            "required": false,
            "description": "Filter balances by connection_id",
            "schema": {
              "type": "string"
            },
            "example": "7fe430be-4b21-4e34-b335-3480017a7165"
          },
          {
            "name": "account_id",
            "in": "query",
            "required": false,
            "description": "Filter balances by account_id",
            "schema": {
              "type": "string"
            },
            "example": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df"
          }
        ],
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/balances' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Successfully retrieved balances",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/BalanceResponse"
                  }
                },
                "example": [
                  {
                    "account_number": "ABC123456",
                    "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                    "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                    "user_id": "newuse011",
                    "currency_code": "USD",
                    "cash": "100000",
                    "buying_power": "200000",
                    "initial_margin": "0",
                    "maintenance_margin": "0",
                    "reg_t_buying_power": "200000",
                    "system_time": "2025-06-27T17:14:37.856000Z"
                  },
                  {
                    "account_number": "ABC123456",
                    "connection_id": "7fe430be-4b21-4e34-b335-3480017a7165",
                    "account_id": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df",
                    "user_id": "newuse011",
                    "currency_code": "USD",
                    "cash": "-87142.87",
                    "buying_power": "14194.42",
                    "initial_margin": "94240.08",
                    "maintenance_margin": "56803.95",
                    "reg_t_buying_power": "14194.42",
                    "system_time": "2025-06-27T17:14:37.869000Z"
                  }
                ]
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Unauthorized"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      }
    },
    "/orders": {
      "post": {
        "tags": [
          "Orders"
        ],
        "summary": "Create a new order",
        "description": "Place a new broker order in the specified account_id.\n\nSee [order examples](#tag/Order-examples) for sample payloads.\n",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderCreateRequest"
              },
              "example": {
                "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                "cl_order_id": "8c9680a0-3a89-4c10-a093-1f14bb80",
                "broker": "ALPACA",
                "side": "BUY",
                "order_qty": "1",
                "order_type": "MKT",
                "order_tif": "DAY",
                "symbol": "MSFT"
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request POST \\\n--url 'https://api.connecttrade.com/orders' \\\n--header 'Content-Type: application/json' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET' \\\n--data '{\n  \"account_id\": \"e48f7013-55b3-472b-b7c9-c85a0d6154c6\",\n  \"cl_order_id\": \"8c9680a0-3a89-4c10-a093-1f14bb80\",\n  \"broker\": \"ALPACA\",\n  \"side\": \"BUY\",\n  \"order_qty\": \"1\",\n  \"order_type\": \"MKT\",\n  \"order_tif\": \"DAY\",\n  \"symbol\": \"MSFT\"\n}'\n"
          }
        ],
        "responses": {
          "201": {
            "description": "Order created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderCreateResponse"
                },
                "example": {
                  "user_id": "newuse011",
                  "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                  "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                  "order_id": "5008e42a-deab-4f90-914b-0bd86f7ac39e",
                  "account_number": "ABC123456",
                  "cl_order_id": "8c9680a0-3a89-4c10-a093-1f14bb80",
                  "platform": "platform_name",
                  "broker": "ALPACA",
                  "normalized_status": "pending",
                  "broker_status": "pending_new",
                  "side": "BUY",
                  "order_qty": "1",
                  "order_notional": null,
                  "order_type": "MKT",
                  "broker_order_type": "market",
                  "order_tif": "DAY",
                  "order_limit_price": "0",
                  "symbol": "MSFT",
                  "instrument": "STK",
                  "exec_dest": null,
                  "entry_time": "2025-06-27T17:22:34.454422Z",
                  "last_exec_time": null,
                  "last_modified_time": "2025-06-27T17:22:34.455936Z",
                  "stop_price": null,
                  "broker_text": null,
                  "fills": [],
                  "legs": null,
                  "system_time": "2025-06-27T17:22:34.501950Z"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Orders"
        ],
        "summary": "List orders",
        "description": "Retrieve a list of orders for a connected broker account. By default, returns all open orders for the current day.",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "connection_id",
            "schema": {
              "type": "string"
            },
            "description": "Filter by connection_id",
            "example": "1f99726b-26de-44b8-a634-213b34313344"
          },
          {
            "in": "query",
            "name": "account_id",
            "schema": {
              "type": "string"
            },
            "description": "Filter by account_id",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          {
            "in": "query",
            "name": "broker",
            "schema": {
              "type": "string"
            },
            "description": "Filter by broker",
            "example": "ALPACA"
          },
          {
            "in": "query",
            "name": "symbols",
            "schema": {
              "type": "string"
            },
            "description": "Filter by trading symbols (comma-separated list)",
            "example": "MSFT,AAPL"
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "open",
                "closed",
                "working",
                "partially_filled",
                "filled",
                "done_for_day",
                "cancelled",
                "expired",
                "pending_cancel",
                "pending_replace",
                "replaced",
                "rejected",
                "pending"
              ]
            },
            "description": "Filter by order status",
            "example": "open"
          },
          {
            "in": "query",
            "name": "side",
            "schema": {
              "type": "string",
              "enum": [
                "BUY",
                "SELL",
                "SELL_SHORT",
                "BUY_TO_OPEN",
                "BUY_TO_CLOSE",
                "SELL_TO_OPEN",
                "SELL_TO_CLOSE"
              ]
            },
            "description": "Filter by order side",
            "example": "BUY"
          },
          {
            "in": "query",
            "name": "start_time",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter orders from this timestamp (ISO 8601 format). Defaults to start of day if not provided.",
            "example": "2025-01-02T16:03:04.123456Z"
          },
          {
            "in": "query",
            "name": "end_time",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter orders up to this timestamp (ISO 8601 format)",
            "example": "2025-01-02T23:59:59.999999Z"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 50
            },
            "description": "Maximum number of orders to return",
            "example": 50
          },
          {
            "in": "query",
            "name": "next_cursor",
            "schema": {
              "type": "string"
            },
            "description": "Cursor for forward pagination. Pass the next_cursor value from the previous response to retrieve the next set of results. Mutually exclusive with prev_cursor—only one cursor parameter may be supplied per request.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          {
            "in": "query",
            "name": "prev_cursor",
            "schema": {
              "type": "string"
            },
            "description": "Cursor for backward pagination. Pass the prev_cursor value from the current response to retrieve the previous set of results. Mutually exclusive with next_cursor—only one cursor parameter may be supplied per request.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          {
            "in": "query",
            "name": "sort",
            "schema": {
              "type": "string",
              "default": "entry_time:desc"
            },
            "description": "Sort parameter (field:direction). Only a single sort field is allowed at a time.\n\nSupported sorting fields are:\n  - \"entry_time\"\n  - \"last_modified_time\"\n  - \"last_exec_time\"\n",
            "example": "entry_time:asc"
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/orders' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "List of orders with pagination cursors",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderListResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{account_id}/orders/{order_id}": {
      "get": {
        "tags": [
          "Orders"
        ],
        "summary": "Get order by account and order ID",
        "description": "Retrieve a specific order by account ID and order ID",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "account_id",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The account ID",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          {
            "in": "path",
            "name": "order_id",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The order ID",
            "example": "c98967d6-a599-42cf-9d9d-6ea048e916dc"
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/accounts/e48f7013-55b3-472b-b7c9-c85a0d6154c6/orders/c98967d6-a599-42cf-9d9d-6ea048e916dc' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Order details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderResponse"
                },
                "example": {
                  "user_id": "newuse011",
                  "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                  "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                  "order_id": "c98967d6-a599-42cf-9d9d-6ea048e916dc",
                  "account_number": "ABC123456",
                  "cl_order_id": "bce8b066-4235-4735-b610-e93a1f40",
                  "platform": "platform_name",
                  "broker": "ALPACA",
                  "normalized_status": "filled",
                  "broker_status": "filled",
                  "side": "BUY",
                  "order_qty": "1",
                  "order_notional": null,
                  "order_type": "MKT",
                  "broker_order_type": "market",
                  "order_tif": "DAY",
                  "order_limit_price": "0",
                  "symbol": "MSFT",
                  "instrument": "STK",
                  "exec_dest": null,
                  "entry_time": "2025-06-27T17:48:40.845000Z",
                  "last_exec_time": "2025-06-27T17:48:41.443000Z",
                  "last_modified_time": "2025-06-27T17:48:41.445000Z",
                  "stop_price": null,
                  "broker_text": null,
                  "fills": [
                    {
                      "time": "2025-06-27T17:48:41.443000Z",
                      "quantity": "1",
                      "price": "497.37",
                      "fill_id": "e5f6b895-3fc8-4f86-9c98-fdf84fd72aff"
                    }
                  ],
                  "legs": null,
                  "system_time": "2025-06-27T17:48:41.758000Z"
                }
              }
            }
          },
          "404": {
            "description": "Order not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                },
                "example": {
                  "message": "Order not found"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Orders"
        ],
        "summary": "Cancel order by account and order ID",
        "description": "Cancel a specific order by account ID and order ID",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "account_id",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The account ID",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          {
            "in": "path",
            "name": "order_id",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The order ID",
            "example": "c98967d6-a599-42cf-9d9d-6ea048e916dc"
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request DELETE \\\n--url 'https://api.connecttrade.com/accounts/e48f7013-55b3-472b-b7c9-c85a0d6154c6/orders/c98967d6-a599-42cf-9d9d-6ea048e916dc' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Order successfully cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderCancelResponse"
                },
                "example": {
                  "order_id": "c98967d6-a599-42cf-9d9d-6ea048e916dc",
                  "status": "cancelled",
                  "message": "Order c98967d6-a599-42cf-9d9d-6ea048e916dc successfully cancelled."
                }
              }
            }
          },
          "404": {
            "description": "Order could not be cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                },
                "example": {
                  "message": "Order with ID c98967d6-a599-42cf-9d9d-6ea048e916dc could not be cancelled."
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Orders"
        ],
        "summary": "Replace order by account and order ID",
        "description": "Replace an active order by account ID and order ID with new order parameters. This supports the modification of quantity, order_limit_price, notional and stop_price.",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "account_id",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The account ID",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          {
            "in": "path",
            "name": "order_id",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The order ID",
            "example": "c98967d6-a599-42cf-9d9d-6ea048e916dc"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderReplaceRequest"
              },
              "example": {
                "new_cl_order_id": "9d0781b1-4a9a-5d21-b704-f04a2f51",
                "broker": "ALPACA",
                "order_qty": "2",
                "order_limit_price": "500.00"
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request PATCH \\\n--url 'https://api.connecttrade.com/accounts/e48f7013-55b3-472b-b7c9-c85a0d6154c6/orders/c98967d6-a599-42cf-9d9d-6ea048e916dc' \\\n--header 'Content-Type: application/json' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET' \\\n--data '{\n  \"new_cl_order_id\": \"9d0781b1-4a9a-5d21-b704-f04a2f51\",\n  \"broker\": \"ALPACA\",\n  \"order_qty\": \"2\"\n}'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Order successfully replaced",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderCreateResponse"
                },
                "example": {
                  "user_id": "newuse011",
                  "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                  "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                  "order_id": "6a19f53b-efbc-5g01-a25e-1ce97g8bd40f",
                  "account_number": "ABC123456",
                  "cl_order_id": "9d0781b1-4a9a-5d21-b704-f04a2f51",
                  "platform": "platform_name",
                  "broker": "ALPACA",
                  "normalized_status": "working",
                  "broker_status": "pending",
                  "side": "BUY",
                  "order_qty": "2",
                  "order_notional": null,
                  "order_type": "LMT",
                  "broker_order_type": "limit",
                  "order_tif": "DAY",
                  "order_limit_price": "500.00",
                  "symbol": "MSFT",
                  "instrument": "STK",
                  "exec_dest": null,
                  "entry_time": "2025-06-27T17:48:40.845000Z",
                  "last_exec_time": null,
                  "last_modified_time": "2025-06-27T18:15:22.123000Z",
                  "stop_price": null,
                  "broker_text": null,
                  "fills": [],
                  "legs": null,
                  "system_time": "2025-06-27T18:15:22.456000Z"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                },
                "example": {
                  "message": "Invalid order replace request"
                }
              }
            }
          },
          "404": {
            "description": "Order not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                },
                "example": {
                  "message": "Order with ID c98967d6-a599-42cf-9d9d-6ea048e916dc not found"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                },
                "example": {
                  "message": "Internal server error"
                }
              }
            }
          }
        }
      }
    },
    "/positions": {
      "get": {
        "tags": [
          "Positions"
        ],
        "summary": "List positions",
        "description": "Retrieve a list of positions for a connected broker account.",
        "parameters": [
          {
            "in": "query",
            "name": "connection_id",
            "schema": {
              "type": "string"
            },
            "description": "Filter by connection ID",
            "example": "7fe430be-4b21-4e34-b335-3480017a7165"
          },
          {
            "in": "query",
            "name": "account_id",
            "schema": {
              "type": "string"
            },
            "description": "Filter by account ID",
            "example": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df"
          },
          {
            "in": "query",
            "name": "symbols",
            "schema": {
              "type": "string"
            },
            "description": "Filter by trading symbols (comma-separated list)",
            "example": "MSFT,AAPL"
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/positions?connection_id=7fe430be-4b21-4e34-b335-3480017a7165&account_id=e5ff8fd9-d0cb-4632-8823-30e60e01f7df&symbols=MSFT,AAPL' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "List of positions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/PositionResponse"
                  }
                },
                "example": [
                  {
                    "connection_id": "7fe430be-4b21-4e34-b335-3480017a7165",
                    "account_id": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df",
                    "user_id": "newuse011",
                    "account_number": "ABC123456",
                    "broker_position_id": "alpaca-AAPL-ABC123456",
                    "symbol": "AAPL",
                    "quantity": "620",
                    "last_price": "201.5",
                    "position_average_price": "201.731887",
                    "unrealized_pl": "-143.770001",
                    "daily_pl": "310",
                    "total_pl": "-143.770001",
                    "instrument": "STK",
                    "system_time": "2025-01-01T12:00:00.000000Z"
                  },
                  {
                    "connection_id": "1f99726b-26de-44b8-a634-213b34313344",
                    "account_id": "e48f7013-55b3-472b-b7c9-c85a0d6154c6",
                    "user_id": "newuse011",
                    "account_number": "ABC123456",
                    "broker_position_id": "alpaca-MSFT-ABC123456",
                    "symbol": "MSFT",
                    "quantity": "6",
                    "last_price": "496.76",
                    "position_average_price": "497.543333",
                    "unrealized_pl": "-4.7",
                    "daily_pl": "-4.699998",
                    "total_pl": "-4.7",
                    "instrument": "STK",
                    "system_time": "2025-01-01T12:00:00.000000Z"
                  }
                ]
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/positions-api_components-schemas-ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/positions-api_components-schemas-ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/positions-api_components-schemas-ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/positions-api_components-schemas-ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ]
      }
    },
    "/transactions": {
      "get": {
        "tags": [
          "Transactions"
        ],
        "summary": "List transactions",
        "description": "Retrieve a list of transactions for a connected broker account.",
        "security": [
          {
            "client-id": [],
            "client-secret": [],
            "user-id": [],
            "user-secret": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "connection_id",
            "schema": {
              "type": "string"
            },
            "description": "Filter by connection_id",
            "example": "1f99726b-26de-44b8-a634-213b34313344"
          },
          {
            "in": "query",
            "name": "account_id",
            "schema": {
              "type": "string"
            },
            "description": "Filter by account_id",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          {
            "in": "query",
            "name": "broker",
            "schema": {
              "type": "string"
            },
            "description": "Filter by broker",
            "example": "alpaca"
          },
          {
            "in": "query",
            "name": "transaction_types",
            "schema": {
              "type": "string"
            },
            "description": "Filter by transaction types (comma-separated list).\n\nAvailable transaction types: ACAT, ACCOUNT_TRANSFER, DEPOSIT, DIVIDEND, FEE, FILL, INTEREST, JOURNAL_ENTRY, MISC, OPTION_EXPIRATION, OPTION_ASSIGNMENT, OPTION_EXERCISE, REI, WITHDRAWAL\n",
            "example": "FEE,DIVIDEND"
          },
          {
            "in": "query",
            "name": "start_time",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter transactions from this timestamp (ISO 8601 format).",
            "example": "2025-01-02T16:03:04.123456Z"
          },
          {
            "in": "query",
            "name": "end_time",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter transactions up to this timestamp (ISO 8601 format)",
            "example": "2025-01-02T23:59:59.999999Z"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 50
            },
            "description": "Maximum number of transactions to return",
            "example": 50
          },
          {
            "in": "query",
            "name": "next_cursor",
            "schema": {
              "type": "string"
            },
            "description": "Cursor for forward pagination. Pass the next_cursor value from the previous response to retrieve the next set of results. Mutually exclusive with prev_cursor—only one cursor parameter may be supplied per request.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          {
            "in": "query",
            "name": "prev_cursor",
            "schema": {
              "type": "string"
            },
            "description": "Cursor for backward pagination. Pass the prev_cursor value from the current response to retrieve the previous set of results. Mutually exclusive with next_cursor—only one cursor parameter may be supplied per request.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          {
            "in": "query",
            "name": "sort",
            "schema": {
              "type": "string",
              "default": "transaction_time:desc"
            },
            "description": "Sort parameter (field:direction). Only a single sort field is allowed at a time.\n\nSupported sort fields:\n  - transaction_time\n  - trade_date\n",
            "example": "trade_date:asc"
          }
        ],
        "x-codeSamples": [
          {
            "lang": "cURL",
            "label": "Shell",
            "source": "curl --request GET \\\n--url 'https://api.connecttrade.com/transactions' \\\n--header 'client-id: YOUR_CLIENT_ID' \\\n--header 'client-secret: YOUR_CLIENT_SECRET' \\\n--header 'user-id: YOUR_USER_ID' \\\n--header 'user-secret: YOUR_USER_SECRET'\n"
          }
        ],
        "responses": {
          "200": {
            "description": "List of transactions with pagination cursors",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TransactionListResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/components-schemas-ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "client-id": {
        "type": "apiKey",
        "in": "header",
        "name": "client-id",
        "description": "The platform ID to identify the client platform"
      },
      "client-secret": {
        "type": "apiKey",
        "in": "header",
        "name": "client-secret",
        "description": "The secret key for platform authentication"
      },
      "user-id": {
        "type": "apiKey",
        "in": "header",
        "name": "user-id",
        "description": "The user ID for user-specific operations"
      },
      "user-secret": {
        "type": "apiKey",
        "in": "header",
        "name": "user-secret",
        "description": "The user secret for user authentication"
      }
    },
    "examples": {
      "LongStraddle": {
        "$ref": "./examples.yml#/components/examples/LongStraddle"
      },
      "BullCallSpread": {
        "$ref": "./examples.yml#/components/examples/BullCallSpread"
      },
      "ClosingBullCallSpread": {
        "$ref": "./examples.yml#/components/examples/ClosingBullCallSpread"
      }
    },
    "schemas": {
      "UserBase": {
        "type": "object",
        "description": "Base user model with common fields",
        "properties": {
          "id": {
            "type": "string",
            "description": "The unique identifier for the user (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439011"
          },
          "platform_id": {
            "type": "string",
            "description": "The ID of the client (platform) this user belongs to",
            "example": "platform_123"
          },
          "platform_user_id": {
            "type": "string",
            "description": "The unique identifier for the user in the external platform",
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          },
          "active": {
            "type": "boolean",
            "description": "Indicates whether the user is active or not",
            "default": true,
            "example": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the user was created (ISO format with timezone)",
            "example": "2025-06-09T10:30:00.000Z"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the user was last updated (ISO format with timezone)",
            "example": "2025-06-09T10:30:00.000Z"
          },
          "last_login_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "The timestamp of the user's last login",
            "example": "2025-06-09T10:30:00.000Z"
          }
        },
        "required": [
          "platform_id",
          "platform_user_id",
          "active",
          "created_at",
          "updated_at"
        ]
      },
      "User": {
        "allOf": [
          {
            "$ref": "#/components/schemas/UserBase"
          },
          {
            "type": "object",
            "properties": {
              "user_secret": {
                "type": "string",
                "nullable": true,
                "description": "The secret key for the user for authentication with the external platform",
                "example": null
              },
              "deleted": {
                "type": "boolean",
                "description": "Indicates whether the user is deleted or not",
                "default": false,
                "example": false
              }
            },
            "required": [
              "deleted"
            ]
          }
        ]
      },
      "UserResponse": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "user_id": {
                "type": "string",
                "nullable": true,
                "description": "The unique identifier for the user in the external platform",
                "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
              }
            }
          }
        ]
      },
      "UserDeleteResponse": {
        "type": "object",
        "description": "Response model for user deletion operations",
        "properties": {
          "message": {
            "type": "string",
            "description": "A message indicating the result of the user deletion operation",
            "example": "User deleted successfully"
          },
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user in the external platform",
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          }
        },
        "required": [
          "message",
          "user_id"
        ]
      },
      "UserCreateRequest": {
        "type": "object",
        "description": "Request model for user creation",
        "properties": {
          "user_id": {
            "type": "string",
            "maxLength": 64,
            "description": "The unique identifier for the user in the external platform (provided by the caller). It should be unique across the platform. Maximum length is 64 characters and it should contain only alphanumeric characters, underscores, and hyphens.",
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          }
        },
        "required": [
          "user_id"
        ]
      },
      "UserCreateResponse": {
        "type": "object",
        "description": "Response model for user creation operations",
        "properties": {
          "message": {
            "type": "string",
            "description": "A message indicating the result of the user creation operation",
            "example": "User created successfully"
          },
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user in the external platform",
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          },
          "user_secret": {
            "type": "string",
            "description": "The user secret generated during user creation. Use this for authentication purposes",
            "example": "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456"
          }
        },
        "required": [
          "message",
          "user_id",
          "user_secret"
        ]
      },
      "UserSecretRotateResponse": {
        "type": "object",
        "description": "Response model for user secret rotation operations",
        "properties": {
          "message": {
            "type": "string",
            "description": "A message indicating the result of the user secret rotation operation",
            "example": "User secret rotated successfully"
          },
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user in the external platform",
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          },
          "user_secret": {
            "type": "string",
            "description": "The new user secret",
            "example": "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456"
          }
        },
        "required": [
          "message",
          "user_id",
          "user_secret"
        ]
      },
      "ConnectionBase": {
        "type": "object",
        "description": "Base connection model with common fields",
        "properties": {
          "id": {
            "type": "string",
            "description": "The unique identifier for the connection (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439011"
          },
          "platform_id": {
            "type": "string",
            "description": "The ID of the client (platform) this connection belongs to",
            "example": "platform_123"
          },
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user in the external platform",
            "example": "user_456"
          },
          "broker": {
            "$ref": "#/components/schemas/BrokerEnum",
            "description": "The brokerage provider name",
            "example": "ALPACA"
          },
          "status": {
            "type": "string",
            "description": "The current status of the connection",
            "enum": [
              "pending",
              "active",
              "inactive",
              "error",
              "expired"
            ],
            "example": "active"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the connection was created (ISO format with timezone)",
            "example": "2025-06-09T10:30:00.000Z"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the connection was last updated (ISO format with timezone)",
            "example": "2025-06-09T10:30:00.000Z"
          },
          "last_validated_at": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "The timestamp of the connection's last validation",
            "example": "2025-06-09T10:30:00.000Z"
          }
        },
        "required": [
          "platform_id",
          "user_id",
          "broker",
          "status",
          "created_at",
          "updated_at"
        ]
      },
      "ConnectionResponse": {
        "type": "object",
        "description": "Response model for connection operations",
        "properties": {
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection (UUID format)",
            "example": "7fe430be-4b21-4e34-b335-3480017a7165"
          },
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user in the external platform",
            "example": "76873239-50c7-4b1c-bb1f-7dc2c9a3af36"
          },
          "broker": {
            "$ref": "#/components/schemas/BrokerEnum",
            "description": "The broker provider name (uppercase)",
            "example": "ALPACA"
          },
          "accounts": {
            "type": "array",
            "description": "Array of account information associated with this connection",
            "items": {
              "type": "object",
              "properties": {
                "account_id": {
                  "type": "string",
                  "description": "The unique identifier for the account (UUID format)",
                  "example": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df"
                },
                "account_number": {
                  "type": "string",
                  "description": "The account number from the broker",
                  "example": "PA123456"
                }
              },
              "required": [
                "account_id",
                "account_number"
              ]
            }
          },
          "connection_type": {
            "type": "string",
            "description": "The type of connection - 'readonly' for data access only, 'trade' for trading operations",
            "enum": [
              "readonly",
              "trade"
            ],
            "example": "readonly"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the connection was created (ISO format with timezone)",
            "example": "2025-06-27T15:42:26.723000Z"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the connection was last updated (ISO format with timezone)",
            "example": "2025-06-27T16:02:50.184000Z"
          }
        },
        "required": [
          "connection_id",
          "user_id",
          "broker",
          "accounts",
          "connection_type",
          "created_at",
          "updated_at"
        ]
      },
      "ConnectionCreateRequest": {
        "type": "object",
        "description": "Request model for connection creation",
        "properties": {
          "connection_type": {
            "type": "string",
            "description": "The type of connection being created. Can be 'trade' or 'readonly'. Connections with 'trade' type allow trading operations, while 'readonly' connections only allow data retrieval.",
            "enum": [
              "trade",
              "readonly"
            ],
            "example": "trade",
            "default": "readonly"
          },
          "broker": {
            "$ref": "#/components/schemas/BrokerEnum",
            "description": "The brokerage code for which the connection is being created.",
            "example": "ALPACA"
          },
          "redirect_url": {
            "type": "string",
            "format": "uri",
            "minLength": 1,
            "nullable": true,
            "description": "The URL to redirect the user after successful authentication. This field is optional.\nIf provided, the system will redirect to this URL with the newly created connection_id as a URL parameter.\nIf provided, a valid URL is required. Empty strings are not allowed.\n`https://` is required for non-localhost hosts. `http://` is allowed only for `localhost` during development.\nIf not provided, the user will remain on the Connect Trade platform.\n",
            "example": "https://example.com/callbacks/success"
          },
          "redirect_on_error_url": {
            "type": "string",
            "format": "uri",
            "minLength": 1,
            "nullable": true,
            "description": "The URL to redirect the user when an error occurs during the connection process. This field is optional.\nIf provided, the same validation rules apply as `redirect_url`.\nIf not provided and `redirect_url` is provided, the system will redirect to `redirect_url`. Otherwise, the user will remain on the Connect Trade platform.\n",
            "example": "https://example.com/callbacks/error"
          }
        }
      },
      "ConnectionCreateResponse": {
        "type": "object",
        "description": "Response model for connection creation",
        "properties": {
          "connection_request_url": {
            "type": "string",
            "description": "The URL that the platform should use to initiate the connection authorization process",
            "example": "https://platform.connecttrade.com?token=uho131AbrG2_hofqGD_AvhZBeJBtwdQaCPCSTkVc_fM"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the connection request URL expires (ISO format with timezone)",
            "example": "2025-07-09T13:24:08.244000Z"
          }
        },
        "required": [
          "connection_request_url",
          "expires_at"
        ]
      },
      "ConnectionDeleteResponse": {
        "type": "object",
        "description": "Response model for connection deletion operations",
        "properties": {
          "message": {
            "type": "string",
            "description": "A message indicating the result of the connection deletion operation",
            "example": "Connection deleted successfully"
          },
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection (UUID format)",
            "example": "c9ae2870-476c-465d-b583-8f00b09a2686"
          }
        },
        "required": [
          "message",
          "connection_id"
        ]
      },
      "ConnectionRegisterRequest": {
        "type": "object",
        "description": "Request model for connection registration",
        "properties": {
          "registration_data": {
            "type": "object",
            "description": "Registration data specific to the broker",
            "additionalProperties": true,
            "example": {
              "callback_url": "https://api.connecttrade.com/callbacks/alpaca"
            }
          }
        },
        "required": [
          "registration_data"
        ]
      },
      "ConnectionRegisterResponse": {
        "type": "object",
        "description": "Response model for connection registration operations",
        "properties": {
          "message": {
            "type": "string",
            "description": "A message indicating the result of the connection registration operation",
            "example": "Connection registered successfully"
          },
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection",
            "example": "conn_123abc"
          },
          "registration_status": {
            "type": "string",
            "description": "The registration status",
            "example": "registered"
          }
        },
        "required": [
          "message",
          "connection_id",
          "registration_status"
        ]
      },
      "ConnectionValidateResponse": {
        "type": "object",
        "description": "Response model for connection validation operations",
        "properties": {
          "message": {
            "type": "string",
            "description": "A message indicating the result of the connection validation operation",
            "example": "Connection validated successfully"
          },
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection",
            "example": "conn_123abc"
          },
          "is_valid": {
            "type": "boolean",
            "description": "Whether the connection is valid",
            "example": true
          },
          "validation_details": {
            "type": "object",
            "description": "Additional details about the validation",
            "additionalProperties": true,
            "example": {
              "account_status": "active",
              "permissions": [
                "trading",
                "data"
              ]
            }
          }
        },
        "required": [
          "message",
          "connection_id",
          "is_valid"
        ]
      },
      "AccountResponse": {
        "type": "object",
        "description": "Response model for account operations",
        "properties": {
          "account_id": {
            "type": "string",
            "description": "The unique identifier for the account (UUID format)",
            "example": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df"
          },
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection this account belongs to (UUID format)",
            "example": "7fe430be-4b21-4e34-b335-3480017a7165"
          },
          "account_name": {
            "type": "string",
            "nullable": true,
            "description": "The name of the account (can be null)",
            "example": null
          },
          "account_number": {
            "type": "string",
            "description": "The account number from the broker",
            "example": "PA123456"
          },
          "institution_name": {
            "$ref": "#/components/schemas/BrokerEnum",
            "description": "The name of the broker institution",
            "example": "ALPACA"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the account was created (ISO format with timezone)",
            "example": "2025-06-27T15:42:26.754000Z"
          },
          "last_update_ts": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the account was last updated (ISO format with timezone)",
            "example": "2025-06-27T15:42:26.754000Z"
          },
          "historical_data_sync_complete": {
            "type": "boolean",
            "description": "Indicates if historical data synchronization has been completed for this account",
            "example": true
          }
        },
        "required": [
          "account_id",
          "connection_id",
          "account_number",
          "institution_name",
          "created_at",
          "last_update_ts"
        ]
      },
      "BalanceResponse": {
        "type": "object",
        "description": "Response model for account balance operations",
        "properties": {
          "account_number": {
            "type": "string",
            "description": "The account number from the broker",
            "example": "PA123456"
          },
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection (UUID format)",
            "example": "1f99726b-26de-44b8-a634-213b34313344"
          },
          "account_id": {
            "type": "string",
            "description": "The unique identifier for the account (UUID format)",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user in the external platform",
            "example": "newuse011"
          },
          "currency_code": {
            "type": "string",
            "description": "The currency code for the balance amounts",
            "example": "USD"
          },
          "cash": {
            "type": "string",
            "description": "The cash balance (can be negative)",
            "example": "100000"
          },
          "buying_power": {
            "type": "string",
            "description": "The total buying power available",
            "example": "200000"
          },
          "initial_margin": {
            "type": "string",
            "description": "The initial margin requirement",
            "example": "0"
          },
          "maintenance_margin": {
            "type": "string",
            "description": "The maintenance margin requirement",
            "example": "0"
          },
          "reg_t_buying_power": {
            "type": "string",
            "description": "The Regulation T buying power",
            "example": "200000"
          },
          "system_time": {
            "type": "string",
            "format": "date-time",
            "description": "The timestamp when the balance data was retrieved (ISO format with timezone)",
            "example": "2025-06-27T17:14:37.856000Z"
          }
        },
        "required": [
          "account_number",
          "connection_id",
          "account_id",
          "user_id",
          "currency_code",
          "cash",
          "buying_power",
          "initial_margin",
          "maintenance_margin",
          "reg_t_buying_power",
          "system_time"
        ]
      },
      "OrderCreateRequest": {
        "type": "object",
        "description": "Request model for creating a new order",
        "properties": {
          "account_id": {
            "type": "string",
            "maxLength": 64,
            "description": "Account ID. The unique identifier for the account associated with the order.",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          "cl_order_id": {
            "type": "string",
            "maxLength": 64,
            "description": "Client order ID. A unique identifier provided by the client for tracking purposes.",
            "example": "8c9680a0-3a89-4c10-a093-1f14bb80"
          },
          "broker": {
            "$ref": "#/components/schemas/BrokerEnum"
          },
          "side": {
            "type": "string",
            "description": "Order side.\n\nEquities: BUY, SELL, SELL_SHORT\n\n- TradeStation: When submitting equity orders to TradeStation, closing a short position must be sent as BUY_TO_COVER (TradeStation-specific). Platforms integrating with TradeStation should use BUY_TO_COVER for short covers.\n\n- TastyTrade: When submitting equity orders to TastyTrade, orders must use the open/close variants. Platforms integrating with TastyTrade should use BUY_TO_OPEN, BUY_TO_CLOSE, SELL_TO_OPEN, or SELL_TO_CLOSE for all equity orders.\n\nOptions: BUY_TO_OPEN, BUY_TO_CLOSE, SELL_TO_OPEN, SELL_TO_CLOSE\n\nMultileg: This field does not apply to multileg orders and will be ignored if included.\n",
            "enum": [
              "BUY",
              "SELL",
              "SELL_SHORT",
              "BUY_TO_OPEN",
              "BUY_TO_CLOSE",
              "SELL_TO_OPEN",
              "SELL_TO_CLOSE"
            ],
            "example": "BUY"
          },
          "order_qty": {
            "type": "string",
            "nullable": true,
            "description": "Order quantity. The number of shares, contracts, or units to buy or sell.",
            "example": "1"
          },
          "order_notional": {
            "type": "string",
            "nullable": true,
            "description": "Order notional. The total notional value of the order.",
            "example": null
          },
          "order_type": {
            "type": "string",
            "description": "Order type. Specifies the type of order execution.",
            "enum": [
              "MKT",
              "LMT",
              "STP",
              "STPLMT"
            ],
            "example": "MKT"
          },
          "order_tif": {
            "type": "string",
            "description": "Order time in force (TIF). Indicates how long the order remains active.",
            "enum": [
              "IOC",
              "FOK",
              "DAY",
              "GTC",
              "OPEN",
              "CLOSE",
              "DAY+",
              "GTC+"
            ],
            "example": "DAY"
          },
          "order_limit_price": {
            "type": "string",
            "nullable": true,
            "description": "Order price. The price at which to execute the order.",
            "example": null
          },
          "symbol": {
            "type": "string",
            "description": "Order symbol. The ticker or identifier of the security to trade.\n\nOptions symbols must use OCC symbology.\n\nMultileg: This field does not apply to multileg orders and will be ignored if included.\n",
            "example": "MSFT"
          },
          "instrument": {
            "type": "string",
            "nullable": true,
            "description": "Order instrument. Specifies the type of instrument. Use `MLEG_OPT` for a multileg order and populate the `legs` array.",
            "enum": [
              "STK",
              "FUT",
              "OPT",
              "MLEG_OPT"
            ],
            "example": "STK"
          },
          "exec_dest": {
            "type": "string",
            "nullable": true,
            "description": "Execution destination. Optionally specifies the venue or exchange.",
            "example": null
          },
          "stop_price": {
            "type": "string",
            "nullable": true,
            "description": "Stop price. Required for stop and stop-limit orders.",
            "example": null
          },
          "legs": {
            "type": "array",
            "description": "Array of legs for a multileg order. Required for multileg orders. Multileg orders can have a minimum of 2 legs and a maximum of 4 legs.",
            "items": {
              "type": "object",
              "properties": {
                "symbol": {
                  "type": "string",
                  "description": "Leg symbol. The ticker or identifier of the option security for this leg using OCC symbology.",
                  "example": "MSFT251024C00280000"
                },
                "action": {
                  "type": "string",
                  "description": "Conveys the intent of the leg trade.",
                  "enum": [
                    "BUY_TO_OPEN",
                    "BUY_TO_CLOSE",
                    "SELL_TO_OPEN",
                    "SELL_TO_CLOSE"
                  ],
                  "example": "BUY_TO_OPEN"
                },
                "ratio": {
                  "type": "string",
                  "description": "Ratio of this leg in relation to the `order_qty`.",
                  "example": "1"
                }
              },
              "required": [
                "symbol",
                "action",
                "ratio"
              ]
            },
            "example": [
              {
                "symbol": "MSFT251024C00340000",
                "action": "BUY_TO_OPEN",
                "ratio": "1"
              },
              {
                "symbol": "MSFT251024C00290000",
                "action": "SELL_TO_OPEN",
                "ratio": "1"
              }
            ]
          }
        },
        "required": [
          "account_id",
          "cl_order_id",
          "broker",
          "side",
          "order_type",
          "order_tif",
          "symbol"
        ]
      },
      "OrderCreateResponse": {
        "type": "object",
        "description": "Response model for order creation operations",
        "properties": {
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user",
            "example": "newuse011"
          },
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection (UUID format)",
            "example": "1f99726b-26de-44b8-a634-213b34313344"
          },
          "account_id": {
            "type": "string",
            "description": "The unique identifier for the account (UUID format)",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          "order_id": {
            "type": "string",
            "description": "The unique identifier for the order",
            "example": "5008e42a-deab-4f90-914b-0bd86f7ac39e"
          },
          "account_number": {
            "type": "string",
            "description": "The account number from the broker",
            "example": "ABC123456"
          },
          "cl_order_id": {
            "type": "string",
            "description": "A unique client-defined order ID included in the request. Must be unique per order per day.",
            "example": "8c9680a0-3a89-4c10-a093-1f14bb80"
          },
          "platform": {
            "type": "string",
            "description": "The platform identifier",
            "example": "platform_name"
          },
          "broker": {
            "type": "string",
            "description": "The broker identifier",
            "example": "ALPACA"
          },
          "normalized_status": {
            "type": "string",
            "description": "The normalized order status",
            "enum": [
              "working",
              "pending",
              "filled",
              "partially_filled",
              "replaced",
              "cancelled",
              "rejected",
              "done_for_day",
              "expired",
              "pending_cancel",
              "pending_replace"
            ],
            "example": "pending"
          },
          "broker_status": {
            "type": "string",
            "description": "The broker-specific order status",
            "example": "pending_new"
          },
          "side": {
            "type": "string",
            "description": "Order side. Null for multileg orders.",
            "enum": [
              "BUY",
              "SELL",
              "SELL_SHORT",
              "BUY_TO_OPEN",
              "BUY_TO_CLOSE",
              "SELL_TO_OPEN",
              "SELL_TO_CLOSE"
            ],
            "example": "BUY"
          },
          "order_qty": {
            "type": "string",
            "description": "Order quantity",
            "example": "1"
          },
          "order_notional": {
            "type": "string",
            "nullable": true,
            "description": "Order notional value",
            "example": null
          },
          "order_type": {
            "type": "string",
            "description": "Order type",
            "enum": [
              "MKT",
              "LMT",
              "STP",
              "STPLMT"
            ],
            "example": "MKT"
          },
          "broker_order_type": {
            "type": "string",
            "description": "Broker-specific order type",
            "example": "market"
          },
          "order_tif": {
            "type": "string",
            "description": "Order time in force",
            "enum": [
              "IOC",
              "FOK",
              "DAY",
              "GTC",
              "OPEN",
              "CLOSE",
              "DAY+",
              "GTC+"
            ],
            "example": "DAY"
          },
          "order_limit_price": {
            "type": "string",
            "description": "Order price",
            "example": "0"
          },
          "symbol": {
            "type": "string",
            "description": "Trading symbol. Null for multileg orders.",
            "example": "MSFT"
          },
          "instrument": {
            "type": "string",
            "description": "Instrument type",
            "enum": [
              "STK",
              "FUT",
              "OPT",
              "MLEG_OPT"
            ],
            "example": "STK"
          },
          "exec_dest": {
            "type": "string",
            "nullable": true,
            "description": "Execution destination",
            "example": null
          },
          "entry_time": {
            "type": "string",
            "format": "date-time",
            "description": "Order entry timestamp",
            "example": "2025-06-27T17:22:34.454422Z"
          },
          "last_exec_time": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "Last execution timestamp",
            "example": null
          },
          "last_modified_time": {
            "type": "string",
            "format": "date-time",
            "description": "Last modification timestamp",
            "example": "2025-06-27T17:22:34.455936Z"
          },
          "stop_price": {
            "type": "string",
            "nullable": true,
            "description": "Stop price for stop orders",
            "example": null
          },
          "broker_text": {
            "type": "string",
            "nullable": true,
            "description": "Informational text provided by the broker, if any. Not provided by all brokers. Can be useful for determining rejection reason.",
            "example": null
          },
          "fills": {
            "type": "array",
            "description": "Array of order fills",
            "items": {
              "type": "object"
            },
            "example": []
          },
          "legs": {
            "type": "array",
            "description": "Array of order legs. Only populated for multileg orders.",
            "items": {
              "type": "object"
            },
            "example": []
          },
          "system_time": {
            "type": "string",
            "format": "date-time",
            "description": "System timestamp",
            "example": "2025-06-27T17:22:34.501950Z"
          }
        },
        "required": [
          "user_id",
          "connection_id",
          "account_id",
          "order_id",
          "account_number",
          "cl_order_id",
          "platform",
          "broker",
          "normalized_status",
          "broker_status",
          "side",
          "order_qty",
          "order_type",
          "broker_order_type",
          "order_tif",
          "order_limit_price",
          "symbol",
          "instrument",
          "entry_time",
          "last_modified_time",
          "broker_text",
          "fills",
          "legs",
          "system_time"
        ]
      },
      "OrderResponse": {
        "type": "object",
        "description": "Response model for order retrieval operations",
        "properties": {
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user",
            "example": "newuse011"
          },
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection (UUID format)",
            "example": "1f99726b-26de-44b8-a634-213b34313344"
          },
          "account_id": {
            "type": "string",
            "description": "The unique identifier for the account (UUID format)",
            "example": "e48f7013-55b3-472b-b7c9-c85a0d6154c6"
          },
          "order_id": {
            "type": "string",
            "description": "The unique identifier for the order",
            "example": "c98967d6-a599-42cf-9d9d-6ea048e916dc"
          },
          "account_number": {
            "type": "string",
            "description": "The account number from the broker",
            "example": "ABC123456"
          },
          "cl_order_id": {
            "type": "string",
            "description": "A unique client-defined order ID included in the request. Must be unique per order per day.",
            "example": "bce8b066-4235-4735-b610-e93a1f40"
          },
          "platform": {
            "type": "string",
            "description": "The platform identifier",
            "example": "alpaca"
          },
          "broker": {
            "type": "string",
            "description": "The brokerage identifier",
            "example": "ALPACA"
          },
          "normalized_status": {
            "type": "string",
            "description": "The normalized order status",
            "enum": [
              "working",
              "pending",
              "filled",
              "partially_filled",
              "replaced",
              "cancelled",
              "rejected",
              "done_for_day",
              "expired",
              "pending_cancel",
              "pending_replace"
            ],
            "example": "filled"
          },
          "broker_status": {
            "type": "string",
            "description": "The broker-specific order status",
            "example": "filled"
          },
          "side": {
            "type": "string",
            "description": "Order side. Null for multileg orders.",
            "enum": [
              "BUY",
              "SELL",
              "SELL_SHORT",
              "BUY_TO_OPEN",
              "BUY_TO_CLOSE",
              "SELL_TO_OPEN",
              "SELL_TO_CLOSE"
            ],
            "example": "BUY"
          },
          "order_qty": {
            "type": "string",
            "description": "Order quantity",
            "example": "1"
          },
          "order_notional": {
            "type": "string",
            "nullable": true,
            "description": "Order notional value",
            "example": null
          },
          "order_type": {
            "type": "string",
            "description": "Order type",
            "enum": [
              "MKT",
              "LMT",
              "STP",
              "STPLMT"
            ],
            "example": "MKT"
          },
          "broker_order_type": {
            "type": "string",
            "description": "Broker-specific order type",
            "example": "market"
          },
          "order_tif": {
            "type": "string",
            "description": "Order time in force",
            "enum": [
              "IOC",
              "FOK",
              "DAY",
              "GTC",
              "OPEN",
              "CLOSE",
              "DAY+",
              "GTC+"
            ],
            "example": "DAY"
          },
          "order_limit_price": {
            "type": "string",
            "description": "Order price",
            "example": "0"
          },
          "symbol": {
            "type": "string",
            "description": "Trading symbol. Null for multileg orders.",
            "example": "MSFT"
          },
          "instrument": {
            "type": "string",
            "description": "Instrument type",
            "enum": [
              "STK",
              "FUT",
              "OPT",
              "MLEG_OPT"
            ],
            "example": "STK"
          },
          "exec_dest": {
            "type": "string",
            "nullable": true,
            "description": "Execution destination",
            "example": null
          },
          "entry_time": {
            "type": "string",
            "format": "date-time",
            "description": "Order entry timestamp",
            "example": "2025-06-27T17:48:40.845000Z"
          },
          "last_exec_time": {
            "type": "string",
            "nullable": true,
            "format": "date-time",
            "description": "Last execution timestamp",
            "example": "2025-06-27T17:48:41.443000Z"
          },
          "last_modified_time": {
            "type": "string",
            "format": "date-time",
            "description": "Last modification timestamp",
            "example": "2025-06-27T17:48:41.445000Z"
          },
          "stop_price": {
            "type": "string",
            "nullable": true,
            "description": "Stop price for stop orders",
            "example": null
          },
          "broker_text": {
            "type": "string",
            "nullable": true,
            "description": "Informational text provided by the broker, if any. Not provided by all brokers. Can be useful for determining rejection reason.",
            "example": null
          },
          "fills": {
            "type": "array",
            "description": "Array of order fills",
            "items": {
              "type": "object",
              "properties": {
                "time": {
                  "type": "string",
                  "format": "date-time",
                  "description": "Fill execution time",
                  "example": "2025-06-27T17:48:41.443000Z"
                },
                "quantity": {
                  "type": "string",
                  "description": "Fill quantity",
                  "example": "1"
                },
                "price": {
                  "type": "string",
                  "description": "Fill price",
                  "example": "497.37"
                },
                "fill_id": {
                  "type": "string",
                  "description": "Unique identifier for the fill, if available.",
                  "example": "e5f6b895-3fc8-4f86-9c98-fdf84fd72aff"
                }
              },
              "required": [
                "time",
                "quantity",
                "price",
                "fill_id"
              ]
            },
            "example": [
              {
                "time": "2025-06-27T17:48:41.443000Z",
                "quantity": "1",
                "price": "497.37",
                "fill_id": "e5f6b895-3fc8-4f86-9c98-fdf84fd72aff"
              }
            ]
          },
          "legs": {
            "type": "array",
            "description": "Array of legs for a multileg order. Null otherwise.",
            "items": {
              "type": "object",
              "properties": {
                "symbol": {
                  "type": "string",
                  "description": "Leg symbol. The ticker or identifier of the option security for this leg using OCC symbology.",
                  "example": "MSFT251024C00280000"
                },
                "action": {
                  "type": "string",
                  "description": "Conveys the intent of the leg trade.",
                  "enum": [
                    "BUY_TO_OPEN",
                    "BUY_TO_CLOSE",
                    "SELL_TO_OPEN",
                    "SELL_TO_CLOSE"
                  ],
                  "example": "BUY_TO_OPEN"
                },
                "ratio": {
                  "type": "string",
                  "description": "Ratio of this leg in relation to the order_qty.",
                  "example": "1"
                },
                "leg_id": {
                  "type": "string",
                  "description": "Unique identifier for the leg, if available.",
                  "example": "82360182-1845-4984-b888-5a1ddceb4350"
                },
                "fills": {
                  "type": "array",
                  "description": "Array of fills for this leg.",
                  "items": {
                    "type": "object",
                    "properties": {
                      "time": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Fill execution time",
                        "example": "2025-06-27T17:48:41.443000Z"
                      },
                      "quantity": {
                        "type": "string",
                        "description": "Fill quantity",
                        "example": "1"
                      },
                      "price": {
                        "type": "string",
                        "description": "Fill price",
                        "example": "497.37"
                      },
                      "fill_id": {
                        "type": "string",
                        "description": "Unique identifier for the fill, if available.",
                        "example": "e5f6b895-3fc8-4f86-9c98-fdf84fd72aff"
                      }
                    },
                    "required": [
                      "time",
                      "quantity",
                      "price",
                      "fill_id"
                    ]
                  }
                }
              },
              "required": [
                "symbol",
                "action",
                "ratio",
                "leg_id",
                "fills"
              ]
            },
            "example": [
              {
                "symbol": "MSFT251024C00280000",
                "action": "BUY_TO_OPEN",
                "ratio": "1",
                "leg_id": "e313b2cf-7f91-4c52-b52d-937aa96470e4",
                "fills": [
                  {
                    "time": "2025-10-12T11:38:12.273000Z",
                    "quantity": "1",
                    "price": "236.72",
                    "fill_id": "1036519a-f1bc-44c0-92a8-9c5502c17a57"
                  }
                ]
              }
            ]
          },
          "system_time": {
            "type": "string",
            "format": "date-time",
            "description": "System timestamp",
            "example": "2025-06-27T17:48:41.758000Z"
          }
        },
        "required": [
          "user_id",
          "connection_id",
          "account_id",
          "order_id",
          "account_number",
          "cl_order_id",
          "platform",
          "broker",
          "normalized_status",
          "broker_status",
          "side",
          "order_qty",
          "order_type",
          "broker_order_type",
          "order_tif",
          "order_limit_price",
          "symbol",
          "instrument",
          "entry_time",
          "last_modified_time",
          "broker_text",
          "fills",
          "legs",
          "system_time"
        ]
      },
      "OrderCancelResponse": {
        "type": "object",
        "properties": {
          "order_id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "PositionResponse": {
        "type": "object",
        "description": "Response model for position data",
        "properties": {
          "connection_id": {
            "type": "string",
            "description": "The unique identifier for the connection (UUID format)",
            "example": "7fe430be-4b21-4e34-b335-3480017a7165"
          },
          "account_id": {
            "type": "string",
            "description": "The unique identifier for the account (UUID format)",
            "example": "e5ff8fd9-d0cb-4632-8823-30e60e01f7df"
          },
          "user_id": {
            "type": "string",
            "description": "The unique identifier for the user",
            "example": "newuse011"
          },
          "account_number": {
            "type": "string",
            "description": "The account number from the broker",
            "example": "ABC123456"
          },
          "broker_position_id": {
            "type": "string",
            "nullable": true,
            "description": "The broker-provided identifier for the position, if available",
            "example": "alpaca-AAPL-ABC123456"
          },
          "symbol": {
            "type": "string",
            "description": "Trading symbol",
            "example": "AAPL"
          },
          "quantity": {
            "type": "string",
            "description": "Position quantity (number of shares/units held)",
            "example": "620"
          },
          "last_price": {
            "type": "string",
            "description": "Last traded price of the security",
            "example": "201.5"
          },
          "position_average_price": {
            "type": "string",
            "description": "Average price at which the position was acquired",
            "example": "201.731887"
          },
          "unrealized_pl": {
            "type": "string",
            "description": "Unrealized profit and loss for the position",
            "example": "-143.770001"
          },
          "daily_pl": {
            "type": "string",
            "description": "Daily profit and loss for the position",
            "example": "310"
          },
          "total_pl": {
            "type": "string",
            "description": "Total profit and loss for the position",
            "example": "-143.770001"
          },
          "instrument": {
            "type": "string",
            "description": "The type of instrument",
            "enum": [
              "STK",
              "FUT",
              "OPT",
              "CRYPTO"
            ],
            "example": "STK"
          },
          "system_time": {
            "type": "string",
            "format": "date-time",
            "description": "System timestamp when the position data was recorded",
            "example": "2025-01-01T12:00:00.000000Z"
          }
        },
        "required": [
          "connection_id",
          "account_id",
          "user_id",
          "account_number",
          "symbol",
          "quantity",
          "last_price",
          "position_average_price",
          "unrealized_pl",
          "daily_pl",
          "total_pl",
          "instrument",
          "system_time"
        ]
      },
      "TransactionType": {
        "type": "string",
        "description": "Normalized transaction type",
        "enum": [
          "ACAT",
          "ACCOUNT_TRANSFER",
          "DEPOSIT",
          "DIVIDEND",
          "FEE",
          "FILL",
          "INTEREST",
          "JOURNAL_ENTRY",
          "MISC",
          "OPTION_EXPIRATION",
          "OPTION_ASSIGNMENT",
          "OPTION_EXERCISE",
          "REI",
          "WITHDRAWAL"
        ]
      },
      "TransactionResponse": {
        "type": "object",
        "description": "Response model for transaction retrieval operations",
        "properties": {
          "transaction_id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier for the transaction",
            "example": null
          },
          "connection_id": {
            "type": "string",
            "format": "uuid",
            "description": "The unique identifier for the connection",
            "example": null
          },
          "account_id": {
            "type": "string",
            "format": "uuid",
            "description": "The unique identifier for the account",
            "example": null
          },
          "account_number": {
            "type": "string",
            "description": "The unique identifier for the account",
            "example": null
          },
          "transaction_type": {
            "$ref": "#/components/schemas/TransactionType",
            "description": "Normalized transaction type",
            "example": null
          },
          "broker_transaction_type": {
            "type": "string",
            "nullable": true,
            "description": "Unnormalized transaction type",
            "example": null
          },
          "broker_transaction_sub_type": {
            "type": "string",
            "nullable": true,
            "description": "Unnormalized transaction sub type",
            "example": null
          },
          "broker_transaction_id": {
            "type": "string",
            "nullable": true,
            "description": "Broker ID, nullable",
            "example": null
          },
          "symbol": {
            "type": "string",
            "nullable": true,
            "description": "Symbol, nullable",
            "example": null
          },
          "price": {
            "type": "string",
            "nullable": true,
            "description": "Price, nullable",
            "example": null
          },
          "qty": {
            "type": "string",
            "nullable": true,
            "description": "Quantity, nullable",
            "example": null
          },
          "side": {
            "type": "string",
            "nullable": true,
            "description": "Side, nullable",
            "example": null
          },
          "amount": {
            "type": "string",
            "nullable": true,
            "description": "Amount, nullable",
            "example": null
          },
          "currency": {
            "type": "string",
            "nullable": true,
            "description": "Currency, nullable",
            "example": null
          },
          "broker_description": {
            "type": "string",
            "nullable": true,
            "description": "Broker description, pass thru",
            "example": null
          },
          "trade_date": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Trade date, nullable",
            "example": null
          },
          "settlement_date": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Settlement date, nullable",
            "example": null
          },
          "fee": {
            "type": "string",
            "nullable": true,
            "description": "Fee, nullable",
            "example": null
          },
          "fx_rate": {
            "type": "string",
            "nullable": true,
            "description": "FX rate, nullable",
            "example": null
          },
          "broker": {
            "type": "string",
            "nullable": true,
            "description": "Broker name, nullable",
            "example": "ALPACA"
          },
          "transaction_time": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Transaction time, nullable",
            "example": "2025-09-06T08:21:24.891000Z"
          },
          "order_id": {
            "type": "string",
            "nullable": true,
            "description": "Order ID, nullable",
            "example": null
          }
        },
        "required": [
          "account_number",
          "connection_id",
          "account_id",
          "transaction_type",
          "transaction_id"
        ]
      },
      "BrokerEnum": {
        "type": "string",
        "description": "Supported brokers",
        "enum": [
          "ALPACA",
          "BANKOFAMERICA",
          "CAPITALONE",
          "CHASE",
          "CITI",
          "FIDELITY",
          "LIGHTSPEED",
          "PNC",
          "PUBLIC",
          "SCHWAB",
          "TASTYTRADE",
          "TD",
          "TRADESTATION",
          "TRADEZERO",
          "USBANK",
          "WEBULL",
          "WELLSFARGO"
        ],
        "example": "ALPACA"
      },
      "BrokerQueryParam": {
        "type": "string",
        "description": "Supported brokers for query parameters (lowercase)",
        "enum": [
          "alpaca",
          "bankofamerica",
          "capitalone",
          "chase",
          "citi",
          "fidelity",
          "lightspeed",
          "pnc",
          "public",
          "schwab",
          "tastytrade",
          "td",
          "tradestation",
          "tradezero",
          "usbank",
          "webull",
          "wellsfargo"
        ],
        "example": "alpaca"
      },
      "ErrorResponse": {
        "type": "object",
        "description": "Standard error response format",
        "properties": {
          "message": {
            "type": "string",
            "description": "Error message describing what went wrong",
            "example": "Platform ID not found"
          }
        }
      },
      "UserListResponse": {
        "type": "object",
        "description": "Paginated response for user list",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UserResponse"
            },
            "description": "Array of user objects"
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor for forward pagination. Use this value in the next_cursor query parameter to retrieve the next page of results. Null if there are no more results.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          "prev_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor for backward pagination. Use this value in the prev_cursor query parameter to retrieve the previous page of results. Null if there are no previous results.",
            "example": "eyJ0c...2QxZTZjIn0="
          }
        },
        "required": [
          "data",
          "next_cursor",
          "prev_cursor"
        ]
      },
      "schemas-ErrorResponse": {
        "type": "object",
        "description": "Standard error response format",
        "properties": {
          "message": {
            "type": "string",
            "description": "Error message describing what went wrong",
            "example": "An error occurred"
          }
        }
      },
      "OrderListResponse": {
        "type": "object",
        "description": "Paginated response for order list",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderResponse"
            },
            "description": "Array of order objects"
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor for forward pagination. Use this value in the next_cursor query parameter to retrieve the next page of results. Null if there are no more results.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          "prev_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor for backward pagination. Use this value in the prev_cursor query parameter to retrieve the previous page of results. Null if there are no previous results.",
            "example": "eyJ0c...2QxZTZjIn0="
          }
        },
        "required": [
          "data",
          "next_cursor",
          "prev_cursor"
        ]
      },
      "components-schemas-ErrorResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        }
      },
      "OrderReplaceRequest": {
        "type": "object",
        "description": "Request model for replacing an existing order",
        "properties": {
          "new_cl_order_id": {
            "type": "string",
            "maxLength": 64,
            "description": "New client order ID. This is a unique identifier provided by the client for tracking purposes.",
            "example": "9d0781b1-4a9a-5d21-b704-f04a2f51"
          },
          "broker": {
            "description": "The broker of the original order.",
            "allOf": [
              {
                "$ref": "#/components/schemas/BrokerEnum"
              }
            ]
          },
          "order_qty": {
            "type": "string",
            "nullable": true,
            "description": "Order quantity. The number of shares, contracts, or units to buy or sell. Only applicable if the original order was submitted with quantity.",
            "example": "2"
          },
          "order_notional": {
            "type": "string",
            "nullable": true,
            "description": "Order notional. The total notional value of the order. Only applicable if the original order was submitted with notional.",
            "example": null
          },
          "order_limit_price": {
            "type": "string",
            "nullable": true,
            "description": "Order price. The price at which to execute the order.",
            "example": "500.00"
          },
          "stop_price": {
            "type": "string",
            "nullable": true,
            "description": "Stop price. The stop price for this order.",
            "example": null
          }
        },
        "required": [
          "new_cl_order_id",
          "broker"
        ]
      },
      "positions-api_components-schemas-ErrorResponse": {
        "type": "object",
        "description": "Error response model",
        "properties": {
          "message": {
            "type": "string",
            "description": "Error message describing what went wrong",
            "example": "Invalid request parameters"
          },
          "code": {
            "type": "string",
            "description": "Error code for programmatic handling",
            "example": "INVALID_PARAMETERS"
          },
          "details": {
            "type": "object",
            "description": "Additional error details",
            "example": {}
          }
        },
        "required": [
          "message"
        ]
      },
      "TransactionListResponse": {
        "type": "object",
        "description": "Paginated response for transaction list",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TransactionResponse"
            },
            "description": "Array of transaction objects"
          },
          "next_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor for forward pagination. Use this value in the next_cursor query parameter to retrieve the next page of results. Null if there are no more results.",
            "example": "eyJ0c...2QxZTZjIn0="
          },
          "prev_cursor": {
            "type": "string",
            "nullable": true,
            "description": "Cursor for backward pagination. Use this value in the prev_cursor query parameter to retrieve the previous page of results. Null if there are no previous results.",
            "example": "eyJ0c...2QxZTZjIn0="
          }
        },
        "required": [
          "data",
          "next_cursor",
          "prev_cursor"
        ]
      }
    }
  }
}