Bybit Trading CLI
Use bybit-cli (binary from bybit-official-trading-cli npm package) for any Bybit V5 API operation.
Bootstrap (do this first)
bybit-cli agent-briefing
That returns ~300 words covering auth setup, safety model, and how to explore commands. Read it carefully before making any API call.
Discovery
bybit-cli catalog— JSON list of all commands (domain, command, requiresAuth, method)bybit-cli <domain> <cmd> --json-schema— JSON Schema for one commandbybit-cli <domain> <cmd> --help— human-readable help
Auth setup
Two env vars minimum:
export BYBIT_API_KEY=<your key>
export BYBIT_API_SECRET=<your secret>
export BYBIT_ENV=testnet # or leave unset for mainnet
For RSA (self-generated key uploaded to Bybit):
export BYBIT_API_KEY=<your key>
export BYBIT_API_PRIVATE_KEY_PATH=/path/to/private.pem
Safety rules (MUST follow on mainnet)
- Every write op requires
--yes— CLI rejects with a summary of what would run - Withdraw / transfer / fiat / P2P are blocked by default — needs
--enable-advanced-money-opsto unlock (be certain first) - Set caps:
--cap-usd 500per-order,--cap-usd-total-hour 2000rolling,--max-orders-per-hour 20 - Kill-switch:
bybit-cli kill-switchfrom any shell blocks all writes untilbybit-cli enable-switch
Install (if which bybit-cli empty)
npm i -g bybit-official-trading-cli@latest
Update
bybit-cli self-update # install latest from npm
Set BYBIT_CLI_NO_UPDATE_CHECK=1 to silence update-available prompts.
Output shape
Every call returns JSON to stdout:
{"retCode":N, "retMsg":"...", "result":{...}, "cli":{"env":"mainnet"|"testnet"}}
retCode=0= success; non-zero = error,retMsg + cli.hintexplainscli.retry: true— safe to retrycli.nextSteps— specific commands to unblock- stderr may contain diagnostics; stdout is always parseable JSON