TD Ameritrade Accounts and Trading API

The Accounts and Trading API from TD Ameritrade — 7 operation(s) for accounts and trading.

OpenAPI Specification

td-ameritrade-accounts-and-trading-api-openapi.yml Raw ↑
openapi: 3.0.0
info:
  description: TD Ameritrade API
  version: 3.0.1
  title: TD Ameritrade Accounts and Trading API
  termsOfService: https://developer.tdameritrade.com/legal
  contact:
    email: austin.millan@protonmail.com
servers:
- url: https://api.tdameritrade.com/v2
- url: http://api.tdameritrade.com/v2
tags:
- name: Accounts and Trading
paths:
  /accounts/{accountId}/orders/{orderId}:
    delete:
      tags:
      - Accounts and Trading
      summary: Cancel Order
      description: 'Cancel a specific order for a specific account. '
      operationId: cancelOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: orderId
        in: path
        description: Order Number
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      responses:
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '404':
          description: An error message if the order was not found.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
    put:
      tags:
      - Accounts and Trading
      summary: Replace Order
      description: Replace an existing order for an account. The existing order will be replaced by the new order. Once replaced, the old order will be canceled and a new order will be created.
      operationId: replaceOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: orderId
        in: path
        description: Order Number
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      requestBody:
        $ref: '#/components/requestBodies/Order'
      responses:
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '404':
          description: An error message if the order was not found.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
    get:
      tags:
      - Accounts and Trading
      summary: Get Order
      description: Get a specific order for a specific account.
      operationId: getOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: orderId
        in: path
        description: Order Number
        required: true
        schema:
          type: integer
          format: int64
      responses:
        '200':
          description: A Order object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
  /accounts/{accountId}/orders:
    get:
      tags:
      - Accounts and Trading
      summary: Get Orders By Path
      description: Orders for a specific account.
      operationId: getOrdersByPath
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: maxResults
        in: query
        description: The maximum number of orders to retrieve.
        required: true
        schema:
          type: integer
      - name: fromEnteredTime
        in: query
        description: Specifies that no orders entered before this time should be returned. Valid ISO-8601 formats are  yyyy-MM-dd and yyyy-MM-dd'T'HH:mm:ssz Date must be within 60 days from today's date. 'toEnteredTime' must also be set.
        required: true
        schema:
          type: string
      - name: toEnteredTime
        in: query
        description: Specifies that no orders entered after this time should be returned.Valid ISO-8601 formats are :yyyy-MM-dd and yyyy-MM-dd'T'HH:mm:ssz. 'fromEnteredTime' must also be set.
        required: true
        schema:
          type: string
          format: string
          maximum: 0
      - name: status
        in: query
        description: The maximum number of orders to retrieve.
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      responses:
        '200':
          description: A Order object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
    post:
      tags:
      - Accounts and Trading
      summary: Place Order
      description: Place an order for a specific account.
      operationId: placeOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      requestBody:
        $ref: '#/components/requestBodies/Order'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
  /orders:
    get:
      tags:
      - Accounts and Trading
      summary: Get Orders By Query
      description: All orders for a specific account or, if account ID isn't specified, orders will be returned for all linked accounts
      operationId: getOrdersByQuery
      parameters:
      - name: accountId
        in: query
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: maxResults
        in: query
        description: The maximum number of orders to retrieve.
        required: true
        schema:
          type: integer
      - name: fromEnteredTime
        in: query
        description: Specifies that no orders entered before this time should be returned. Valid ISO-8601 formats are  yyyy-MM-dd and yyyy-MM-dd'T'HH:mm:ssz Date must be within 60 days from today's date. 'toEnteredTime' must also be set.
        required: true
        schema:
          type: string
      - name: toEnteredTime
        in: query
        description: Specifies that no orders entered after this time should be returned.Valid ISO-8601 formats are :yyyy-MM-dd and yyyy-MM-dd'T'HH:mm:ssz. 'fromEnteredTime' must also be set.
        required: true
        schema:
          type: string
          format: string
          maximum: 0
      - name: status
        in: query
        description: The maximum number of orders to retrieve.
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      responses:
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
  /accounts/{accountId}/savedorders:
    get:
      tags:
      - Accounts and Trading
      summary: Get Saved Orders by Path
      description: Saved orders for a specific account.
      operationId: getSavedOrdersByPath
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      responses:
        '200':
          description: A Order object
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SavedOrder'
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
    post:
      tags:
      - Accounts and Trading
      summary: Create Saved Order
      description: 'Save an order for a specific account. '
      operationId: saveOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: orderId
        in: path
        description: Order Number
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SavedOrder'
        description: The order to save.
      responses:
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
  /accounts/{accountId}/savedorders/{savedOrderId}:
    delete:
      tags:
      - Accounts and Trading
      summary: Delete Saved Order
      description: Delete a specific saved order for a specific account.
      operationId: deleteSavedOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: savedOrderId
        in: path
        description: Order Number
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      responses:
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
    get:
      tags:
      - Accounts and Trading
      summary: Get Saved Order
      description: Specific saved order by its ID, for a specific account.
      operationId: getSavedOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: savedOrderId
        in: path
        description: Order Number
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      responses:
        '200':
          description: A Order object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
    put:
      tags:
      - Accounts and Trading
      summary: Replace Saved Order
      description: Replace an existing saved order for an account. The existing saved order will be replaced by the new order.
      operationId: replaceSavedOrder
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      - name: savedOrderId
        in: path
        description: Order Number
        required: true
        schema:
          type: integer
          format: int64
          maximum: 0
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SavedOrder'
        description: The order to place.
      responses:
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '404':
          description: An error message if the order was not found.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
  /accounts/{accountId}:
    get:
      tags:
      - Accounts and Trading
      summary: Get Account
      description: Account balances, positions, and orders for a specific account.
      operationId: getAccount
      parameters:
      - name: accountId
        in: path
        description: Account Number
        required: true
        schema:
          type: integer
          format: string
      responses:
        '200':
          description: A Account Object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Account'
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
  /accounts:
    get:
      tags:
      - Accounts and Trading
      summary: Get Accounts
      description: Account balances, positions, and orders for a specific account.
      operationId: getAccounts
      responses:
        '200':
          description: A Account Object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Account'
        '207':
          description: Indicates there was a problem getting account data for one or more linked accounts, but the accounts who's data returned successfully is in the response. Do not aggregate balances and positions for this case.
        '400':
          description: An error message indicating the validation problem with the request.
        '401':
          description: An error message indicating the caller must pass a valid AuthToken in the HTTP authorization request header.
        '403':
          description: An error message indicating the caller is forbidden from accessing this page.
        '500':
          description: An error message indicating there was an unexpected server error.
      security:
      - Bearer: []
components:
  schemas:
    CashAccount:
      properties:
        accountId:
          example: string
          type: string
        currentBalances:
          properties:
            accruedInterest:
              example: 0
              type: number
            bondValue:
              example: 0
              type: number
            cashAvailableForTrading:
              example: 0
              type: number
            cashAvailableForWithdrawal:
              example: 0
              type: number
            cashBalance:
              example: 0
              type: number
            cashCall:
              example: 0
              type: number
            cashDebitCallValue:
              example: 0
              type: number
            cashReceipts:
              example: 0
              type: number
            liquidationValue:
              example: 0
              type: number
            longMarketValue:
              example: 0
              type: number
            longNonMarginableMarketValue:
              example: 0
              type: number
            longOptionMarketValue:
              example: 0
              type: number
            moneyMarketFund:
              example: 0
              type: number
            mutualFundValue:
              example: 0
              type: number
            pendingDeposits:
              example: 0
              type: number
            savings:
              example: 0
              type: number
            shortMarketValue:
              example: 0
              type: number
            shortOptionMarketValue:
              example: 0
              type: number
            totalCash:
              example: 0
              type: number
            unsettledCash:
              example: 0
              type: number
          type: object
        initialBalances:
          properties:
            accountValue:
              example: 0
              type: number
            accruedInterest:
              example: 0
              type: number
            bondValue:
              example: 0
              type: number
            cashAvailableForTrading:
              example: 0
              type: number
            cashAvailableForWithdrawal:
              example: 0
              type: number
            cashBalance:
              example: 0
              type: number
            cashDebitCallValue:
              example: 0
              type: number
            cashReceipts:
              example: 0
              type: number
            isInCall:
              type: boolean
            liquidationValue:
              example: 0
              type: number
            longOptionMarketValue:
              example: 0
              type: number
            longStockValue:
              example: 0
              type: number
            moneyMarketFund:
              example: 0
              type: number
            mutualFundValue:
              example: 0
              type: number
            pendingDeposits:
              example: 0
              type: number
            shortOptionMarketValue:
              example: 0
              type: number
            shortStockValue:
              example: 0
              type: number
            unsettledCash:
              example: 0
              type: number
          type: object
        isClosingOnlyRestricted:
          type: boolean
        isDayTrader:
          type: boolean
        orderStrategies:
          items:
            properties:
              accountId:
                example: 0
                type: number
              activationPrice:
                example: 0
                type: number
              cancelTime:
                properties:
                  date:
                    example: string
                    type: string
                  shortFormat:
                    type: boolean
                type: object
              cancelable:
                type: boolean
              childOrderStrategies:
                items:
                  type: object
                type: array
              closeTime:
                example: string
                type: string
              complexOrderStrategyType:
                $ref: '#/components/schemas/ComplexOrderStrategyType'
              destinationLinkName:
                example: string
                type: string
              duration:
                $ref: '#/components/schemas/Duration'
              editable:
                type: boolean
              enteredTime:
                example: string
                type: string
              filledQuantity:
                example: 0
                type: number
              orderActivityCollection:
                items:
                  $ref: '#/components/schemas/Execution'
                type: array
              orderId:
                example: 0
                type: number
              orderLegCollection:
                items:
                  properties:
                    instruction:
                      $ref: '#/components/schemas/Instruction'
                    instrument:
                      $ref: '#/components/schemas/InstrumentType'
                    legId:
                      example: 0
                      type: number
                    orderLegType:
                      $ref: '#/components/schemas/AssetType'
                    positionEffect:
                      $ref: '#/components/schemas/PositionEffect'
                    quantity:
                      example: 0
                      type: number
                    quantityType:
                      $ref: '#/components/schemas/QuantityType'
                  type: object
                type: array
              orderStrategyType:
                $ref: '#/components/schemas/OrderStrategyType'
              orderType:
                $ref: '#/components/schemas/OrderType'
              price:
                example: 0
                type: number
              priceLinkBasis:
                $ref: '#/components/schemas/PriceLinkBasis'
              priceLinkType:
                $ref: '#/components/schemas/PriceLinkType'
              quantity:
                example: 0
                type: number
              releaseTime:
                example: string
                type: string
              remainingQuantity:
                example: 0
                type: number
              replacingOrderCollection:
                items:
                  type: object
                type: array
              requestedDestination:
                $ref: '#/components/schemas/DestinationExchange'
              session:
                $ref: '#/components/schemas/Session'
              specialInstruction:
                $ref: '#/components/schemas/SpecialInstruction'
              status:
                $ref: '#/components/schemas/OrderStatus'
              statusDescription:
                example: string
                type: string
              stopPrice:
                example: 0
                type: number
              stopPriceLinkBasis:
                $ref: '#/components/schemas/PriceLinkBasis'
              stopPriceLinkType:
                $ref: '#/components/schemas/PriceLinkType'
              stopPriceOffset:
                example: 0
                type: number
              stopType:
                $ref: '#/components/schemas/StopType'
              tag:
                example: string
                type: string
              taxLotMethod:
                $ref: '#/components/schemas/TaxLotMethod'
            type: object
          type: array
        positions:
          items:
            properties:
              agedQuantity:
                example: 0
                type: number
              averagePrice:
                example: 0
                type: number
              currentDayProfitLoss:
                example: 0
                type: number
              currentDayProfitLossPercentage:
                example: 0
                type: number
              instrument:
                $ref: '#/components/schemas/InstrumentType'
              longQuantity:
                example: 0
                type: number
              marketValue:
                example: 0
                type: number
              settledLongQuantity:
                example: 0
                type: number
              settledShortQuantity:
                example: 0
                type: number
              shortQuantity:
                example: 0
                type: number
            type: object
          type: array
        projectedBalances:
          properties:
            accruedInterest:
              example: 0
              type: number
            bondValue:
              example: 0
              type: number
            cashAvailableForTrading:
              example: 0
              type: number
            cashAvailableForWithdrawal:
              example: 0
              type: number
            cashBalance:
              example: 0
              type: number
            cashCall:
              example: 0
              type: number
            cashDebitCallValue:
              example: 0
              type: number
            cashReceipts:
              example: 0
              type: number
            liquidationValue:
              example: 0
              type: number
            longMarketValue:
              example: 0
              type: number
            longNonMarginableMarketValue:
              example: 0
              type: number
            longOptionMarketValue:
              example: 0
              type: number
            moneyMarketFund:
              example: 0
              type: number
            mutualFundValue:
              example: 0
              type: number
            pendingDeposits:
              example: 0
              type: number
            savings:
              example: 0
              type: number
            shortMarketValue:
              example: 0
              type: number
            shortOptionMarketValue:
              example: 0
              type: number
            totalCash:
              example: 0
              type: number
            unsettledCash:
              example: 0
              type: number
          type: object
        roundTrips:
          example: 0
          type: number
        type:
          example: '''CASH'' or ''MARGIN'''
          type: string
      type: object
    QuantityType:
      enum:
      - ALL_SHARES
      - DOLLARS
      - SHARES
      example: '''ALL_SHARES'' or ''DOLLARS'' or ''SHARES'''
      type: string
    Option:
      properties:
        assetType:
          $ref: '#/components/schemas/AssetType'
        cusip:
          example: string
          type: string
        description:
          example: string
          type: string
        optionDeliverables:
          items:
            properties:
              assetType:
                $ref: '#/components/schemas/AssetType'
              currencyType:
                $ref: '#/components/schemas/CurrencyType'
              deliverableUnits:
                example: 0
                type: number
              symbol:
                example: string
                type: string
            type: object
          type: array
        optionMultiplier:
          example: 0
          type: number
        putCall:
          $ref: '#/components/schemas/PutOrCall'
        symbol:
          example: string
          type: string
        type:
          $ref: '#/components/schemas/OptionType'
        underlyingSymbol:
          example: string
          type: string
      type: object
    FixedIncome:
      properties:
        assetType:
          $ref: '#/components/schemas/AssetType'
        cusip:
          example: string
          type: string
        description:
          example: string
          type: string
        factor:
          example: 0
          type: number
        maturityDate:
          example: string
          type: string
        symbol:
          example: string
          type: string
        variableRate:
          example: 0
          type: number
      type: object
    MarginAccount:
      properties:
        accountId:
          example: string
          type: string
        currentBalances:
          properties:
            accruedInterest:
              example: 0
              type: number
            availableFunds:
              example: 0
              type: number
            availableFundsNonMarginableTrade:
              example: 0
              type: number
            bondValue:
              example: 0
              type: number
            buyingPower:
              example: 0
              type: number
            buyingPowerNonMarginableTrade:
              example: 0
              type: number
            cashBalance:
              example: 0
              type: number
            cashReceipts:
              example: 0
              type: number
            dayTradingBuyingPower:
              example: 0
              type: number
            dayTradingBuyingPowerCall:
              example: 0
              type: number
            equity:
              example: 0
              type: number
            equityPercentage:
              example: 0
              type: number
            isInCall:
              type: boolean
            liquidationValue:
              example: 0
              type: number
            longMarginValue:
              example: 0
              type: number
            longMarketValue:
              example: 0
              type: number
            longOptionMarketValue:
              example: 0
              type: number
            maintenanceCall:
              example: 0
              type: number
            maintenanceRequirement:
              example: 0
              type: number
            marginBalance:
              example: 0
              type: number
            moneyMarketFund:
              example: 0
              type: number
            mutualFundValue:
              example: 0
              type: number
            optionBuyingPower:
              example: 0
              type: number
            pendingDeposits:
              example: 0
              type: number
            regTCall:
              example: 0
              type: number
            savings:
              example: 0
              type: number
            shortBalance:
              example: 0
              type: number
            shortMarginValue:
              example: 0
              type: number
            shortMarketValue:
              example: 0
              type: number
            shortOptionMarketValue:
              example: 0
              type: number
            sma:
              example: 0
              ty

# --- truncated at 32 KB (63 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/td-ameritrade/refs/heads/main/openapi/td-ameritrade-accounts-and-trading-api-openapi.yml