Guide

DCA API Documentation

API

OpenOcean DCA API Integration Guide

OpenOcean provides an API interface for DCA (Dollar-Cost Averaging) trading, enabling developers to implement automated swaps. This guide will introduce how to use this feature's API.

Currently we only support the Base chain, and will expand to other EVM chains in the near future. Below are the OpenOcean DCA contract addresses on Base:

DCA V1 contract address: 0x7F727EB80183D5dE9bdd11dF6b8C402bab1DF147

DCA V2 contract address: 0x6cBB2598881940D08d5Ea3fA8F557E02996e1031 *If you're the first time integrating our DCA, please use the V2 contract address. V1 will be deprecated soon.

DCA Overview

The DCA feature allows users to automatically invest fixed amounts at regular intervals on the OpenOcean.

DCA Trading in 3 Steps

  1. Create DCA Order

  2. Cancel DCA Order (Optional)

  3. Query User Orders

1. Create DCA Order

Set up your automatic investment plan by choosing how much and how often you want to invest.

Example request:

import axios from 'axios';
const response = await axios({
    url: 'https://open-api.openocean.finance/v1/8453/dca/swap',
    method: 'POST',
    data: {
      "makerAmount": "20000000", // total amount with decimals
      "takerAmount": "19983700", // optional,  with decimals
      "signature": "0x37e6...", // user sign messagae, get from the frontend sdk
      "orderHash": "0x8e89...", //order hash, get from the frontend sdk
      "orderMaker": "0xB3cb...",// wallet address
      "remainingMakerAmount": "20000000", // remaing amount
      "data": {
        "salt": "", // get from the frontend sdk
        "makerAsset": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", // token address
        "takerAsset": "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA", // token address
        "maker": "0xB3cb...", // wallet address
        "receiver": "0x0000000000000000000000000000000000000000", // default value
        "allowedSender": "0x0000000000000000000000000000000000000000", // default value
        "makingAmount": "20000000", // with decimals
        "takingAmount": "19983700", // with decimals
        "makerAssetData": "0x", // default value, get from the frontend sdk
        "takerAssetData": "0x", // default value, get from the frontend sdk
        "getMakerAmount": "0x", // default value
        "getTakerAmount": "0x", // default value
        "predicate": "0x", // default value, get from the frontend sdk
        "permit": "0x", // default value, get from the frontend sdk
        "interaction": "0x" // get from the frontend sdk
      },
      "isActive": true,
      "chainId": 8453, // chainId
      "expireTime": 600, // expire time s, time * times
      "amountRate": "1.000816", // makerAmount/takerAmount
      "interaction": "0x", // default value
      "time": 300, // interval time, s
      "times": 2, // frequency
      "minPrice": "0.9", // optional, price range
      "maxPrice": "1.1" // optional, price range
      "version": "v2", // default as v1. Please use v2 for the first time integration.
      "referrer": "0xxxxxxxxxxxxxxxxxxx" // optional. It's the EOA address to set up fees and track data from your end.
      "referrerFee": "1" // optional. e.g.'1'= 1%. Enter the num to charge the platform fee on your end. 
    }
});

Example response:

{
  code: 200,
}

2. Cancel DCA Order

Cancel your automatic trading plan at any time.

Example request:

import axios from 'axios';
const response = await axios({
    url: 'https://open-api.openocean.finance/v1/8453/dca/cancel',
    method: 'POST',
    data: {
        orderHash: "0x1e48.."
    }
});

Example response:

{
  code: 200,
}

3. Query User Orders

Check your active and completed automatic trades.

Example request:

import axios from 'axios';
const response = await axios({
    url: 'https://open-api.openocean.finance/v1/8453/dca/address/0xb3cbeff0336baa4863cb51238bd6c35bdaab3d84',
    method: 'GET',
    params: {
      page: 1,
      limit: 10,
      statuses: [1,2,5],
      sortBy: "createDateTime",
    }
});

Example response:

{
  "code": 200,
  "data": [
    {
      "makerAmount": "10000000",
      "takerAmount": "9989600",
      "signature": "0x000..",
      "orderHash": "0xac1c191974a06c260f0abdffc778d100c30926ccd0208d44b392adbef292732a",
      "createDateTime": "2024-06-20T05:43:20.000Z",
      "orderMaker": "0xB3cbefF0336BaA4863Cb51238bD6C35BDAaB3D84",
      "remainingMakerAmount": "10000000",
      "makerBalance": null,
      "makerAllowance": null,
      "expireTime": "2028-04-20T05:43:20.000Z",
      "statuses": 1,
      "time": 60480000,
      "times": 2,
      "have_filled": 1,
      "minPrice": null,
      "maxPrice": null,
      "data": {},
      "makerRate": null,
      "takerRate": null
    },
  ]
}

Important Notes

a) All amounts must include token decimals

b) Use status parameters for efficient filtering

c) Verify minimum amounts before order creation

d) Monitor order execution progress

Last updated