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

# Create DCA Order

> Generate calldata to create a dollar-cost averaging order on-chain

## Overview

Creates a DCA (Dollar-Cost Averaging) order that automatically executes recurring swaps at specified intervals. Each order is deployed as a dedicated smart contract that manages your funds and executes trades autonomously.

## Request

<ParamField body="traderAddress" type="string" required>
  Address that will own the DCA order
</ParamField>

<ParamField body="sellTokenAddress" type="string" required>
  Token to sell over time
</ParamField>

<ParamField body="sellAmount" type="string" required>
  Total amount to sell across all cycles
</ParamField>

<ParamField body="sellAmountPerCycle" type="string" required>
  Amount to sell in each cycle
</ParamField>

<ParamField body="buyTokenAddress" type="string" required>
  Token to purchase
</ParamField>

<ParamField body="frequency" type="string" required>
  ISO 8601 duration format (e.g., "P1D" for daily, "PT12H" for 12 hours)

  * `PT1H` - Every hour
  * `PT6H` - Every 6 hours
  * `P1D` - Daily
  * `P1W` - Weekly
  * `P1M` - Monthly
</ParamField>

<ParamField body="startDate" type="string">
  ISO 8601 start date (defaults to now)
</ParamField>

<ParamField body="pricingStrategy" type="object" required>
  Price constraints for order execution

  <Expandable title="properties">
    <ParamField body="tokenToMinAmount" type="string">
      Minimum acceptable buy amount per cycle (hex format)
    </ParamField>

    <ParamField body="tokenToMaxAmount" type="string">
      Maximum acceptable buy amount per cycle (hex format)
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="chainId" type="string" required>
  Network identifier (e.g., "0x534e5f4d41494e")
</ResponseField>

<ResponseField name="calls" type="array" required>
  Array of transaction calls to create the order

  <Expandable title="Call Object">
    <ResponseField name="contractAddress" type="string" required>
      Contract to call
    </ResponseField>

    <ResponseField name="entrypoint" type="string" required>
      Function to call
    </ResponseField>

    <ResponseField name="calldata" type="array" required>
      Function arguments
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://starknet.api.avnu.fi/dca/v3/orders" \\
    -H "Content-Type: application/json" \\
    -d '{
      "traderAddress": "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
      "sellTokenAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
      "sellAmount": "1000000000000000000",
      "sellAmountPerCycle": "100000000000000000",
      "buyTokenAddress": "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
      "frequency": "P1D",
      "pricingStrategy": {
        "tokenToMinAmount": null,
        "tokenToMaxAmount": null
      }
    }'
  ```

  ```typescript TypeScript theme={null}
  // Create a DCA order to buy $100 USDC daily with ETH
  const response = await fetch('https://starknet.api.avnu.fi/dca/v3/orders', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      traderAddress: account.address,
      sellTokenAddress: ETH_ADDRESS,
      sellAmount: ethers.parseEther("1"), // 1 ETH total
      sellAmountPerCycle: ethers.parseEther("0.1"), // 0.1 ETH per day
      buyTokenAddress: USDC_ADDRESS,
      frequency: "P1D", // Daily
      pricingStrategy: {
        tokenToMinAmount: null, // No minimum (market order)
        tokenToMaxAmount: null  // No maximum
      }
    })
  });

  const { calls } = await response.json();

  // Execute the calls to create the order
  await account.execute(calls);
  ```

  ```python Python theme={null}
  import requests
  from datetime import datetime

  # Create a weekly DCA order
  order_data = {
      'traderAddress': account_address,
      'sellTokenAddress': ETH_ADDRESS,
      'sellAmount': str(10**18),  # 1 ETH total
      'sellAmountPerCycle': str(10**17 * 25 // 100),  # 0.25 ETH per week
      'buyTokenAddress': STRK_ADDRESS,
      'frequency': 'P1W',  # Weekly
      'startDate': datetime.now().isoformat(),
      'pricingStrategy': {
          'tokenToMinAmount': null,  # No minimum (market order)
          'tokenToMaxAmount': null   # No maximum
      }
  }

  response = requests.post(
      'https://starknet.api.avnu.fi/dca/v3/orders',
      json=order_data,
  )

  calls = response.json()['calls']
  # Execute calls through your account
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "chainId": "0x534e5f4d41494e",
    "calls": [
      {
        "contractAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
        "entrypoint": "approve",
        "calldata": [
          "0x073f6e3f2e5f8f8e7d3d2b1a0c9b8a7f6e5d4c3b2a1",
          "0xde0b6b3a7640000",
          "0x0"
        ]
      },
      {
        "contractAddress": "0x073f6e3f2e5f8f8e7d3d2b1a0c9b8a7f6e5d4c3b2a1",
        "entrypoint": "deploy_dca_order",
        "calldata": [
          "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
          "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
          "0xde0b6b3a7640000",
          "0x16345785d8a0000",
          "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
          "0x15180",
          "0x0",
          "0x1"
        ]
      }
    ]
  }
  ```
</ResponseExample>

## Order Calculation

<Info>
  **Number of cycles** = Total Amount ÷ Amount Per Cycle

  **Duration** = Number of Cycles × Frequency

  Example: 1 ETH total, 0.1 ETH per cycle, daily frequency = 10 days duration
</Info>
