cb is the Coinbase trading CLI in this monorepo.
Source location: src/apps/cb
cb follows a layered split for order workflows:
src/apps/cb/commands/: command handlers (command intent only)src/apps/cb/service/order-builders.ts: pure sizing/validation/merge logicsrc/apps/cb/service/order-prompts.ts: interactive CLI summaries and confirmationssrc/apps/cb/service/order-service.ts: orchestration layer (builders + prompts + client calls)src/shared/coinbase/orders-client.ts: order-focused Coinbase transport APIsrc/shared/coinbase/rest.ts: low-level signed REST request helpers
When adding or changing order behavior:
- Put deterministic calculations and order-shape transforms in
order-builders.ts. - Keep
orders.tsthin and orchestration-only. - Keep direct Coinbase order create/get/list/cancel/edit calls behind
orders-client.ts. - Add/adjust typed fixtures in
test/src/fixtures/coinbase-orders.tsbefore adding large inline order objects in tests.
Command registration under src/apps/cb/commands/register/ uses one pattern:
withAction(commandName, parser, handler)fromregister/register-utils.ts- parser helpers (
parseArg,parseArgOptions,parseProductIdOptions, etc.) handle validation and argument normalization
Prefer parser composition over adding new one-off wrapper helpers.
- Node.js
>=20 - npm
Install dependencies from the repo root:
npm installConfigure env in the default helper path:
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/helper"
cp .env.example "${XDG_CONFIG_HOME:-$HOME/.config}/helper/.env"Set:
HELPER_COINBASE_CREDENTIALS_PATH=/absolute/path/to/coinbase-credentials.json
HELPER_ALLOW_LIVE_EXCHANGE=trueCreate credentials using Coinbase's API key authentication guide: https://docs.cdp.coinbase.com/coinbase-app/authentication-authorization/api-key-authentication
When creating the key, be sure to select the ECDSA signature algorithm (ES256).
Optional override:
export HELPER_ENV_FILE=/absolute/path/to/.envRun from TypeScript source:
npm run dev -- --helpnpm run dev -- price btc
Run built CLI:
npm run buildnode dist/apps/cb/cli.js --help
Install binary in your shell:
npm linkcb --help
Notes:
[product]defaults toBTCwhen omitted.- Use
cb <command> --helpfor command-specific options. - Prefer
cb ... --jsonwhen you want machine-readable output for automation or agent workflows.
cb accounts [product] [--crypto] [--cash] [--json] [--json-file <path>] [--raw] [--value](alias:account)- non-zero balances by default; hold/available are formatted to each currency's base increment using cached product metadata when present unless
--rawis used --jsonprints{ rows, filters, meta }for machine reading--json-file <path>writes the same structured payload to disk and still prints JSON to stdout--valueadds a USD value column based on current product price (forced product refresh for supported products)- when
[product]is provided, matching accounts are shown with price-based USD values
- non-zero balances by default; hold/available are formatted to each currency's base increment using cached product metadata when present unless
cb balance [--json] [--json-file <path>](alias:usd)--jsonprints{ row, meta }
cb cash [--json] [--json-file <path>] [--raw] [--value]- same structured payload and formatting flags as
cb accounts --cash
- same structured payload and formatting flags as
cb fees [--json] [--json-file <path>]--jsonprints{ row, meta }
cb product [product] [--json] [--json-file <path>]--jsonprints{ row, meta }
cb price [product] [--json] [--json-file <path>]--jsonprints{ row, meta }
cb buy [product] [--baseSize <baseSize>] [--value <value>]cb sell [product] [--baseSize <baseSize>] [--value <value>]cb market [product] (--buy | --sell) [--baseSize <baseSize>] [--value <value>]
cb bid [product] [--baseSize <baseSize>] [--value <value>] [--no-postOnly]cb ask [product] [--baseSize <baseSize>] [--value <value>] [--no-postOnly]cb limit [product] (--buy | --sell) --limitPrice <limitPrice> [--baseSize <baseSize>] [--value <value>] [--no-postOnly]cb stop [product] --baseSize <baseSize> --limitPrice <limitPrice> --stopPrice <stopPrice>cb bracket [product] --baseSize <baseSize> --limitPrice <limitPrice> --stopPrice <stopPrice>cb max [product]
cb plan [product] --buyPrice <price> --stopPrice <stopPrice> --takeProfitPrice <takeProfitPrice> [--riskPercent <riskPercent>] [--bufferPercent <bufferPercent>] [--all-in] [--dryRunFlag] [--no-postOnly]cb fib [product] --floor <price> --ceiling <price> [--entry <extension>] [--take-profit <extension>] [--round] [--riskPercent <riskPercent>] [--bufferPercent <bufferPercent>] [--all-in] [--dryRunFlag] [--no-postOnly]
cb order get <order_id> [--json] [--json-file <path>]--jsonprints{ row, meta }
cb order list [product] [--json] [--json-file <path>](alias:cb orders [product])--jsonprints{ rows, filters, meta }
cb order cancel <order_id>cb order replace <order_id>(re-places a cancelled priced order with the same prices and attached TP/SL when present; funding must be available: base asset for sells, USD for buys)cb order modify <order_id> [--baseSize <baseSize>] [--limitPrice <limitPrice>] [--stopPrice <stopPrice>] [--takeProfitPrice <takeProfitPrice>](supports limit, stop-limit, bracket, and TP/SL orders)cb order breakeven <order_id> --buyPrice <buyPrice> [--limitPrice <limitPrice>]
cb order modify behavior by order type:
LIMITwithout attached TP/SL:--baseSize,--limitPriceupdate the entry order--stopPrice/--takeProfitPriceare rejected
LIMITwith attached TP/SL (for example, fromcb planbefore fill):--baseSize,--limitPriceupdate the parent limit buy--stopPrice,--takeProfitPriceupdate the attached TP/SL legs
BRACKET(for example, the post-fill order created after a plan entry fills):--baseSizeupdates position size--limitPriceor--takeProfitPriceupdates the take-profit leg (price)--stopPriceupdates the stop leg (stop_price)
TAKE_PROFIT_STOP_LOSS:- same semantics as
BRACKET
- same semantics as
STOP_LIMIT:--baseSize,--limitPrice,--stopPriceare supported--takeProfitPriceis rejected
Prefer cb accounts --json when you want a stable machine-readable account snapshot for automation or agent-assisted inspection.
Examples:
cb accounts --json
cb accounts btc-usd --json
cb accounts --crypto --raw --json-file tmp/accounts.json
cb price eth --json
cb order list btc-usd --json-file tmp/open-orders.jsonnpm run lintnpm run typechecknpm run testnpm run buildnpm run release:check
Project workflow and standards are in CONTRIBUTING.md.