Skip to content

ibidathoillah/bittime-cli

Repository files navigation

bittime-cli

Unofficial Rust CLI for the Bittime exchange. Use it to inspect markets, manage account data, place spot orders, stream live WebSocket events, and expose the same command surface to agents through MCP.

Rust CLI WebSocket MCP

Highlights

  • Public market data: ping, server time, exchange info, tickers, order book, trades, aggregate trades.
  • Private account data: balances, account info, assets, order history, trade history.
  • Spot trading: market and limit buy/sell, query order, cancel order, open orders.
  • Funding and OTC: crypto deposit/withdraw history, OTC VA code, OTC IDR deposit and withdrawal history.
  • Real-time streams: market depth, private order events, private balance events, raw user channels.
  • Paper trading: local simulated balances and orders stored in ~/.config/bittime/paper_state.json.
  • Automation-friendly output: human tables by default, JSON envelopes with -o json.
  • Credential resolution: CLI flags, environment variables, or ~/.config/bittime/config.toml.
  • Agent support: MCP server mode for tool discovery and JSON-RPC execution.

Installation

Install from source:

git clone https://github.com/ibidathoillah/bittime-cli.git
cd bittime-cli
cargo install --path .

Install from crates.io:

cargo install bittime-cli

Install from npm:

npm install -g bittime-cli

Run with Docker:

docker run --rm ibidathoillah/bittime-cli --help
docker run --rm -e BITTIME_API_KEY -e BITTIME_API_SECRET ibidathoillah/bittime-cli balance

Run from the checkout:

cargo build
./target/debug/bittime --help

Quick Start

Market data does not require credentials:

bittime ping
bittime ticker usdt/idr
bittime orderbook usdt/idr --count 10
bittime -o json book-ticker usdt/idr

Configure private API credentials:

bittime auth set --api-key YOUR_API_KEY --api-secret YOUR_API_SECRET
bittime auth test

Or use environment variables:

export BITTIME_API_KEY=your_api_key
export BITTIME_API_SECRET=your_api_secret

Credential priority:

  1. --api-key and --api-secret
  2. BITTIME_API_KEY and BITTIME_API_SECRET
  3. ~/.config/bittime/config.toml

Command Reference

Global options:

bittime [OPTIONS] <COMMAND>

Options:
  -o, --output <table|json>      Output format [default: table]
      --api-key <API_KEY>        API key override
      --api-secret <API_SECRET>  API secret override
  -v, --verbose                  Enable verbose logs
      --host <HOST>              Override API host

Market

bittime ping
bittime server-time
bittime exchange-info
bittime ticker usdt/idr
bittime ticker-all
bittime price usdt/idr
bittime book-ticker usdt/idr
bittime orderbook usdt/idr --count 10
bittime trades usdt/idr --count 5
bittime agg-trades usdt/idr --count 5
bittime historical-trades usdt/idr --count 5

Account

bittime account-info
bittime balance
bittime account-info-v2
bittime assets usdt
bittime trades-history usdt/idr
bittime trades-history-v2 usdt/idr --since 123
bittime trades-legacy usdt/idr

Trading

bittime order buy usdt/idr -t LIMIT -p 16000 --volume 1
bittime order sell usdt/idr -t MARKET --volume 1
bittime order cancel usdt/idr --order-id 123456
bittime order query usdt/idr --order-id 123456
bittime order open-orders usdt/idr
bittime order all-orders usdt/idr
bittime order pending-orders usdt/idr
bittime order book-orders usdt/idr --count 5

Notes:

  • pending-orders is a compatibility alias for Bittime's documented openOrders endpoint.
  • book-orders returns public order book depth from Bittime's documented depth endpoint.

Funding

bittime withdraw --asset USDT --volume 100 --address 0x... --network ERC20
bittime withdrawal status --asset usdt
bittime deposit status --asset usdt
bittime deposit va --bank-id 7
bittime deposit otc-status --count 10
bittime withdrawal otc-status --count 10

Paper Trading

bittime paper init --pair usdt/idr --quote-balance 100000000 --base-balance 1
bittime paper balance
bittime paper buy usdt/idr --price 16000 --volume 1
bittime paper sell usdt/idr --price 17000 --volume 1
bittime paper fill 1
bittime paper orders
bittime paper orders --all
bittime paper cancel 2
bittime paper cancel-all --pair usdt/idr
bittime paper topup IDR 5000000
bittime paper history
bittime paper status
bittime paper reset

Use --fill on paper buy or paper sell to immediately settle an order at the supplied price.

WebSocket Streaming

Market depth:

bittime ws depth usdt/idr
bittime ws depth usdt/idr --limit 1 --seconds 15

Private streams:

bittime ws orders
bittime ws balances
bittime ws user user_order_update
bittime ws user user_balance_update

The WebSocket client handles Bittime's market gzip frames, market ping/pong, user-stream ping/pong, listen-key creation, and listen-key keepalive.

Interactive Shell

bittime shell

MCP Server

bittime mcp

The MCP server exposes CLI commands as machine-readable tools over JSON-RPC stdio.

E2E Testing

The repository includes live API smoke tests:

./scripts/e2e_test.sh --public
./scripts/e2e_test.sh --private
./scripts/e2e_test.sh --ws

Environment knobs:

BITTIME_TEST_PAIR=usdt/idr
BITTIME_TEST_COIN=usdt
BITTIME_BIN=./target/debug/bittime

Latest local verification:

cargo test: 16 passed
./scripts/e2e_test.sh --public: 22 passed
./scripts/e2e_test.sh --private: 19 passed
./scripts/e2e_test.sh --ws: 4 passed

API Coverage

  • REST base: https://openapi.bittime.com
  • Market WebSocket: wss://ws.bittime.com/market/ws
  • User WebSocket: wss://wsapi.bittime.com
  • API docs: https://bittime-docs.github.io/

Architecture

graph TD
    A[bittime binary] --> B[Clap command dispatcher]
    B --> C[AppContext]
    C --> D[BittimeClient]
    C --> E[Output dispatcher JSON/Table]
    D --> F[Bittime REST API]
    D --> G[Bittime WebSocket streams]
    B --> H[Interactive shell REPL]
    B --> I[Model Context Protocol server]
Loading

Security

  • Credentials are stored with 0600 permissions when using bittime auth set.
  • Prefer read-only API keys for account inspection and WebSocket monitoring.
  • Use IP restrictions on exchange API keys when possible.
  • Never commit real API keys, secrets, or listen keys.

Development

cargo fmt
cargo test
cargo build

Related Projects

If you use multiple exchanges, check out these related CLI tools built with the same architecture:

License

MIT

Disclaimer

This project is unofficial and is not affiliated with or endorsed by Bittime. Cryptocurrency trading is risky; review commands carefully before using write-capable API keys.

About

Unofficial high-performance Rust command-line interface and Model Context Protocol server for the Bittime spot exchange. Supports REST API queries, real-time WebSocket streams, stateful interactive REPL shell, secure credential resolution, and simulated paper trading.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors