dipcoin-cli 0.8.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,35 +1,44 @@
1
- # DipCoin Perpetual Trading SDK & CLI
1
+ # DipCoin Perpetual Trading CLI
2
2
 
3
- TypeScript SDK and CLI for perpetual futures trading on the Sui blockchain.
3
+ TypeScript CLI for perpetual futures trading on the Sui blockchain.
4
4
 
5
- ## Installation
5
+ ## Usage For AI Agent
6
6
 
7
- **CLI (global):**
7
+ Send the following skill link to your AI Agent, and it will guide you through the rest — including installation, configuration, and trading:
8
8
 
9
- ```bash
10
- npm install -g dipcoin-cli
11
9
  ```
10
+ https://raw.githubusercontent.com/dipcoinlab/dipcoin-cli/main/SKILL.md
11
+ ```
12
+
13
+ ## Usage For Human
12
14
 
13
- **SDK (as dependency):**
15
+ ### Installation
14
16
 
15
17
  ```bash
16
- npm install dipcoin-cli
18
+ npm install -g dipcoin-cli
17
19
  ```
18
20
 
19
- ## CLI Quick Start
20
-
21
21
  ### Configuration
22
22
 
23
- Create a `.env` file in your working directory (or at `~/.config/dipcoin/env` for global config):
23
+ Create a config file at `~/.config/dipcoin/env` (recommended) or `.env` in your working directory:
24
24
 
25
25
  ```bash
26
- MNEMONIC=word1 word2 word3 ... word12
27
- NETWORK=testnet # or mainnet
26
+ mkdir -p ~/.config/dipcoin
27
+ cat > ~/.config/dipcoin/env << 'EOF'
28
+ DIPCOIN_PRIVATE_KEY=suiprivkey1...
29
+ DIPCOIN_NETWORK=mainnet
30
+ EOF
28
31
  ```
29
32
 
30
- Index 0 of the HD derivation path is the main account. Use `--vault-index` for sub-accounts.
33
+ | Variable | Required | Description |
34
+ |----------|----------|-------------|
35
+ | `DIPCOIN_PRIVATE_KEY` | One of these | Sui private key (`suiprivkey1...`), supports ED25519/Secp256k1/Secp256r1 |
36
+ | `DIPCOIN_MNEMONIC` | is required | 12-word Sui mnemonic phrase (derives keypair at `m/44'/784'/0'/0'/0'`) |
37
+ | `DIPCOIN_NETWORK` | No | `mainnet` or `testnet` (default: `mainnet`) |
31
38
 
32
- ### Basic Workflow
39
+ If both `DIPCOIN_PRIVATE_KEY` and `DIPCOIN_MNEMONIC` are set, the private key takes precedence.
40
+
41
+ ### Quick Start
33
42
 
34
43
  ```bash
35
44
  # Check available pairs
@@ -54,17 +63,16 @@ dipcoin-cli trade sell BTC 0 10x --qty 0.01 --reduce-only
54
63
  dipcoin-cli history orders --symbol BTC-PERP
55
64
  ```
56
65
 
57
- ## CLI Commands
66
+ ### Commands
58
67
 
59
- ### Global Options
68
+ #### Global Options
60
69
 
61
70
  | Option | Description |
62
71
  |--------|-------------|
63
72
  | `--json` | Output in JSON format (machine-readable) |
64
- | `--vault-index <n>` | Use HD-derived sub-account at index N (placed before subcommand) |
65
73
  | `-V, --version` | Show version |
66
74
 
67
- ### market
75
+ #### market
68
76
 
69
77
  ```bash
70
78
  dipcoin-cli market pairs # List all trading pairs
@@ -75,7 +83,7 @@ dipcoin-cli market oracle <symbol> # Oracle price
75
83
 
76
84
  Symbols auto-normalize: `BTC` becomes `BTC-PERP`.
77
85
 
78
- ### account
86
+ #### account
79
87
 
80
88
  ```bash
81
89
  dipcoin-cli account info # Balance, margin, PnL
@@ -84,13 +92,13 @@ dipcoin-cli account deposit <amount> # Deposit USDC to exchange
84
92
  dipcoin-cli account withdraw <amount> # Withdraw USDC from exchange
85
93
  ```
86
94
 
87
- ### balance
95
+ #### balance
88
96
 
89
97
  ```bash
90
98
  dipcoin-cli balance # On-chain coin balances
91
99
  ```
92
100
 
93
- ### trade
101
+ #### trade
94
102
 
95
103
  ```bash
96
104
  # Buy/Sell with USDC margin amount (auto-converts to quantity)
@@ -104,11 +112,15 @@ dipcoin-cli trade buy BTC 100USDC 10x --price 95000
104
112
  dipcoin-cli trade buy BTC 100USDC 10x --tp 105000 --sl 90000
105
113
 
106
114
  # Explicit quantity instead of USDC margin
107
- dipcoin-cli trade buy BTC 100USDC 10x --qty 0.01
115
+ dipcoin-cli trade buy BTC 0 10x --qty 0.01
108
116
 
109
117
  # Reduce-only (for closing)
110
118
  dipcoin-cli trade sell BTC 0 10x --qty 0.01 --reduce-only
111
119
 
120
+ # List open orders
121
+ dipcoin-cli trade orders
122
+ dipcoin-cli trade orders --symbol BTC-PERP
123
+
112
124
  # Cancel orders
113
125
  dipcoin-cli trade cancel <symbol> <hash1> [hash2...]
114
126
  ```
@@ -122,9 +134,9 @@ dipcoin-cli trade cancel <symbol> <hash1> [hash2...]
122
134
  | `--reduce-only` | Reduce-only order |
123
135
  | `--tp <price>` | Take profit trigger price |
124
136
  | `--sl <price>` | Stop loss trigger price |
125
- | `--vault <address>` | Vault/creator address (fallback) |
137
+ | `--vault <address>` | Vault/creator address (for trading vault positions) |
126
138
 
127
- ### position
139
+ #### position
128
140
 
129
141
  ```bash
130
142
  dipcoin-cli position list # List open positions
@@ -145,15 +157,7 @@ dipcoin-cli position margin remove <symbol> <amount>
145
157
 
146
158
  The `--side` is the **closing side**: use `sell` for long positions, `buy` for short.
147
159
 
148
- ### orders
149
-
150
- ```bash
151
- dipcoin-cli orders # List all open orders
152
- dipcoin-cli orders --symbol BTC-PERP # Filter by symbol
153
- dipcoin-cli orders --vault <address> # Filter by vault
154
- ```
155
-
156
- ### vault
160
+ #### vault
157
161
 
158
162
  On-chain vault operations (DipCoin vault contracts):
159
163
 
@@ -162,9 +166,15 @@ dipcoin-cli vault create --name <name> --trader <address> --max-cap <usdc> \
162
166
  --min-deposit <usdc> --creator-share <pct> --profit-share <pct> --initial <usdc>
163
167
 
164
168
  dipcoin-cli vault list # List vaults created by wallet
169
+ dipcoin-cli vault list-all # List all public vaults (page 1, 10 per page)
170
+ dipcoin-cli vault list-all --page 2 --page-size 20
171
+ dipcoin-cli vault list-all --filter Leading # Filter: All, Leading, Newest, HotDeposit
165
172
  dipcoin-cli vault info <vaultId> # Vault details
173
+ dipcoin-cli vault position <vaultId> # Your shares & estimated value
174
+ dipcoin-cli vault position <vaultId> --address <addr> # Query another address
166
175
  dipcoin-cli vault deposit <vaultId> <amount>
167
176
  dipcoin-cli vault withdraw <vaultId> <shares>
177
+ dipcoin-cli vault withdraw <vaultId> --all # Withdraw all shares
168
178
  dipcoin-cli vault fill <vaultId> <requestIDs...> [--markets <ids>]
169
179
  dipcoin-cli vault close <vaultId> [--markets <ids>]
170
180
  dipcoin-cli vault remove <vaultId>
@@ -177,17 +187,17 @@ dipcoin-cli vault set-min-deposit <vaultId> <amount>
177
187
  dipcoin-cli vault set-auto-close <vaultId> [--disable]
178
188
  ```
179
189
 
180
- ### sub-account
181
-
182
- HD-derived sub-account management:
190
+ #### referral
183
191
 
184
192
  ```bash
185
- dipcoin-cli sub-account list [--count <n>] # List derived addresses (default 5)
186
- dipcoin-cli sub-account setup <index> # Derive and register sub-account on-chain
187
- dipcoin-cli sub-account set <subAddress> # Authorize a sub-account address
193
+ dipcoin-cli referral bind <code> # Bind a referral code
194
+ dipcoin-cli referral link # Get your referral link and invite code
195
+ dipcoin-cli referral change-code <code> # Change your referral code
196
+ dipcoin-cli referral invitees # List your invitees
197
+ dipcoin-cli referral invitees --page 2 --page-size 20
188
198
  ```
189
199
 
190
- ### history
200
+ #### history
191
201
 
192
202
  ```bash
193
203
  dipcoin-cli history orders [--symbol <s>] [--page <n>] [--size <n>]
@@ -197,210 +207,12 @@ dipcoin-cli history balance [--page <n>] [--size <n>]
197
207
 
198
208
  All history commands support `--vault <address>` and `--begin-time <ms>`.
199
209
 
200
- ## Multi-Vault Workflow
201
-
202
- The CLI uses HD key derivation from your mnemonic. Index 0 is the main account, index 1+ are sub-accounts.
203
-
204
- ```bash
205
- # List derived addresses
206
- dipcoin-cli sub-account list
207
-
208
- # Register sub-account 1 on-chain
209
- dipcoin-cli sub-account setup 1
210
-
211
- # Deposit to sub-account 1
212
- dipcoin-cli --vault-index 1 account deposit 100
213
-
214
- # Trade on sub-account 1
215
- dipcoin-cli --vault-index 1 trade buy BTC 50USDC 10x
216
-
217
- # Check sub-account 1 positions
218
- dipcoin-cli --vault-index 1 position list
219
- ```
220
-
221
- `--vault-index` is always a **global option** placed before the subcommand.
222
-
223
- ## SDK Usage
224
-
225
- ### Initialize
226
-
227
- ```typescript
228
- import { initDipCoinPerpSDK } from "dipcoin-cli";
229
- import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
230
-
231
- const keypair = Ed25519Keypair.deriveKeypair("your mnemonic phrase ...");
232
- const sdk = initDipCoinPerpSDK(keypair, { network: "mainnet" });
233
-
234
- // With sub-account for vault trading
235
- const subKeypair = Ed25519Keypair.deriveKeypair("your mnemonic", "m/44'/784'/1'/0'/0'");
236
- const vaultSdk = initDipCoinPerpSDK(keypair, { network: "mainnet", subAccountKey: subKeypair });
237
- ```
238
-
239
- ### Authentication
240
-
241
- ```typescript
242
- const authResult = await sdk.authenticate();
243
- if (authResult.status) {
244
- console.log("Authenticated:", authResult.data);
245
- }
246
-
247
- // All API methods auto-authenticate when needed
248
- ```
249
-
250
- ### Account Info
251
-
252
- ```typescript
253
- const info = await sdk.getAccountInfo();
254
- if (info.status && info.data) {
255
- console.log("Balance:", info.data.walletBalance);
256
- console.log("Free Collateral:", info.data.freeCollateral);
257
- }
258
- ```
259
-
260
- ### Deposit & Withdraw
261
-
262
- ```typescript
263
- // On-chain transactions (USDC to/from exchange)
264
- await sdk.depositToBank(100); // 100 USDC
265
- await sdk.withdrawFromBank(50); // 50 USDC
266
- ```
267
-
268
- ### Place Order
269
-
270
- ```typescript
271
- import { OrderSide, OrderType } from "dipcoin-cli";
272
-
273
- // Market order
274
- const result = await sdk.placeOrder({
275
- symbol: "BTC-PERP",
276
- side: OrderSide.BUY,
277
- orderType: OrderType.MARKET,
278
- quantity: "0.1",
279
- leverage: "10",
280
- });
281
-
282
- // Limit order
283
- const limit = await sdk.placeOrder({
284
- symbol: "BTC-PERP",
285
- side: OrderSide.BUY,
286
- orderType: OrderType.LIMIT,
287
- quantity: "0.1",
288
- price: "95000",
289
- leverage: "10",
290
- });
291
-
292
- // With TP/SL
293
- const withTpSl = await sdk.placeOrder({
294
- symbol: "BTC-PERP",
295
- side: OrderSide.BUY,
296
- orderType: OrderType.MARKET,
297
- quantity: "0.1",
298
- leverage: "10",
299
- tpTriggerPrice: "105000",
300
- slTriggerPrice: "90000",
301
- });
302
- ```
303
-
304
- ### Position TP/SL
305
-
306
- ```typescript
307
- await sdk.placePositionTpSlOrders({
308
- symbol: "BTC-PERP",
309
- market: "<perpetual-id>",
310
- side: OrderSide.SELL,
311
- isLong: true,
312
- leverage: "10",
313
- quantity: "0.1",
314
- tp: { triggerPrice: "105000", orderType: OrderType.MARKET, tpslType: "position" },
315
- sl: { triggerPrice: "90000", orderType: OrderType.MARKET, tpslType: "position" },
316
- });
317
- ```
318
-
319
- ### Market Data
320
-
321
- ```typescript
322
- const ticker = await sdk.getTicker("BTC-PERP");
323
- const orderBook = await sdk.getOrderBook("BTC-PERP");
324
- const oraclePrice = await sdk.getOraclePrice("BTC-PERP");
325
- const pairs = await sdk.getTradingPairs();
326
- ```
327
-
328
- ### Cancel Order
329
-
330
- ```typescript
331
- await sdk.cancelOrder({
332
- symbol: "BTC-PERP",
333
- orderHashes: ["0x1234..."],
334
- });
335
- ```
336
-
337
- ### Positions & Open Orders
338
-
339
- ```typescript
340
- const positions = await sdk.getPositions();
341
- const orders = await sdk.getOpenOrders();
342
- ```
343
-
344
- ### Leverage & Margin
345
-
346
- ```typescript
347
- await sdk.adjustLeverage({ symbol: "BTC-PERP", leverage: "10", marginType: "ISOLATED" });
348
- await sdk.addMargin({ symbol: "BTC-PERP", amount: 5 });
349
- await sdk.removeMargin({ symbol: "BTC-PERP", amount: 2 });
350
- ```
351
-
352
- ## Types
353
-
354
- ```typescript
355
- enum OrderSide { BUY = "BUY", SELL = "SELL" }
356
- enum OrderType { MARKET = "MARKET", LIMIT = "LIMIT" }
357
-
358
- interface AccountInfo {
359
- walletBalance: string;
360
- totalUnrealizedProfit: string;
361
- accountValue: string;
362
- freeCollateral: string;
363
- totalMargin: string;
364
- }
365
-
366
- interface Position {
367
- symbol: string; side: string; quantity: string;
368
- avgEntryPrice: string; leverage: string; margin: string;
369
- unrealizedProfit: string; liquidationPrice: string;
370
- }
371
-
372
- interface OpenOrder {
373
- hash: string; symbol: string; side: string;
374
- orderType: string; price: string; quantity: string;
375
- filledQty: string; leverage: string; status: string;
376
- }
377
-
378
- interface SDKResponse<T> {
379
- status: boolean;
380
- data?: T;
381
- error?: string;
382
- }
383
- ```
384
-
385
- ## Error Handling
386
-
387
- All SDK methods return `SDKResponse<T>`. Check `status` before accessing `data`:
388
-
389
- ```typescript
390
- const result = await sdk.placeOrder(/* ... */);
391
- if (result.status) {
392
- console.log(result.data);
393
- } else {
394
- console.error(result.error);
395
- }
396
- ```
397
-
398
210
  ## Development
399
211
 
400
212
  ```bash
401
213
  npm run cli # Run CLI in dev mode (tsx)
402
214
  npm run build # Build for distribution
403
- npm run example # Run example script
215
+ npm run lint # Run ESLint
404
216
  ```
405
217
 
406
218
  ## License