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

# Initiate Atomic Swap

> Start an atomic swap between RGB assets

## Atomic Swap Flow

1. Get a quote using `/api/v1/market/quote`
2. Initiate the swap with this endpoint
3. Confirm the swap using `/api/v1/swaps/execute`

<Warning>Swaps must be confirmed within the quote expiration time.</Warning>


## OpenAPI

````yaml /openapi.json post /api/v1/swaps/init
openapi: 3.1.0
info:
  title: Kaleidoswap RGB-LSP API
  description: API for managing swaps and channels
  version: 0.1.0
servers: []
security: []
paths:
  /api/v1/swaps/init:
    post:
      tags:
        - swaps
      summary: Initiate Swap
      operationId: initiate_swap_api_v1_swaps_init_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SwapResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: javascript
          label: TypeScript SDK - Initialize Swap
          source: >-
            import { KaleidoClient } from 'kaleido-sdk';


            const client = new KaleidoClient({
              baseUrl: 'https://api.staging.kaleidoswap.com/api/v1'
            });


            // First get a quote

            const quote = await client.quoteRequest('BTC',
            'rgb:im7mWgoS-4QX_1b1-DT23iPq-niObDFM-qGN7R2x-lFLJYak', 1000000);


            // Initialize the swap

            const swap = await client.initMakerSwap({
              rfq_id: quote.rfq_id,
              from_asset: 'BTC',
              to_asset: 'rgb:im7mWgoS-4QX_1b1-DT23iPq-niObDFM-qGN7R2x-lFLJYak',
              from_amount: 1000000,
              to_amount: quote.to_amount
            });

            console.log(`Swap initialized: ${swap.payment_hash}`);
        - lang: python
          label: Python SDK - Initialize Swap
          source: |-
            import asyncio
            from kaleido_sdk import KaleidoClient, InitMakerSwapRequest

            async def main():
                async with KaleidoClient(
                    api_url="https://api.staging.kaleidoswap.com/api/v1"
                ) as client:
                    # First get a quote
                    quote = await client.get_quote(
                        from_asset="BTC",
                        to_asset="rgb:im7mWgoS-4QX_1b1-DT23iPq-niObDFM-qGN7R2x-lFLJYak",
                        amount=1000000
                    )
                    
                    # Initialize the swap
                    swap = await client.init_maker_swap(
                        InitMakerSwapRequest(
                            rfq_id=quote.rfq_id,
                            from_asset="BTC",
                            to_asset="rgb:im7mWgoS-4QX_1b1-DT23iPq-niObDFM-qGN7R2x-lFLJYak",
                            from_amount=1000000,
                            to_amount=quote.to_amount
                        )
                    )
                    print(f"Swap initialized: {swap.payment_hash}")

            asyncio.run(main())
components:
  schemas:
    SwapRequest:
      properties:
        rfq_id:
          type: string
          title: Rfq Id
          example: '1234567890'
        from_asset:
          type: string
          title: From Asset
          example: BTC
        from_amount:
          type: integer
          title: From Amount
          example: 1000000
        to_asset:
          type: string
          title: To Asset
          example: rgb:2dkSTbr-jFhznbPmo-TQafzswCN-av4gTsJjX-ttx6CNou5-M98k8Zd
        to_amount:
          type: integer
          title: To Amount
          example: 1000000
      type: object
      required:
        - rfq_id
        - from_asset
        - from_amount
        - to_asset
        - to_amount
      title: SwapRequest
    SwapResponse:
      properties:
        swapstring:
          type: string
          title: Swapstring
          example: >-
            30/rgb:2dkSTbr-jFhznbPmo-TQafzswCN-av4gTsJjX-ttx6CNou5-M98k8Zd/10/rgb:2eVw8uw-8G88LQ2tQ-kexM12SoD-nCX8DmQrw-yLMu6JDfK-xx1SCfc/1715896416/9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2
        payment_hash:
          type: string
          title: Payment Hash
          example: 9d342c6ba006e24abee84a2e034a22d5e30c1f2599fb9c3574d46d3cde3d65a2
      type: object
      required:
        - swapstring
        - payment_hash
      title: SwapResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````