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

# Dex - 兌換

> 兌換參數，包括輸入代幣、輸出代幣、數量和滑點



## OpenAPI

````yaml /zh-Hant/api-reference/openapi-defi-zh-Hant.yaml POST /v2/dex/{chain}/swap
openapi: 3.1.0
info:
  title: Defi Service API
  description: Defi Service API ⚡️
  version: '1.0'
  contact:
    name: AI
    url: https://github.com/chainstream-io/defi-service
    email: ai@sx.ai
servers:
  - url: https://api.chainstream.io
    description: Production
security: []
tags:
  - name: Endpoints
    description: ''
paths:
  /v2/dex/{chain}/swap:
    post:
      tags:
        - Dex
      summary: Dex - 兌換
      description: 兌換參數，包括輸入代幣、輸出代幣、數量和滑點
      operationId: swap
      parameters:
        - name: chain
          required: true
          in: path
          description: 支援網路列表中的鏈名稱
          schema:
            $ref: '#/components/schemas/ChainSymbol'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapInput'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapReply'
      security:
        - bearer: []
components:
  schemas:
    ChainSymbol:
      type: string
      enum:
        - sol
        - bsc
        - eth
    SwapInput:
      type: object
      properties:
        dex:
          type: string
          description: 交易所使用的 DEX 標識符
          example: jupiter
          enum:
            - jupiter
            - kyberswap
            - raydium
            - pumpfun
            - moonshot
            - candy
            - launchpad
        userAddress:
          type: string
          description: 發起交易的錢包公鑰
          example: oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7
          minLength: 8
          maxLength: 64
        priorityFee:
          type: string
          description: 優先費（SOL），用於提高交易處理速度
          example: '1000'
        poolAddress:
          type: string
          description: DEX 池子地址
          example: 58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2
        amount:
          type: string
          description: 兌換數量。使用 "auto" 表示全部餘額，或使用百分比如 "50%"
          example: '1000000000'
        swapMode:
          type: string
          description: 兌換方向模式
          enum:
            - ExactIn
            - ExactOut
          example: ExactIn
        slippage:
          type: integer
          description: 滑點容忍百分比
          example: 10
          default: 10
          minimum: 0
          maximum: 100
          format: int64
        inputMint:
          type: string
          description: 輸入代幣鑄造地址
        outputMint:
          type: string
          description: 輸出代幣鑄造地址
      required:
        - dex
        - userAddress
        - amount
        - swapMode
        - slippage
    SwapReply:
      type: object
      properties:
        serializedTx:
          type: string
          description: Base64 編碼的交易
          example: >-
            AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDRgYGpQEDAQIABQcICQoLDA0ODwAAAAAAAAAAAAAQERITFBUWFxgZGhscHR4fAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
        elapsedTime:
          type: integer
          description: 請求處理耗時（毫秒）
          example: 245
          format: int64
      required:
        - serializedTx
        - elapsedTime
  securitySchemes:
    bearer:
      scheme: bearer
      bearerFormat: JWT
      type: http

````