Skip to content

Latest commit

 

History

History
163 lines (110 loc) · 6.34 KB

File metadata and controls

163 lines (110 loc) · 6.34 KB

Context

Context CLI

CLI for trading on Context Markets prediction markets. Works interactively or as JSON for AI agents.

npm License: MIT Discord

Install

npm install -g context-markets-cli

This installs the context command globally.

Or run without installing:

npx context-markets-cli <command>

Getting Started

The fastest way to get set up:

context setup

This walks you through:

  1. Wallet — generate a new wallet or import an existing private key
  2. Save credentials — persists to ~/.config/context/config.env (chmod 600)
  3. API key — prompts for your Context API key (get one at context.markets)
  4. Approve contracts — checks ETH balance, approves on-chain (requires ETH on Base for gas)
  5. 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.

Manual setup

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.env

Credentials are loaded in order: CLI flags > env vars > config file.

Need an API key? Visit context.markets or join our Discord.

Quick Start

# 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 shell

Agent Workflow

The 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 json

All commands accept --output json for structured output. When piped (non-TTY), JSON is the default.

Commands

Marketsmarkets 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

Ordersorders 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

Portfolioportfolio overview · portfolio get · portfolio claimable · portfolio stats · portfolio balance · portfolio token-balance

Accountaccount 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

Questionsquestions submit · questions status · questions submit-and-wait · questions agent-submit · questions agent-submit-and-wait

Othersetup · approve · deposit · guides · ecosystem · shell

Run context <command> help or context <command> --help for details on any command.

Key Concepts

  • Prices are in cents (1–99). A price of 65 means $0.65 per share.
  • Outcomes are yes or no. Each market is a binary question.
  • Output auto-detects: tables in a terminal, JSON when piped. Override with --output json or --output table.
  • Read-only commands only need CONTEXT_API_KEY. Trading commands also need CONTEXT_PRIVATE_KEY.
  • Interactive shell (context shell) supports #N row references, next/back pagination, and all commands.

Guides

Built-in guides are available in the CLI:

context guides              # List available guides
context guides trading      # View the trading guide

Documentation

Ecosystem

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

License

MIT — see LICENSE for details.