DeepBook CLI Skill
Use this skill when the user wants to use deepbook end to end: market data, wallet/config setup, and on-chain execution (spot, swap, manager, margin).
Installation
Check if deepbook is installed:
deepbook --version
If not, install it:
npm install -g deepbook-cli
Setup
- Work from the
deepbook-cli project directory.
- Ensure
~/.deepbook/config.json exists (auto-created on first run).
- Configure global defaults in
~/.deepbook (works from any path).
- Optional one-off overrides can still be provided via global flags.
mainnet/testnet are aliases used consistently for both provider-side reads/streams and on-chain RPC.
Global flags
--json
--provider <name>
--base-url <url>
--stream-base-url <url>
--network <mainnet|testnet>
--rpc-url <url>
--private-key <suiprivkey>
--address <address>
--manager <id>
--trade-cap <id>
Available commands
Top-level:
deepbook providers
deepbook pools
deepbook orderbook <pool> (alias: deepbook book <pool>)
deepbook trades <pool>
deepbook ohlcv <pool>
deepbook stream ...
deepbook spot ...
deepbook swap ...
deepbook margin ...
deepbook manager ...
deepbook config ...
deepbook account ...
deepbook config:
show
set-network <network>
set-provider <provider>
set-rpc-url <network> <url>
set-address <address>
set-trade-cap <id>
set-read-key [apiKey]
set-stream-key <pool> [apiKey]
set-provider-base-url <network> <url>
set-provider-stream-base-url <network> <url>
import-key [privateKey]
deepbook account:
details
list
balance
import <alias> [privateKey]
use <alias>
deepbook stream:
deepbook spot:
pools
buy <pool>
sell <pool>
limit <pool>
deepbook swap:
base-for-quote <pool>
quote-for-base <pool>
deepbook margin:
pools
managers
deposit <pool>
market <pool>
limit <pool>
position <pool>
close <pool>
deepbook manager:
ls
create
deposit
withdraw
balance
Command cheat sheet (required args/options)
deepbook providers
deepbook pools
deepbook orderbook <pool>
deepbook trades <pool>
deepbook ohlcv <pool>
deepbook stream trades <pool>
deepbook spot pools
deepbook spot buy <pool> --quantity <value> [--price <value>] [--manager <id>]
deepbook spot sell <pool> --quantity <value> [--price <value>] [--manager <id>]
deepbook spot limit <pool> --side <buy|sell> --price <value> --quantity <value> [--manager <id>]
deepbook spot limit <pool> --cancel <id> [--manager <id>]
deepbook config show
deepbook config set-network <mainnet|testnet>
deepbook config set-provider <surflux>
deepbook config set-rpc-url <mainnet|testnet> <url>
deepbook config set-address <address>
deepbook config set-trade-cap <objectId>
deepbook config set-read-key [apiKey] (or --stdin)
deepbook config set-stream-key <pool> [apiKey] (or --stdin)
deepbook config set-provider-base-url <mainnet|testnet> <url>
deepbook config set-provider-stream-base-url <mainnet|testnet> <url>
deepbook config import-key [privateKey] (or --stdin, optional --alias)
deepbook account details
deepbook account list
deepbook account balance [--coin <SUI|USDC|DEEP|coinType>]
deepbook account import <alias> [privateKey] (or --stdin)
deepbook account use <alias>
deepbook swap base-for-quote <pool> --amount <value>
deepbook swap quote-for-base <pool> --amount <value>
deepbook margin pools
deepbook margin managers
deepbook margin deposit <pool> --coin <BASE|QUOTE|DEEP|coinKey> --amount <value> [--margin-manager <id>]
deepbook margin market <pool> --side <buy|sell> --quantity <value> [--margin-manager <id>]
deepbook margin limit <pool> --side <buy|sell> --price <value> --quantity <value> [--margin-manager <id>]
deepbook margin position <pool> [--margin-manager <id>]
deepbook margin close <pool> [--margin-manager <id>] + either:
--full
- OR
--side <buy|sell> --quantity <value>
deepbook manager ls
deepbook manager create
deepbook manager deposit --coin <key> --amount <value> [--manager <id>]
deepbook manager withdraw --coin <key> --amount <value> [--manager <id>]
deepbook manager balance --coin <key> [--manager <id>]
Key margin close flags
deepbook margin close <pool> --full --withdraw
deepbook margin close <pool> --full --non-reduce-only
deepbook margin close <pool> --side <buy|sell> --quantity <q> --reduce-only --no-repay
Swap vs spot market buy
- Swap (
deepbook swap quote-for-base) is a direct pool swap with exact-input semantics.
- Spot market buy (
deepbook spot buy <pool> --quantity ...) is an orderbook market order and uses a balance manager.
- CLI output now includes
execution.kind and execution.type/direction so the mode is explicit.
Safety defaults
- Prefer
--dry-run first for all state-changing commands.
- Validate pool key and manager object ID before placing/canceling orders.
- SUI-involved deposit/collateral paths split from gas coin inside the transaction automatically.
- Never print or log private keys.
- Margin manager type safety:
- Margin managers are generic typed objects:
MarginManager<Base, Quote>.
- The margin manager type must match the exact pool pair being traded.
- Example:
MarginManager<DEEP,USDC> works with DEEP_USDC, not DEEP_SUI.
- Margin manager resolution behavior:
- If
--margin-manager is omitted, CLI auto-selects a compatible manager for that pool, or creates one in-transaction if none exists.
- If
--margin-manager is provided, CLI treats it as explicit and strict: it must match signer + pool; no fallback or auto-create is performed.
- Internal margin fee buffer behavior:
- Margin market/limit orders auto-deposit a fee buffer before placing the order.
- With
--no-pay-with-deep, buffer is deposited in trade asset collateral (base for sell, quote for buy).
- Without
--no-pay-with-deep, buffer is deposited as DEEP into the margin manager.
- Full-close quantity normalization:
deepbook margin close <pool> --full now auto-normalizes inferred quantity to pool lot-size/min-size.
- If reduce-only full close cannot satisfy lot-size exactly, CLI auto-switches to non-reduce-only and rounds up, then repays debt in the same transaction.
- If user explicitly passes
--reduce-only, CLI keeps reduce-only semantics and errors when full close cannot be represented as a valid lot-size quantity.
End-to-end spot trading flow (fund -> buy -> withdraw)
Use this when executing a real spot trade through a balance manager.
- Discover balance managers:
- If none exist, create one:
- Deposit quote coin to manager (for
DEEP_SUI buy, fund SUI):
deepbook manager deposit --coin SUI --amount 1 --manager <id>
- Optional balance check:
deepbook manager balance --coin SUI --manager <id>
- Simulate buy first:
deepbook spot buy DEEP_SUI --quantity 38 --manager <id> --no-pay-with-deep --dry-run
- Execute live buy:
deepbook spot buy DEEP_SUI --quantity 38 --manager <id> --no-pay-with-deep
- Withdraw purchased asset to signer address (or explicit recipient):
deepbook manager withdraw --coin DEEP --amount 38 --manager <id>
- optional recipient:
--recipient <address>
- Verify manager balance:
deepbook manager balance --coin DEEP --manager <id>
Spot trade troubleshooting
MoveAbort ... balance_manager::withdraw_with_proof code=3 means manager available balance is too low.
- This includes fees/reserved amounts, not just raw deposited balance.
- For spot buys, ensure quote coin is funded in manager (for
DEEP_SUI, quote is SUI).
- If fees are attempted in DEEP and manager lacks DEEP, either deposit DEEP or pass
--no-pay-with-deep.
- When manager is omitted, CLI resolves dynamically:
- one manager found -> uses it
- none found -> error
- multiple found -> require
--manager <id>
Typical workflow
- Inspect pools/orderbook (
deepbook spot pools, deepbook margin pools, deepbook orderbook ...).
- Confirm manager ID (
deepbook manager ls).
- Simulate order (
deepbook spot buy ... --dry-run).
- Execute live order (same command without
--dry-run).
- Monitor with
deepbook orderbook --watch and deepbook stream trades ....
1---2name: deepbook-cli3description: Operate the deepbook CLI for DeepBook reads (REST/SSE), global ~/.deepbook config/account management, on-chain spot trading, top-level swap execution, balance-manager ops, and margin trading.4---5
6# DeepBook CLI Skill
7
8Use this skill when the user wants to use `deepbook` end to end: market data, wallet/config setup, and on-chain execution (spot, swap, manager, margin).
9
10# Installation
11
12Check if `deepbook` is installed:
13
14```bash
15deepbook --version
16```
17
18If not, install it:
19
20```bash
21npm install -g deepbook-cli
22```
23
24## Setup
25
261. Work from the `deepbook-cli` project directory.
272. Ensure `~/.deepbook/config.json` exists (auto-created on first run).
283. Configure global defaults in `~/.deepbook` (works from any path).
294. Optional one-off overrides can still be provided via global flags.
30
31`mainnet`/`testnet` are aliases used consistently for both provider-side reads/streams and on-chain RPC.
32
33## Global flags
34
35- `--json`
36- `--provider <name>`
37- `--base-url <url>`
38- `--stream-base-url <url>`
39- `--network <mainnet|testnet>`
40- `--rpc-url <url>`
41- `--private-key <suiprivkey>`
42- `--address <address>`
43- `--manager <id>`
44- `--trade-cap <id>`
45
46## Available commands
47
48- Top-level:
49 - `deepbook providers`
50 - `deepbook pools`
51 - `deepbook orderbook <pool>` (alias: `deepbook book <pool>`)
52 - `deepbook trades <pool>`
53 - `deepbook ohlcv <pool>`
54 - `deepbook stream ...`
55 - `deepbook spot ...`
56 - `deepbook swap ...`
57 - `deepbook margin ...`
58 - `deepbook manager ...`
59 - `deepbook config ...`
60 - `deepbook account ...`
61
62- `deepbook config`:
63 - `show`
64 - `set-network <network>`
65 - `set-provider <provider>`
66 - `set-rpc-url <network> <url>`
67 - `set-address <address>`
68 - `set-trade-cap <id>`
69 - `set-read-key [apiKey]`
70 - `set-stream-key <pool> [apiKey]`
71 - `set-provider-base-url <network> <url>`
72 - `set-provider-stream-base-url <network> <url>`
73 - `import-key [privateKey]`
74
75- `deepbook account`:
76 - `details`
77 - `list`
78 - `balance`
79 - `import <alias> [privateKey]`
80 - `use <alias>`
81
82- `deepbook stream`:
83 - `trades <pool>`
84
85- `deepbook spot`:
86 - `pools`
87 - `buy <pool>`
88 - `sell <pool>`
89 - `limit <pool>`
90
91- `deepbook swap`:
92 - `base-for-quote <pool>`
93 - `quote-for-base <pool>`
94
95- `deepbook margin`:
96 - `pools`
97 - `managers`
98 - `deposit <pool>`
99 - `market <pool>`
100 - `limit <pool>`
101 - `position <pool>`
102 - `close <pool>`
103
104- `deepbook manager`:
105 - `ls`
106 - `create`
107 - `deposit`
108 - `withdraw`
109 - `balance`
110
111## Command cheat sheet (required args/options)
112
113- `deepbook providers`
114- `deepbook pools`
115- `deepbook orderbook <pool>`
116- `deepbook trades <pool>`
117- `deepbook ohlcv <pool>`
118- `deepbook stream trades <pool>`
119- `deepbook spot pools`
120- `deepbook spot buy <pool> --quantity <value> [--price <value>] [--manager <id>]`
121- `deepbook spot sell <pool> --quantity <value> [--price <value>] [--manager <id>]`
122- `deepbook spot limit <pool> --side <buy|sell> --price <value> --quantity <value> [--manager <id>]`
123- `deepbook spot limit <pool> --cancel <id> [--manager <id>]`
124
125- `deepbook config show`
126- `deepbook config set-network <mainnet|testnet>`
127- `deepbook config set-provider <surflux>`
128- `deepbook config set-rpc-url <mainnet|testnet> <url>`
129- `deepbook config set-address <address>`
130- `deepbook config set-trade-cap <objectId>`
131- `deepbook config set-read-key [apiKey]` (or `--stdin`)
132- `deepbook config set-stream-key <pool> [apiKey]` (or `--stdin`)
133- `deepbook config set-provider-base-url <mainnet|testnet> <url>`
134- `deepbook config set-provider-stream-base-url <mainnet|testnet> <url>`
135- `deepbook config import-key [privateKey]` (or `--stdin`, optional `--alias`)
136
137- `deepbook account details`
138- `deepbook account list`
139- `deepbook account balance [--coin <SUI|USDC|DEEP|coinType>]`
140- `deepbook account import <alias> [privateKey]` (or `--stdin`)
141- `deepbook account use <alias>`
142
143
144- `deepbook swap base-for-quote <pool> --amount <value>`
145- `deepbook swap quote-for-base <pool> --amount <value>`
146
147- `deepbook margin pools`
148- `deepbook margin managers`
149- `deepbook margin deposit <pool> --coin <BASE|QUOTE|DEEP|coinKey> --amount <value> [--margin-manager <id>]`
150- `deepbook margin market <pool> --side <buy|sell> --quantity <value> [--margin-manager <id>]`
151- `deepbook margin limit <pool> --side <buy|sell> --price <value> --quantity <value> [--margin-manager <id>]`
152- `deepbook margin position <pool> [--margin-manager <id>]`
153- `deepbook margin close <pool> [--margin-manager <id>]` + either:
154 - `--full`
155 - OR `--side <buy|sell> --quantity <value>`
156
157- `deepbook manager ls`
158- `deepbook manager create`
159- `deepbook manager deposit --coin <key> --amount <value> [--manager <id>]`
160- `deepbook manager withdraw --coin <key> --amount <value> [--manager <id>]`
161- `deepbook manager balance --coin <key> [--manager <id>]`
162
163## Key margin close flags
164
165- `deepbook margin close <pool> --full --withdraw`
166- `deepbook margin close <pool> --full --non-reduce-only`
167- `deepbook margin close <pool> --side <buy|sell> --quantity <q> --reduce-only --no-repay`
168
169## Swap vs spot market buy
170
171- Swap (`deepbook swap quote-for-base`) is a direct pool swap with exact-input semantics.
172- Spot market buy (`deepbook spot buy <pool> --quantity ...`) is an orderbook market order and uses a balance manager.
173- CLI output now includes `execution.kind` and `execution.type/direction` so the mode is explicit.
174
175## Safety defaults
176
177- Prefer `--dry-run` first for all state-changing commands.
178- Validate pool key and manager object ID before placing/canceling orders.
179- SUI-involved deposit/collateral paths split from gas coin inside the transaction automatically.
180- Never print or log private keys.
181- Margin manager type safety:
182 - Margin managers are generic typed objects: `MarginManager<Base, Quote>`.
183 - The margin manager type must match the exact pool pair being traded.
184 - Example: `MarginManager<DEEP,USDC>` works with `DEEP_USDC`, not `DEEP_SUI`.
185- Margin manager resolution behavior:
186 - If `--margin-manager` is omitted, CLI auto-selects a compatible manager for that pool, or creates one in-transaction if none exists.
187 - If `--margin-manager` is provided, CLI treats it as explicit and strict: it must match signer + pool; no fallback or auto-create is performed.
188- Internal margin fee buffer behavior:
189 - Margin market/limit orders auto-deposit a fee buffer before placing the order.
190 - With `--no-pay-with-deep`, buffer is deposited in trade asset collateral (base for sell, quote for buy).
191 - Without `--no-pay-with-deep`, buffer is deposited as DEEP into the margin manager.
192- Full-close quantity normalization:
193 - `deepbook margin close <pool> --full` now auto-normalizes inferred quantity to pool lot-size/min-size.
194 - If reduce-only full close cannot satisfy lot-size exactly, CLI auto-switches to non-reduce-only and rounds up, then repays debt in the same transaction.
195 - If user explicitly passes `--reduce-only`, CLI keeps reduce-only semantics and errors when full close cannot be represented as a valid lot-size quantity.
196
197## End-to-end spot trading flow (fund -> buy -> withdraw)
198
199Use this when executing a real spot trade through a balance manager.
200
2011. Discover balance managers:
202 - `deepbook manager ls`
2032. If none exist, create one:
204 - `deepbook manager create`
2053. Deposit quote coin to manager (for `DEEP_SUI` buy, fund `SUI`):
206 - `deepbook manager deposit --coin SUI --amount 1 --manager <id>`
2074. Optional balance check:
208 - `deepbook manager balance --coin SUI --manager <id>`
2095. Simulate buy first:
210 - `deepbook spot buy DEEP_SUI --quantity 38 --manager <id> --no-pay-with-deep --dry-run`
2116. Execute live buy:
212 - `deepbook spot buy DEEP_SUI --quantity 38 --manager <id> --no-pay-with-deep`
2137. Withdraw purchased asset to signer address (or explicit recipient):
214 - `deepbook manager withdraw --coin DEEP --amount 38 --manager <id>`
215 - optional recipient: `--recipient <address>`
2168. Verify manager balance:
217 - `deepbook manager balance --coin DEEP --manager <id>`
218
219## Spot trade troubleshooting
220
221- `MoveAbort ... balance_manager::withdraw_with_proof code=3` means manager available balance is too low.
222- This includes fees/reserved amounts, not just raw deposited balance.
223- For spot buys, ensure quote coin is funded in manager (for `DEEP_SUI`, quote is `SUI`).
224- If fees are attempted in DEEP and manager lacks DEEP, either deposit DEEP or pass `--no-pay-with-deep`.
225- When manager is omitted, CLI resolves dynamically:
226 - one manager found -> uses it
227 - none found -> error
228 - multiple found -> require `--manager <id>`
229
230
231## Typical workflow
232
2331. Inspect pools/orderbook (`deepbook spot pools`, `deepbook margin pools`, `deepbook orderbook ...`).
2342. Confirm manager ID (`deepbook manager ls`).
2353. Simulate order (`deepbook spot buy ... --dry-run`).
2364. Execute live order (same command without `--dry-run`).
2375. Monitor with `deepbook orderbook --watch` and `deepbook stream trades ...`.