CLI for trading on Context Markets prediction markets. Works interactively or as JSON for AI agents.
npm install -g context-markets-cliThis installs the context command globally.
Or run without installing:
npx context-markets-cli <command>The fastest way to get set up:
context setupThis walks you through:
- Wallet — generate a new wallet or import an existing private key
- Save credentials — persists to
~/.config/context/config.env(chmod 600) - API key — prompts for your Context API key (get one at context.markets)
- Approve contracts — checks ETH balance, approves on-chain (requires ETH on Base for gas)
- Deposit USDC — checks USDC balance, deposits into the exchange
If anything fails (no ETH, rate limit, etc.), you can re-run context setup — it detects your existing config and picks up where you left off.
If you prefer to configure manually:
# Option 1: Environment variables
export CONTEXT_API_KEY="your-api-key"
export CONTEXT_PRIVATE_KEY="0x..."
# Option 2: Config file (created by `context setup`)
# ~/.config/context/config.envCredentials are loaded in order: CLI flags > env vars > config file.
Need an API key? Visit context.markets or join our Discord.
# Browse markets
context markets list --status active --limit 5
# Search for a market
context markets search "march madness"
# Get a link to a market
context markets link <market-id>
# View the orderbook
context markets orderbook <market-id>
# Place a limit order
context orders create --market <id> --outcome yes --side buy --price 45 --size 10
# Check your portfolio
context portfolio overview
# Interactive shell
context shellThe CLI supports a fully non-interactive JSON mode for AI agents:
# 1. Generate wallet and save to config
context setup --output json --save
# → { "status": "new_wallet", "address": "0x...", "privateKey": "0x...", "configPath": "..." }
# 2. Approve contracts (after funding wallet with ETH on Base)
context approve --output json
# → { "status": "approved", "usdcApprovalTx": "0x...", "operatorApprovalTx": "0x..." }
# 3. Deposit USDC
context deposit 100 --output json
# → { "status": "deposited", "amount_usdc": 100, "tx_hash": "0x..." }
# 4. Trade
context orders create --market <id> --outcome yes --side buy --price 45 --size 10 --output jsonAll commands accept --output json for structured output. When piped (non-TTY), JSON is the default.
Markets — markets list · markets search · markets get · markets link · markets quotes · markets orderbook · markets simulate · markets price-history · markets oracle · markets oracle-quotes · markets request-oracle-quote · markets activity · markets global-activity · markets create
Orders — orders list · orders mine · orders get · orders recent · orders simulate · orders create · orders market · orders cancel · orders cancel-replace · orders bulk-create · orders bulk-cancel · orders bulk
Portfolio — portfolio overview · portfolio get · portfolio claimable · portfolio stats · portfolio balance · portfolio token-balance
Account — account status · account setup · account deposit · account withdraw · account mint-test-usdc · account mint-complete-sets · account burn-complete-sets · account gasless-approve · account gasless-deposit
Questions — questions submit · questions status · questions submit-and-wait · questions agent-submit · questions agent-submit-and-wait
Other — setup · approve · deposit · guides · ecosystem · shell
Run context <command> help or context <command> --help for details on any command.
- Prices are in cents (1–99). A price of 65 means $0.65 per share.
- Outcomes are
yesorno. Each market is a binary question. - Output auto-detects: tables in a terminal, JSON when piped. Override with
--output jsonor--output table. - Read-only commands only need
CONTEXT_API_KEY. Trading commands also needCONTEXT_PRIVATE_KEY. - Interactive shell (
context shell) supports#Nrow references,next/backpagination, and all commands.
Built-in guides are available in the CLI:
context guides # List available guides
context guides trading # View the trading guide- Command Reference — full list of commands with flags and response shapes
- CLI Guide — setup, authentication, and workflows
- Agent Workflows — common patterns for AI agent integration
| Package | Description |
|---|---|
| context-markets | TypeScript SDK for trading |
| context-markets-react | React hooks for market data and trading |
| context-markets-mcp | MCP server for AI agents |
| context-markets-cli | CLI for trading from the terminal |
| context-skills | AI agent skill files |
| context-plugin | Claude Code plugin |
MIT — see LICENSE for details.