Autonomous DCA agent that periodically swaps tokens on X Layer via OnchainOS
This skill runs an autonomous Dollar-Cost Averaging (DCA) agent on X Layer (Chain ID 196). It periodically swaps a fixed amount of one token (e.g. USDT) into a target token (e.g. OKB) using the onchainos CLI for wallet operations, market data, security scanning, and swap execution.
The agent includes a web dashboard, paper-trade mode (default), stop-loss protection, and per-session spending limits.
This agent is provided for educational and hackathon demonstration purposes only. It does not constitute investment advice.
DRY_RUN = True).
No real funds are spent until you explicitly switch to live mode.Recommendation: Run in Paper Mode first. After understanding the agent behavior, consider whether to enable Live Mode with small amounts.
Before using this skill, ensure:
The onchainos CLI is installed (>= 2.0.0):
# Windows (PowerShell)
irm https://raw.githubusercontent.com/okx/onchainos-skills/main/install.ps1 | iex
# macOS / Linux
curl -sSL https://raw.githubusercontent.com/okx/onchainos-skills/main/install.sh | sh
If onchainos is not found after install, add to PATH:
export PATH="$HOME/.local/bin:$PATH"
Log in to Agentic Wallet (one-time, email verification):
onchainos wallet login <your-email>
onchainos wallet status
# Confirm: loggedIn: true
Confirm X Layer wallet address:
onchainos wallet addresses --chain 196
Find token contract addresses on X Layer:
onchainos token search --chain xlayer --query USDT
onchainos token search --chain xlayer --query OKB
Set token addresses in scripts/config.py:
FROM_TOKEN = USDT contract addressTO_TOKEN = target token contract addressPython 3.8+ installed (standard library only, no pip packages needed).
dca-swap-agent/
├── scripts/
│ ├── agent.py # Main DCA agent loop
│ └── config.py # All parameters (hot-reload)
├── SKILL.md # This file
├── .claude-plugin/
│ └── plugin.json # Claude skill metadata
├── .env.example # API key template
├── LICENSE
└── README.md
onchainos token search --chain xlayer --query USDT
When to use: Before first run, to find the contract addresses for FROM_TOKEN and TO_TOKEN on X Layer. Output: Token name, symbol, contract address, decimals.
onchainos wallet balance --chain 196
When to use: To verify the agent wallet has sufficient funds before starting. Output: List of token balances on X Layer.
onchainos market prices --tokens 196:<token_address>
When to use: To view the current price of the target token. Output: Current USD price, 24h change.
onchainos security token-scan --address <token_address> --chain xlayer
When to use: To verify a token is safe before adding it as TO_TOKEN. Output: Risk level, honeypot status, tax rate.
onchainos swap quote --from <from_token> --to <to_token> --amount <amount_raw> --chain xlayer
When to use: To preview a swap without executing it. Output: Expected output amount, price impact, route.
onchainos swap swap --from <from_token> --to <to_token> --amount <amount_raw> --chain xlayer --wallet <address> --slippage 0.5
When to use: Only when DRY_RUN = False in config.py. Executes a real swap via TEE signing.
Output: Transaction hash, amounts swapped.
cd scripts
python3 agent.py
When to use: To start the autonomous DCA loop. Output: Logs each DCA cycle to stdout. Dashboard at http://localhost:3196.
Press Ctrl+C in the terminal, or:
pkill -f agent.py
When a user requests to start this strategy, follow this procedure.
Show the user:
DCA Swap Agent v1.0.0 - X Layer
This agent periodically buys a target token using a fixed amount.
Default: 1.0 USDT per swap, every 5 minutes.
Includes stop-loss, spending limits, and security scanning.
Current mode: PAPER (no real funds spent)
Dashboard: http://localhost:3196
Risk: On-chain trading carries high risk. You may lose all capital.
Ask the user:
Then:
onchainos token search --chain xlayer --query <token> to find addresses.config.py.PAUSED = False to start.If Live Mode:
DRY_RUN = False in config.py.SWAP_AMOUNT + RESERVE_AMOUNT.onchainos --version, onchainos wallet statuscd scripts && python3 agent.pyIf user says "just run it" -> launch with defaults in Paper Mode, set PAUSED = False.
All parameters are in scripts/config.py. Changes take effect on the next cycle
(hot-reload via importlib.reload, no restart needed).
| Need | Modify in config.py |
|---|---|
| Pause/Resume | PAUSED = True/False |
| Paper/Live mode | DRY_RUN = True/False |
| Swap size | SWAP_AMOUNT = 1.0 |
| Swap interval | INTERVAL_SECONDS = 300 |
| Max total spend | MAX_TOTAL_SPEND = 50.0 |
| Max swaps | MAX_SWAPS = 200 |
| Stop-loss threshold | STOP_LOSS_PCT = 30.0 |
| Slippage tolerance | SLIPPAGE = 0.5 |
| Reserve (never spend) | RESERVE_AMOUNT = 1.0 |
| Target token | TO_TOKEN = "0x..." |
| Source token | FROM_TOKEN = "0x..." |
| Error | Cause | Resolution |
|---|---|---|
| "onchainos CLI not found" | CLI not installed or not in PATH | Install via install.ps1 or install.sh, add ~/.local/bin to PATH |
| "No X Layer address found" | Wallet not logged in | Run onchainos wallet login <email> |
| "Insufficient balance" | Not enough FROM_TOKEN | Add funds to the wallet or reduce SWAP_AMOUNT |
| "Price unavailable" | Token not listed or API issue | Verify TO_TOKEN address with onchainos token search |
| "SAFETY REJECT" | Token failed security scan | Choose a different token or verify the address |
| "STOP LOSS" | Price dropped beyond threshold | Review market conditions; adjust STOP_LOSS_PCT if intended |
| "MAX_TOTAL_SPEND reached" | Budget exhausted | Increase MAX_TOTAL_SPEND or stop the agent |
| "Swap failed" | Network issue or insufficient gas | Check X Layer RPC status; ensure wallet has OKB for gas |
| "Timeout" | onchainos CLI took too long | Retry automatically on next cycle; check network |
| Dashboard port in use | Port 3196 occupied | Change DASHBOARD_PORT in config.py |
DRY_RUN = False.okx-dex-swap skillokx-wallet-portfolio skillokx-security skillokx-dex-token skillokx-dex-market skill