Skip to content

Commit e8b2fa4

Browse files
committed
feat: add convert and spot margin workflows
1 parent 02827b4 commit e8b2fa4

16 files changed

Lines changed: 1310 additions & 5 deletions

File tree

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ All output includes `"mode": "paper"` in JSON. Limit buys reserve quote balance
359359

360360
## Commands
361361

362-
The CLI exposes 16 top-level command groups. For the machine-readable agent/MCP tool surface, load [agents/tool-catalog.json](agents/tool-catalog.json).
362+
The CLI exposes 18 top-level command groups. For the machine-readable agent/MCP tool surface, load [agents/tool-catalog.json](agents/tool-catalog.json).
363363

364364
| Group | Auth | Dangerous | Description |
365365
|-------|------|-----------|-------------|
@@ -368,6 +368,8 @@ The CLI exposes 16 top-level command groups. For the machine-readable agent/MCP
368368
| account | Yes | No | Balances, info, fee rates, transaction log |
369369
| position | Yes | Yes | List, leverage, TP/SL, margin, closed P&L |
370370
| asset | Yes | Yes | Balances, transfers, deposits, withdrawals |
371+
| convert | Yes | Mixed | Coin conversion quote, execute, status, and history |
372+
| margin | Mixed | Mixed | Spot margin status, VIP data, mode toggle, and leverage |
371373
| funding | Yes | Yes | Wallet balances, deposits, withdrawals, and transfers |
372374
| subaccount | Yes | Yes | Master-account subaccount management |
373375
| earn | Mixed | Mixed | Bybit Earn products, positions, stake/redeem, and yield history |
@@ -412,6 +414,7 @@ The CLI exposes 16 top-level command groups. For the machine-readable agent/MCP
412414
| `bybit trade cancel --symbol SYM --order-id ID` | Cancel order |
413415
| `bybit trade cancel-all [--symbol SYM]` | Cancel all orders |
414416
| `bybit trade cancel-after <SECS>` | Dead man's switch (0 = disable) |
417+
| `bybit trade dcp-info` | Show current DCP (Disconnect Cancel All) configuration |
415418
| `bybit trade open-orders [--symbol SYM]` | Open orders |
416419
| `bybit trade history [--symbol SYM] [--limit N]` | Order history |
417420
| `bybit trade fills [--symbol SYM] [--limit N]` | Execution history |
@@ -435,6 +438,35 @@ The CLI exposes 16 top-level command groups. For the machine-readable agent/MCP
435438
| `bybit account set-margin-mode --margin-mode REGULAR_MARGIN` | Set margin mode |
436439
| `bybit account set-spot-hedging --mode ON` | Set spot hedging |
437440
| `bybit account set-usdc-settlement --coin USDC` | Set UTA settlement coin for USDC products |
441+
| `bybit account borrow --coin USDT --amount AMT` | Manually borrow funds |
442+
| `bybit account repay --coin USDT --amount AMT` | Manually repay borrowed funds |
443+
| `bybit account quick-repay [--coin USDT]` | Auto-select and repay liabilities |
444+
445+
### Convert
446+
447+
| Command | Description |
448+
|---------|-------------|
449+
| `bybit convert coins [--account-type UNIFIED] [--coin BTC] [--side 1]` | List coins and supported conversion directions |
450+
| `bybit convert quote --from-coin BTC --to-coin USDT (--from-amount AMT \| --to-amount AMT)` | Request a conversion quote |
451+
| `bybit convert quote ... --dry-run` | Preview the quote request without calling the API |
452+
| `bybit convert execute --quote-tx-id ID` | Execute a previously obtained quote |
453+
| `bybit convert status --quote-tx-id ID [--account-type UNIFIED]` | Check conversion status |
454+
| `bybit convert history [--account-type UNIFIED] [--coin BTC] [--start MS] [--end MS] [--index N] [--limit N]` | Conversion history |
455+
456+
Notes:
457+
The Convert API requires the Bybit API key permission `Exchange`. If that permission is missing, Bybit may reject coin-list and quote requests even though the CLI command itself is correct.
458+
459+
### Spot Margin
460+
461+
| Command | Description |
462+
|---------|-------------|
463+
| `bybit margin vip-data [--vip-level "No VIP"] [--currency BTC]` | Public VIP borrow/leverage data for spot margin |
464+
| `bybit margin status` | Current spot margin state and leverage for the unified account |
465+
| `bybit margin toggle --mode on\|off` | Enable or disable unified account spot margin |
466+
| `bybit margin set-leverage --leverage N [--currency BTC]` | Set spot margin leverage globally or for a coin |
467+
468+
Notes:
469+
Spot margin activation and leverage changes can be rejected by Bybit until the account completes the required margin-trading setup or quiz in the Bybit UI.
438470

439471
### Earn
440472

@@ -458,7 +490,7 @@ The CLI exposes 16 top-level command groups. For the machine-readable agent/MCP
458490
| `bybit position set-tpsl --symbol SYM [--take-profit P] [--stop-loss P]` | Set TP/SL |
459491
| `bybit position set-risk-limit --symbol SYM --risk-id N` | Set risk limit |
460492
| `bybit position add-margin --symbol SYM --margin AMT` | Add/reduce margin |
461-
| `bybit position closed-pnl [--symbol SYM] [--limit N]` | Closed P&L history |
493+
| `bybit position closed-pnl [--category linear] [--symbol SYM] [--limit N]` | Closed P&L history for supported contract categories |
462494
| `bybit position move --from-uid UID --to-uid UID --positions '[...]'` | Move positions |
463495
| `bybit position move-history` | Move position history |
464496

@@ -542,7 +574,7 @@ The CLI exposes 16 top-level command groups. For the machine-readable agent/MCP
542574
| `bybit reports borrow-history [--currency USDT]` | Borrow history |
543575
| `bybit reports orders [--category linear] [--symbol SYM]` | Order history |
544576
| `bybit reports fills [--category linear] [--symbol SYM]` | Execution history |
545-
| `bybit reports closed-pnl [--category linear] [--symbol SYM]` | Closed P&L history |
577+
| `bybit reports closed-pnl [--category linear] [--symbol SYM]` | Closed P&L history for supported contract categories |
546578
| `bybit reports moves [--category linear] [--symbol SYM]` | Position move history |
547579
| `bybit reports deposits [--coin BTC]` | Deposit history |
548580
| `bybit reports withdrawals [--coin USDT]` | Withdrawal history |

agents/tool-catalog.json

Lines changed: 154 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/account.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ pub enum AccountCommand {
126126
#[arg(long)]
127127
symbol: Option<String>,
128128
},
129+
/// Manually borrow funds (UTA Pro / Portfolio Margin)
130+
Borrow {
131+
/// Coin to borrow, e.g. USDT
132+
#[arg(long)]
133+
coin: String,
134+
/// Amount to borrow
135+
#[arg(long)]
136+
amount: String,
137+
},
138+
/// Manually repay borrowed funds
139+
Repay {
140+
/// Coin to repay, e.g. USDT
141+
#[arg(long)]
142+
coin: String,
143+
/// Amount to repay
144+
#[arg(long)]
145+
amount: String,
146+
},
147+
/// Quick-repay liability (auto-select coin and amount)
148+
QuickRepay {
149+
/// Coin to repay; omit to auto-select
150+
#[arg(long)]
151+
coin: Option<String>,
152+
},
129153
}
130154

131155
pub async fn run(
@@ -392,6 +416,37 @@ pub async fn run(
392416
}
393417
client.private_get("/v5/market/adlAlert", &params).await?
394418
}
419+
420+
AccountCommand::Borrow { coin, amount } => {
421+
confirm(&format!("Borrow {amount} {coin}?"), force)?;
422+
let body = json!({ "coin": coin, "qty": amount });
423+
client
424+
.private_post("/v5/account/manual-borrow", &body)
425+
.await?
426+
}
427+
428+
AccountCommand::Repay { coin, amount } => {
429+
confirm(&format!("Repay {amount} {coin}?"), force)?;
430+
let body = json!({ "coin": coin, "qty": amount });
431+
client
432+
.private_post("/v5/account/manual-repay", &body)
433+
.await?
434+
}
435+
436+
AccountCommand::QuickRepay { coin } => {
437+
let msg = match &coin {
438+
Some(c) => format!("Quick-repay liability for {c}?"),
439+
None => "Quick-repay all liabilities?".to_string(),
440+
};
441+
confirm(&msg, force)?;
442+
let mut body = json!({});
443+
if let Some(c) = coin {
444+
body["coin"] = json!(c);
445+
}
446+
client
447+
.private_post("/v5/account/quick-repayment", &body)
448+
.await?
449+
}
395450
};
396451

397452
print_output(&value, format);

0 commit comments

Comments
 (0)