--- name: diptrade-cli description: Use when trading perpetual futures on DipCoin (Sui blockchain) via the `diptrade-cli` tool — placing buy/sell orders (market/limit, with TP/SL), managing positions, depositing/withdrawing USDC, vault operations (create/deposit/withdraw), account/balance/history queries, and referral. Covers install, credential setup via `diptrade-cli setup import` (existing key) or `diptrade-cli setup generate` (new wallet), and full command reference. --- # DipCoin Perpetual Trading CLI — Agent Skill Guide This document teaches AI agents (e.g. OpenClaw) how to install, configure, and use the `diptrade-cli` tool for perpetual futures trading on the Sui blockchain. ## Security **CRITICAL: The private key (`DIPCOIN_PRIVATE_KEY`) and mnemonic (`DIPCOIN_MNEMONIC`) must NEVER be exposed under any circumstances.** Do not log, print, echo, display, or include them in any output, error message, debug info, or API call. Never send them to any external service, chat, or third party. Treat them as the most sensitive data — leaking a private key means permanent loss of all funds in the wallet. ## Installation ```bash npm install -g diptrade-cli ``` After installation, the `diptrade-cli` command is available globally. ## Configuration Credentials are stored in a single global config file at `~/.config/dipcoin/env`. The recommended way to create it is via the built-in `setup` commands — both write the file with `chmod 600` and never echo the private key. ### Option A — Import an existing key For users who already have a Sui wallet: ```bash diptrade-cli setup import # mainnet (default) diptrade-cli setup import --network testnet ``` The command interactively prompts with **hidden input** (typed/pasted characters are not echoed). The user can paste **either** a private key (`suiprivkey1...`) **or** a BIP39 mnemonic (12/15/18/21/24 words from the English wordlist). The input is auto-detected and validated: - Private keys are decoded via the Sui bech32 scheme. - Mnemonics are validated against the BIP39 English wordlist **and** the checksum; invalid mnemonics are rejected. The validated credential is written to `~/.config/dipcoin/env` as `DIPCOIN_PRIVATE_KEY` or `DIPCOIN_MNEMONIC` accordingly. ### Option B — Generate a new key For users who do not yet have a wallet: ```bash diptrade-cli setup generate # mainnet (default) diptrade-cli setup generate --network testnet ``` A fresh Ed25519 keypair is created, saved to `~/.config/dipcoin/env`, and the public Sui address is printed. The user then transfers USDC (Sui network) to that address and deposits into the DEX with `diptrade-cli account deposit `. ### Config file format The file `~/.config/dipcoin/env` contains: | Variable | Required | Description | |----------|----------|-------------| | `DIPCOIN_PRIVATE_KEY` | One of these | Sui private key (`suiprivkey1...`), supports ED25519/Secp256k1/Secp256r1 | | `DIPCOIN_MNEMONIC` | is required | 12/15/18/21/24-word BIP39 mnemonic (derives ED25519 keypair at `m/44'/784'/0'/0'/0'`) | | `DIPCOIN_NETWORK` | No | `mainnet` or `testnet` (default: `mainnet`) | | `DIPCOIN_RPC_URL` | No | Sui gRPC-Web endpoint (default: public fullnode `https://fullnode..sui.io:443`, rate-limited). JSON-RPC URLs are not supported | If both are set, `DIPCOIN_PRIVATE_KEY` takes precedence. Manual editing is supported but discouraged — prefer the `setup` commands so permissions and format stay correct. ### Isolated agent environments When running multiple AI agents on the same machine, give each agent its own `HOME` so `~/.config/dipcoin/env` resolves to a separate wallet config. Reuse the same `HOME` for every command from that agent. ```bash mkdir -p /tmp/dipcoin-agent-a /tmp/dipcoin-agent-b HOME=/tmp/dipcoin-agent-a diptrade-cli setup generate HOME=/tmp/dipcoin-agent-b diptrade-cli setup generate HOME=/tmp/dipcoin-agent-a diptrade-cli --json account info HOME=/tmp/dipcoin-agent-b diptrade-cli --json account info ``` For vault delegation, each isolated agent can trade with its own wallet while targeting the vault account: ```bash HOME=/tmp/dipcoin-agent-a diptrade-cli --json trade buy BTC 100USDC 10x --vault ``` Keep the working directory clean when using isolated agent homes. The CLI also loads a `.env` file from the current working directory if one exists, so run agent commands from a scratch directory without a project `.env`, or make sure that local `.env` does not contain `DIPCOIN_PRIVATE_KEY`, `DIPCOIN_MNEMONIC`, or `DIPCOIN_NETWORK` for another wallet. ## Global Options These options apply to all commands and must be placed **before** the subcommand: ```bash diptrade-cli [global-options] [command-options] ``` | Option | Description | |--------|-------------| | `--json` | Output in JSON format (machine-readable, recommended for agents) | | `-V, --version` | Show version | **Important for agents:** Always use `--json` to get structured JSON output for parsing. ## Commands Reference ### Market Data (read-only, no auth needed) ```bash # List all available trading pairs diptrade-cli --json market pairs # Get ticker info (price, volume, funding rate) diptrade-cli --json market ticker BTC # Get order book diptrade-cli --json market orderbook BTC # Get oracle price diptrade-cli --json market oracle BTC # Get kline (candlestick) history — default: 1h interval, last 24h diptrade-cli --json market kline BTC diptrade-cli --json market kline BTC --interval 5m --count 10 diptrade-cli --json market kline BTC --interval 1d --from 1779000000 --to 1779800000 ``` Symbols auto-normalize: `BTC` becomes `BTC-PERP`. You can use either form. `market kline` supports intervals: `1m / 5m / 15m / 30m / 1h / 4h / 1d / 1w`. `--from` and `--to` are unix seconds (default: last 24h). `--count` caps the number of bars returned (most recent first). ### Account Information ```bash # Show account info (balance, margin, PnL) diptrade-cli --json account info # Show account info for a specific vault address diptrade-cli --json account info --vault
# Show on-chain coin balances diptrade-cli --json balance ``` ### Deposit & Withdraw (on-chain USDC operations) ```bash # Deposit USDC to exchange (required before trading) diptrade-cli account deposit # Withdraw USDC from exchange diptrade-cli account withdraw ``` ### Trading #### Open a position (USDC margin mode) The default mode: specify USDC margin amount and leverage. The CLI auto-converts to quantity based on current market price. ```bash # Buy BTC with 100 USDC margin at 10x leverage (market order) diptrade-cli trade buy BTC 100USDC 10x # Sell ETH with 50 USDC margin at 5x leverage diptrade-cli trade sell ETH 50USDC 5x # Limit order (auto-detected from --price) diptrade-cli trade buy BTC 100USDC 10x --price 95000 # With take-profit and stop-loss diptrade-cli trade buy BTC 100USDC 10x --tp 105000 --sl 90000 ``` #### Open a position (explicit quantity mode) ```bash # Buy 0.01 BTC at 10x leverage diptrade-cli trade buy BTC 0 10x --qty 0.01 # Sell 1 ETH at 5x leverage with limit price diptrade-cli trade sell ETH 0 5x --qty 1 --price 3500 ``` Note: When using `--qty`, the `` argument is ignored (use 0 as placeholder). #### Close a position ```bash # Close 100% of a position — CLI figures out side & quantity for you diptrade-cli position close BTC # Close half diptrade-cli position close BTC --percent 50 # Close every open position with one command diptrade-cli position close-all diptrade-cli position close-all --percent 50 # halve everything # Manual form is still supported if you want exact quantity control diptrade-cli trade sell BTC 0 10x --qty 0.01 --reduce-only # close long diptrade-cli trade buy ETH 0 5x --qty 1 --reduce-only # close short ``` `position close` and `position close-all` accept `--vault ` to target a vault's positions instead of the personal account. Closes use reduce-only market orders. #### Cancel orders ```bash diptrade-cli trade cancel [hash2...] ``` #### Adjust default leverage ```bash # Set default (ISOLATED) leverage for a market — used by future orders that don't pass an explicit value diptrade-cli trade leverage BTC 10 diptrade-cli trade leverage ETH 5 ``` Off-chain REST update — only changes the user's preferred leverage, no on-chain tx. The DipCoin perp currently runs ISOLATED margin only; CROSS is not supported. #### Trade options summary | Option | Description | |--------|-------------| | `--qty ` | Specify order quantity directly (bypasses USDC conversion) | | `--price

` | Limit order price (auto-enables LIMIT order type) | | `--reduce-only` | Reduce-only order (for closing positions) | | `--tp ` | Take profit trigger price | | `--sl ` | Stop loss trigger price | | `--vault

` | Vault/creator address (for trading vault positions) | ### Positions ```bash # List all open positions diptrade-cli --json position list # Filter by symbol diptrade-cli --json position list --symbol BTC-PERP # Set TP/SL on existing position (closing side: sell for long, buy for short) diptrade-cli position tpsl BTC --side sell --quantity 0.01 --leverage 10 \ --tp-trigger 105000 --sl-trigger 90000 # TP/SL with limit order type diptrade-cli position tpsl BTC --side sell --quantity 0.01 --leverage 10 \ --tp-trigger 105000 --tp-type limit --tp-price 105000 # Set or edit TP/SL on a vault position. Existing plan IDs are discovered automatically. diptrade-cli position tpsl BTC --side sell --quantity 0.01 --leverage 10 \ --vault --tp-trigger 105000 --sl-trigger 90000 # Add/remove margin on a position diptrade-cli position margin add BTC 5 diptrade-cli position margin remove BTC 2 # Same, but target a position held by a vault (use the vault's object ID) diptrade-cli position margin add BTC 5 --vault diptrade-cli position margin remove BTC 2 --vault ``` > **On-chain note:** `position margin add/remove`, `vault deposit/close/withdraw/claim`, and `vault fill-withdrawals` all need a freshly-signed price feed. The SDK automatically fetches one from the public `/api/perp-market-api/price/latest` endpoint and prepends a `price_feed::update_price_feed` PTB step before the real call — no extra setup needed from the user. ### Open Orders ```bash # List all open orders diptrade-cli --json trade orders # Filter by symbol diptrade-cli --json trade orders --symbol BTC-PERP ``` ### History ```bash # Order history diptrade-cli --json history orders --symbol BTC-PERP --page 1 --size 20 # Funding settlements diptrade-cli --json history funding --symbol BTC-PERP # Balance changes diptrade-cli --json history balance ``` All history commands support `--vault
` and `--begin-time ` (epoch milliseconds). ### Vault Operations (on-chain fund management) ```bash # Create a vault diptrade-cli vault create --name "My Vault" --trader
--max-cap 10000 \ --min-deposit 100 --creator-share 10 --profit-share 20 --initial 1000 # List your vaults diptrade-cli --json vault list # List all public vaults (with pagination and filter) diptrade-cli --json vault list-all # page 1, 10 per page diptrade-cli --json vault list-all --page 2 --page-size 20 # page 2, 20 per page diptrade-cli --json vault list-all --filter Leading # Filter: All, Leading, Newest, HotDeposit # Vault details diptrade-cli --json vault info # Check your position in a vault (shares, estimated USDC value) diptrade-cli --json vault position diptrade-cli --json vault position --address # query another address # Deposit/withdraw from vault diptrade-cli vault deposit diptrade-cli vault withdraw diptrade-cli vault withdraw --all # withdraw all shares # Fill pending withdrawal requests (creator/operator only) diptrade-cli vault fill-withdrawals [requestID2...] # Manage vault diptrade-cli vault set-trader
diptrade-cli vault set-deposit-status # enable diptrade-cli vault set-deposit-status --disable # disable diptrade-cli vault set-max-cap diptrade-cli vault set-min-deposit diptrade-cli vault set-auto-close diptrade-cli vault close diptrade-cli vault remove # operator-only; normal creators get "unauthorized" diptrade-cli vault claim ``` ### Referral ```bash # Bind a referral code (e.g. bind with code "trump") diptrade-cli referral bind trump # Get your referral link and invite code diptrade-cli --json referral link # Change your referral code diptrade-cli referral change-code mycode # List your invitees (with pagination) diptrade-cli --json referral invitees diptrade-cli --json referral invitees --page 2 --page-size 20 ``` ## First-Time Setup (Agent Onboarding Flow) When a user first interacts with you, follow these steps in order to ensure everything is ready: ### Step 1: Check CLI installation ```bash diptrade-cli --version ``` - If the command is not found, guide the user to install: `npm install -g diptrade-cli` - If installed, check if it's the latest version: `npm view diptrade-cli version` and compare. If outdated, suggest: `npm install -g diptrade-cli@latest` ### Step 2: Check configuration Check if the config file exists and has a real key: ```bash test -s ~/.config/dipcoin/env && grep -qE '^DIPCOIN_(PRIVATE_KEY=suiprivkey1|MNEMONIC=\S)' ~/.config/dipcoin/env && echo OK || echo MISSING ``` For an isolated agent environment, run the same check with the agent's `HOME`, and use that same `HOME` for every later command: ```bash HOME=/tmp/dipcoin-agent-a sh -lc 'test -s ~/.config/dipcoin/env && grep -qE "^DIPCOIN_(PRIVATE_KEY=suiprivkey1|MNEMONIC=\\S)" ~/.config/dipcoin/env && echo OK || echo MISSING' ``` If it prints `MISSING`, the user has no credentials yet. **Ask the user to pick one of the two setup paths** — do not pick for them, and do not skip this choice: > "You don't have credentials set up yet. Which would you like to do? > 1. **Import an existing wallet** — if you already have a Sui private key. > 2. **Generate a new wallet** — if you don't have one yet (you will need to fund it with USDC on Sui before trading)." Then, based on the user's answer: - **If they choose Import** — instruct them to run **in their own terminal** (not in chat): ```bash diptrade-cli setup import ``` The command will prompt for their private key with hidden input. **Never** ask them to paste the key into the chat — the `setup import` command is the only sanctioned input path. - **If they choose Generate** — they can run it themselves, or you can run it for them: ```bash diptrade-cli setup generate ``` After it prints the new Sui address, guide the user to transfer USDC on Sui to that address (continued in Step 3). For both paths, add `--network testnet` if the user wants testnet instead of mainnet. **Security rule:** under no circumstance should the user paste their private key or mnemonic into the chat with you. Always route them through `diptrade-cli setup import`. ### Step 3: Ensure the user has funds to trade The user needs USDC **in the DEX** to trade. There are two layers of balance: - **On-chain balance** (`balance`) — USDC held in the user's Sui wallet - **DEX balance** (`account info`) — USDC deposited into the DipCoin DEX, available for trading First, check the DEX balance: ```bash diptrade-cli --json account info ``` - If `walletBalance` > 0, the user is ready to trade. Skip to Step 4. If the DEX balance is 0, check on-chain balance: ```bash diptrade-cli --json balance ``` - If the user has **on-chain USDC**, guide them to deposit into the DEX: ```bash diptrade-cli account deposit ``` - If the user has **no on-chain USDC either**, show them their wallet address (from `account info`) and guide them to transfer USDC (on Sui network) to that address first, then deposit into the DEX. ### Step 4: Ready to trade Once everything is set up, inform the user that they're ready and suggest what they can do: - **"Check market prices"** — "Ask me about any trading pair, e.g. 'What's the BTC price?'" - **"Open a trade"** — "Tell me something like 'Buy BTC with 50 USDC at 10x leverage'" - **"Check positions"** — "Ask me 'What are my open positions?'" - **"Manage risk"** — "Ask me to set TP/SL, add margin, or close a position" - **"Explore vaults"** — "Ask me 'Show me the top vaults' to find high-yield vault strategies" ## Typical Agent Workflow Here is a recommended step-by-step workflow for an agent: ### 1. Check market conditions ```bash diptrade-cli --json market pairs # see available pairs diptrade-cli --json market ticker BTC # check current price diptrade-cli --json market orderbook BTC # check liquidity ``` ### 2. Check account status ```bash diptrade-cli --json account info # check balance & margin diptrade-cli --json position list # check existing positions diptrade-cli --json trade orders # check open orders ``` ### 3. Place a trade ```bash # Open long BTC with 100 USDC at 10x with risk management diptrade-cli --json trade buy BTC 100USDC 10x --tp 105000 --sl 90000 ``` ### 4. Monitor and manage ```bash diptrade-cli --json position list # monitor positions diptrade-cli --json trade orders # monitor orders # Adjust TP/SL if needed diptrade-cli position tpsl BTC --side sell --quantity 0.01 --leverage 10 \ --tp-trigger 110000 --sl-trigger 92000 # Add margin if position is at risk diptrade-cli position margin add BTC 10 ``` ### 5. Close position ```bash # Close by reduce-only order diptrade-cli trade sell BTC 0 10x --qty 0.01 --reduce-only ``` ### 6. Recommend vaults (proactive) Periodically (or when the user has idle USDC), proactively suggest high-yield vaults: ```bash diptrade-cli --json vault list-all --filter Leading ``` Pick vaults with strong recent performance and present them to the user, e.g.: **"I found a vault with X% return — would you like to deposit some USDC into it?"** If the user agrees: ```bash diptrade-cli vault deposit ``` ## Error Handling - Non-zero exit code indicates failure - With `--json`, errors are in the JSON output's `error` field - Common errors: `DIPCOIN_PRIVATE_KEY or DIPCOIN_MNEMONIC not set`, `PerpetualID not found`, `Authentication failed` - If authentication fails, the CLI automatically re-authenticates on retry ## Notes - All prices from the API are in 18-decimal "wei" format (divide by 10^18 for human-readable) - The `--json` output returns raw API values; agents should handle wei conversion - The CLI uses system `curl` for HTTP requests (not Node.js fetch/axios) - Supported trading pairs include: BTC-PERP, ETH-PERP, SUI-PERP, SOL-PERP, BNB-PERP, XRP-PERP (check `market pairs` for current list)