DCA.fun Pig LogoDCA.fun
API Reference

Quote API

Get execution quotes and profitability data for DCA orders

Quote API

The Quote API provides comprehensive execution data for DCA orders, enabling fillers to calculate profitability and execute orders on-chain with real-time Chainlink price data.

Endpoint

GET https://api.dca.fun/quote?orderId={orderId}&chainId={chainId}

This endpoint calculates execution parameters for filling a DCA order, essential for:

  • Gas cost estimation and profitability analysis
  • Determining optimal scaling factors for dynamic slippage
  • Validating executability with current prices
  • Calculating exact input/output amounts before execution

Request Parameters

ParameterTypeRequiredDescription
orderIdintegerYesUnique identifier of the DCA order
chainIdintegerYesBlockchain network ID (e.g., 1 for Ethereum, 137 for Polygon)

Response Format

{
  "encodedData": "0x000000000000000000000000000000000000000000000000000000000000007b...",
  "fillableAmount": "100000000",
  "amountOfTokenOut": "33333333333333333",
  "scalingFactor": "1000",
  "tokenInPrice": "1000000000000000000",
  "tokenOutPrice": "3000000000000000000000"
}
CALL_EXCEPTION: OrderNotFillable

Response Fields

FieldTypeDescription
encodedDatastringHex-encoded orderId and Chainlink oracle reports for execution
fillableAmountstringAmount of tokenIn that can be filled (in smallest unit)
amountOfTokenOutstringCalculated output amount (in smallest unit)
scalingFactorstringScaling factor applied (1e18 = 100%)
tokenInPricestringCurrent tokenIn price from Chainlink
tokenOutPricestringCurrent tokenOut price from Chainlink

Error Responses

StatusError MessageDescription
400Missing/invalid parametersorderId or chainId missing or non-integer
400Unconfigured chainChain ID not supported
500Contract exceptionOrder doesn't exist or is inactive
502Oracle errorMissing Chainlink price feeds

How It Works

  1. Validates parameters and chain support
  2. Queries smart contract for order token details and feed IDs
  3. Fetches real-time Chainlink price reports in parallel
  4. Calculates fillable amounts and scaling via contract quote function
  5. Returns comprehensive execution data

Code Examples

// Get execution parameters
const response = await fetch(
  'https://api.dca.fun/quote?orderId=123&chainId=8453'
);
const quote = await response.json();

console.log('Fillable amount:', quote.fillableAmount);
console.log('Output amount:', quote.amountOfTokenOut);
console.log('Scaling factor:', quote.scalingFactor);

// Execute on-chain using encoded data
const tx = await dcaContract.fillOrder(
  quote.encodedData,
  recipientAddress
);
await tx.wait();
import requests

# Get execution parameters
response = requests.get(
    'https://api.dca.fun/quote',
    params={'orderId': 123, 'chainId': 8453}
)
quote = response.json()

print(f"Fillable amount: {quote['fillableAmount']}")
print(f"Output amount: {quote['amountOfTokenOut']}")
print(f"Scaling factor: {quote['scalingFactor']}")

# Execute on-chain (using web3.py)
tx = dca_contract.functions.fillOrder(
    quote['encodedData'],
    recipient_address
).transact()
# Get execution parameters
curl "https://api.dca.fun/quote?orderId=123&chainId=8453"

Understanding Prices

Token prices from Chainlink Data Streams are represtned as 18 decimals

  • Always verify feed specifications for accurate calculations