> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phoenix.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# Build spot collateral swap transaction

> Builds an unsigned swap transaction for a trader account. User callers must authenticate as the wallet named by `authority`; service accounts with the route scope may build for any authority.



## OpenAPI

````yaml /openapi/phoenix-public-api.json post /v1/ix/swap
openapi: 3.1.0
info:
  title: Phoenix Eternal API
  description: >-
    RESTful API for accessing Phoenix Eternal perpetual trading data. Provides
    real-time orderbook levels, asset information, and market metadata.
  termsOfService: https://www.phoenix.trade/terms-of-service
  contact:
    name: Phoenix Development Team
    url: https://github.com/Ellipsis-Labs/phoenix
  license:
    name: Proprietary
  version: 1.0.0
servers:
  - url: https://perp-api.phoenix.trade
    description: Phoenix Eternal Perp API
security: []
tags:
  - name: Auth
    description: Wallet and session authentication.
  - name: Exchange
    description: Exchange, market, candle, and no-referral register-instruction workflows.
  - name: Invite
    description: Invite validation, referral activation, and wallet allowlist checks.
  - name: Notifications
    description: Trader notification reads and acknowledgement helpers.
  - name: Trader
    description: Trader state, account history, and transaction builders.
externalDocs:
  url: https://docs.phoenix.trade
  description: Phoenix developer documentation
paths:
  /v1/ix/swap:
    post:
      tags:
        - Trader
      summary: Build spot collateral swap transaction
      description: >-
        Builds an unsigned swap transaction for a trader account. User callers
        must authenticate as the wallet named by `authority`; service accounts
        with the route scope may build for any authority.
      operationId: post.v1.ix.swap
      requestBody:
        description: JSON request payload for `post.v1.ix.swap`.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BuildSwapTransactionRequest'
            example:
              assetIn: sol
              assetOut: sol
              authority: string
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BuildSwapTransactionResponse'
          description: Successful response
        '400':
          $ref: '#/components/responses/ErrorResponse'
        '401':
          $ref: '#/components/responses/ErrorResponse'
        '403':
          $ref: '#/components/responses/ErrorResponse'
        '429':
          $ref: '#/components/responses/ErrorResponse'
      security:
        - PhoenixBearerAuth: []
components:
  schemas:
    BuildSwapTransactionRequest:
      type: object
      description: >-
        Request payload for /v1/ix/swap.


        Venue configuration (venue list, base URLs, API keys, shared lookup

        tables, slippage bounds) is server-side; the request only selects what
        to

        swap and how to quote it.
      required:
        - authority
        - assetIn
        - assetOut
      properties:
        amountAtoms:
          type:
            - integer
            - 'null'
          format: int64
          description: >-
            Exact-in amount in atoms of `asset_in` (lamports for SOL, quote
            atoms

            for quote, mint atoms for spot). Exactly one of `amount_atoms` /

            `quantity` is required.
          minimum: 0
        assetIn:
          $ref: '#/components/schemas/SwapAsset'
          description: Asset sold (exact-in).
        assetOut:
          $ref: '#/components/schemas/SwapAsset'
          description: Asset bought. Must differ from `asset_in`.
        authority:
          type: string
          description: >-
            Wallet the trader PDA derives from. Without `position_authority` it
            is

            also the swapper: sole required signer of the `swap_native`

            instruction, owner of every token account the swap touches, and the

            default fee payer.
        collateralAmountAtoms:
          type:
            - integer
            - 'null'
          format: int64
          description: |-
            Beta quote->SOL swaps only: canonical quote collateral debited by
            `SwapNative` in quote atoms, decoupled from the venue amount.
            Defaults to the venue amount. Rejected on other deployments or
            directions.
          minimum: 0
        computeUnitPriceMicroLamports:
          type:
            - integer
            - 'null'
          format: int64
          description: >-
            Priority fee (compute unit price) in micro-lamports. A v0

            transaction carries it as a compute-budget instruction; a v1

            transaction carries `ceil(price * compute_unit_limit / 1e6)`
            lamports

            in its message config. Sponsored swaps must set fees here rather
            than

            recompiling the message, since the sponsorship attestation covers
            the

            exact compiled bytes.
          minimum: 0
        feePayer:
          type:
            - string
            - 'null'
          description: |-
            Fee payer for the compiled transaction; defaults to the swapper
            (`position_authority` when provided, else `authority`). Does not
            change the swap's signer, only who pays the transaction fee.
        positionAuthority:
          type:
            - string
            - 'null'
          description: >-
            Position authority delegated on the trader account. When provided it

            becomes the swapper: it signs `swap_native` and owns the staged
            token

            accounts in place of `authority`. The trader PDA still derives from

            `authority`.
        quantity:
          type:
            - number
            - 'null'
          format: double
          description: |-
            Exact-in amount in whole units of `asset_in` (e.g. 0.5 SOL);
            converted server-side using the input asset's decimals. Exactly one
            of `amount_atoms` / `quantity` is required.
        slippageBps:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Slippage tolerance override in basis points; clamped to the
            server-configured maximum.
          minimum: 0
        traderPdaIndex:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Which of the authority's trader PDAs the swap settles collateral
            against; defaults to 0.
          minimum: 0
        traderSubaccountIndex:
          type:
            - integer
            - 'null'
          format: int32
          description: |-
            Subaccount of the selected trader PDA the swap settles collateral
            against; defaults to 0 (cross-margin).
          minimum: 0
        transactionVersion:
          type:
            - integer
            - 'null'
          format: int32
          description: >-
            Transaction format to compile: `0` (default) for a v0 message with

            address lookup tables, `1` for a v1 message (SIMD-0385) that inlines

            every address and carries the compute budget in its config instead
            of

            compute-budget instructions. Other values are rejected.
          minimum: 0
        venue:
          type:
            - string
            - 'null'
          description: >-
            Restrict planning to the venue with this id from the server config

            (e.g. "jupiter"). By default every configured venue is quoted and
            the

            best minimum output wins.
    BuildSwapTransactionResponse:
      type: object
      description: |-
        Response payload for /v1/ix/swap.

        Carries the same plan twice: a compiled unsigned transaction for clients
        that sign and send as-is, and the instruction/lookup-table breakdown for
        clients that compile their own message (own blockhash, fee payer, and
        safety instructions).
      required:
        - transaction
        - transactionVersion
        - instructions
        - addressLookupTableAddresses
        - venue
        - amountInAtoms
        - swapNativeAmountInAtoms
        - expectedAmountOutAtoms
        - minAmountOutAtoms
        - priceImpactBps
        - contextSlot
        - computeUnitLimit
        - blockhash
        - lastValidBlockHeight
      properties:
        addressLookupTableAddresses:
          type: array
          items:
            type: string
          description: >-
            Address lookup tables the instructions require. A swap route does
            not

            fit in a legacy transaction, so client-side compilation must load

            these tables and compile a v0 message. Empty for v1.
        amountInAtoms:
          type: integer
          format: int64
          description: |-
            Venue-leg input amount in atoms of the input asset, after deducting
            the server-configured swap fee.
          minimum: 0
        attestationExpiresAt:
          type:
            - integer
            - 'null'
          format: int64
          description: Unix time at which `sponsorship_attestation` expires.
        blockhash:
          type: string
          description: Recent blockhash the transaction was compiled against.
        computeUnitLimit:
          type: integer
          format: int32
          description: Compute unit limit set on the compiled transaction.
          minimum: 0
        contextSlot:
          type: integer
          format: int64
          description: Slot the venue quoted at.
          minimum: 0
        expectedAmountOutAtoms:
          type: integer
          format: int64
          description: Venue's quoted output in atoms of the output asset.
          minimum: 0
        instructions:
          type: array
          items:
            $ref: '#/components/schemas/ApiInstructionResponse'
          description: |-
            The transaction's instructions for clients compiling their own
            message: compute budget first for v0, none for v1, then the swap.
        lastValidBlockHeight:
          type: integer
          format: int64
          description: |-
            Last block height at which `blockhash` (and therefore `transaction`)
            is valid.
          minimum: 0
        minAmountOutAtoms:
          type: integer
          format: int64
          description: |-
            Minimum output enforced on-chain, derived from the slippage
            tolerance.
          minimum: 0
        priceImpactBps:
          type: integer
          format: int32
          description: Venue-reported price impact in basis points.
          minimum: 0
        sponsorshipAttestation:
          type:
            - string
            - 'null'
          description: >-
            Provenance attestation over the compiled message, for the

            sponsorship server. Present only when the server has an attestation

            key configured. Issued for the swapper (`position_authority` when

            provided, else `authority`). Sign `transaction` verbatim and pass
            this

            through to POST /v1/sponsorship/transaction; any recompilation

            invalidates it.
        swapNativeAmountInAtoms:
          type: integer
          format: int64
          description: |-
            `SwapNative`'s collateral `amount_in`, including the swap fee;
            overridden on a beta buy with `collateral_amount_atoms` set.
          minimum: 0
        transaction:
          type: string
          description: >-
            Base64 wire bytes of the unsigned transaction (placeholder

            signatures) in the format `transaction_version` names, compiled

            against `blockhash`. v0 carries the compute budget as instructions
            and

            loads the resolved lookup tables; v1 carries it in the message
            config.
        transactionVersion:
          type: integer
          format: int32
          description: 'Message version of `transaction`: `0` or `1`.'
          minimum: 0
        venue:
          type: string
          description: Venue id that won the quote.
    SwapAsset:
      oneOf:
        - type: string
          description: Native SOL (lamports).
          enum:
            - sol
        - type: string
          description: The exchange's canonical quote token (quote atoms).
          enum:
            - quote
        - type: object
          description: |-
            SPL spot collateral identified by its base58 mint (mint atoms). Only
            supported as `asset_in`.
          required:
            - spot
          properties:
            spot:
              type: string
              description: >-
                SPL spot collateral identified by its base58 mint (mint atoms).
                Only

                supported as `asset_in`.
      description: >-
        The assets a Phoenix swap can move between. The direction of the swap is

        derived from which asset is the input: SOL or spot in means a sell,
        quote

        in means a buy.
    ApiInstructionResponse:
      type: object
      description: |-
        API representation of a Solana instruction.

        Note: this is a pure DTO. When needed, clients/servers can enable the
        appropriate conversion logic in the consumer crate to avoid forcing a
        Solana dependency in `phoenix-api-types`.
      required:
        - data
        - keys
        - programId
      properties:
        data:
          type: array
          items:
            type: integer
            format: int32
            minimum: 0
        keys:
          type: array
          items:
            $ref: '#/components/schemas/ApiAccountMeta'
        programId:
          type: string
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
    ApiAccountMeta:
      type: object
      description: Account metadata returned from instruction-building endpoints.
      required:
        - pubkey
        - isSigner
        - isWritable
      properties:
        isSigner:
          type: boolean
        isWritable:
          type: boolean
        pubkey:
          type: string
  responses:
    ErrorResponse:
      description: Standard JSON error payload.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    PhoenixBearerAuth:
      type: http
      scheme: bearer
      description: Bearer access token issued by `/v1/auth/*` login endpoints.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.