Autonomous portfolio rebalancing agent for X Layer using OnchainOS
This skill runs an autonomous portfolio rebalancing agent on X Layer (Chain ID 196). It monitors your token allocations and automatically executes swaps to maintain your target portfolio weights using the onchainos CLI.
The agent includes a web dashboard with live allocation charts, paper-trade mode (default), security scanning, and drift-based triggers.
This agent is provided for educational and hackathon demonstration purposes only. It does not constitute investment advice.
Install onchainos CLI (>= 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
Log in to Agentic Wallet:
onchainos wallet login <your-email>
onchainos wallet status
Find token addresses:
onchainos token search --chain xlayer --query USDT
onchainos token search --chain xlayer --query OKB
Edit scripts/config.py with your target allocation.
cd scripts
python3 agent.py
Dashboard opens at http://localhost:3197
All parameters in scripts/config.py:
| Parameter | Default | Description |
|---|---|---|
DRY_RUN | True | Paper mode (quote only) |
DRIFT_THRESHOLD | 5.0 | Rebalance trigger (% drift) |
CHECK_INTERVAL | 300 | Seconds between checks |
TARGET_PORTFOLIO | 60/40 OKB/USDT | Target weights (must sum to 1.0) |
MAX_SWAP_AMOUNT_USD | 50.0 | Max single swap in USD |
SLIPPAGE | 0.5 | Max slippage % for live swaps |
| Skill | Purpose |
|---|---|
okx-agentic-wallet | Wallet auth, balance, addresses |
okx-dex-swap | Swap quotes and execution |
okx-dex-market | Token price data |
okx-security | Token safety scanning |
okx-dex-token | Token search and discovery |
User sets TARGET_PORTFOLIO in config.py
|
v
+------------------+
| Rebalance Cycle |
| |
| 1. Get balances | <-- onchainos wallet balance
| 2. Get prices | <-- onchainos market prices
| 3. Compute drift |
| 4. Plan trades |
| 5. Security scan | <-- onchainos security scan
| 6. Execute swaps | <-- onchainos swap
+------------------+
|
v
Web Dashboard (port 3197)