DCA.fun Pig LogoDCA.fun
API Reference

Order Creation API

Get Chainlink price reports for creating DCA orders on-chain

Order Creation API

The Order Creation API provides Chainlink Data Streams price reports required when creating DCA orders on-chain. These endpoints fetch verified price data that must be included in the smart contract createOrder transaction.

Endpoints

Get Latest Price Report

GET https://api.dca.fun/createorder?tokenFeedId={feedId}&chainId={chainId}

Fetches the latest Chainlink Data Streams price report for a specific token feed.

Request Parameters

ParameterTypeRequiredDescription
tokenFeedIdstringYesChainlink feed ID (32-byte hex string starting with 0x)
chainIdintegerYesBlockchain network ID (1, 137, 8453, 42161, 10, 84532)

Response Format

{
  "unverifiedReport": [
    "0x0006f9b553e393ced311551055a5028b580461b2304d48139c8551a749..."
  ],
  "decodedReport": {
    "feedId": "0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6",
    "validFromTimestamp": 1704067200,
    "observationsTimestamp": 1704067205,
    "nativeFee": "1000000000000000",
    "linkFee": "5000000000000000000",
    "expiresAt": 1704067500,
    "price": "3000000000000000000000"
  }
}

Response Fields

FieldTypeDescription
unverifiedReportarrayArray of hex-encoded Chainlink reports (pass to createOrder)
decodedReportobjectHuman-readable decoded price data
decodedReport.feedIdstringChainlink feed identifier
decodedReport.validFromTimestampintegerUnix timestamp when report becomes valid
decodedReport.observationsTimestampintegerUnix timestamp of price observation
decodedReport.nativeFeestringFee in native token (wei)
decodedReport.linkFeestringFee in LINK token (wei)
decodedReport.expiresAtintegerUnix timestamp when report expires
decodedReport.pricestringToken price (18 decimals)

Code Examples

// Get latest price report for USDC on Base
const feedId = '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6';
const chainId = 8453;

const response = await fetch(
  `https://api.dca.fun/createorder?tokenFeedId=${feedId}&chainId=${chainId}`
);
const { unverifiedReport, decodedReport } = await response.json();

console.log('Price:', decodedReport.price);
console.log('Valid until:', new Date(decodedReport.expiresAt * 1000));

// Use unverifiedReport when creating order on-chain
const tx = await dcaContract.createOrder(
  orderArgs,
  unverifiedReport
);
import requests

# Get latest price report for USDC on Base
feed_id = '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6'
chain_id = 8453

response = requests.get(
    'https://api.dca.fun/createorder',
    params={'tokenFeedId': feed_id, 'chainId': chain_id}
)
data = response.json()

print(f"Price: {data['decodedReport']['price']}")
print(f"Expires at: {data['decodedReport']['expiresAt']}")

# Use unverifiedReport when creating order on-chain
tx = dca_contract.functions.createOrder(
    order_args,
    data['unverifiedReport']
).transact()
# Get latest price report for USDC on Base
curl "https://api.dca.fun/createorder?tokenFeedId=0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6&chainId=8453"

Creating an Order On-Chain

Fetch price reports for both tokens

// Get price reports for tokenIn and tokenOut
const [tokenInReport, tokenOutReport] = await Promise.all([
  fetch(
    `https://api.dca.fun/createorder?tokenFeedId=${tokenInFeedId}&chainId=8453`
  ).then((r) => r.json()),
  fetch(
    `https://api.dca.fun/createorder?tokenFeedId=${tokenOutFeedId}&chainId=8453`
  ).then((r) => r.json()),
]);

const unverifiedReports = [
  ...tokenInReport.unverifiedReport,
  ...tokenOutReport.unverifiedReport,
];

Prepare order arguments

const orderArgs = {
  recipient: "0x...", // Address to receive output tokens
  tokenIn: "0x...", // USDC address
  tokenOut: "0x...", // WETH address
  spendAmount: "100000000", // 100 USDC (6 decimals)
  repeats: 10, // Execute 10 times
  freqInterval: 86400, // Once per day (seconds)
  scalingInterval: 300, // 5 minutes (seconds)
  slippage: 100, // 1% (basis points)
  firstExecution: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
  stakeAssetIn: false, // Don't stake input in Aave
  stakeAssetOut: false, // Don't stake output in Aave
};

Approve tokens and create order

// Approve Permit2 to spend tokens
const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
await tokenInContract.approve(
  permit2Address,
  orderArgs.spendAmount * orderArgs.repeats
);

// Create the order
const tx = await dcaContract.createOrder(orderArgs, unverifiedReports);
await tx.wait();

console.log("Order created! Transaction:", tx.hash);

Important: - Price reports have expiration times (expiresAt). Create orders before expiration. - You need price reports for BOTH tokenIn and tokenOut. - Ensure you have approved Permit2 before calling createOrder. - For native ETH orders, use createOrderNative instead.