Skip to main content

Agent workflows

Common patterns for using the CLI in agent pipelines and automation scripts.

Non-interactive agent workflow

Set up and start trading without any interactive prompts, suitable for headless environments:
# Generate wallet and save credentials
context setup --output json --save

# Approve exchange contracts
context approve --output json

# Deposit USDC for trading
context deposit 100 --output json

# Now ready to trade
context markets search "elections" --output json
context orders create --market <id> --outcome yes --side buy --price 45 --size 10 --output json

Market scanner

Find trending markets and get quotes for each:
context markets list --status active --sort-by trending --limit 10 | \
  jq -r '.[].id' | \
  while read id; do
    echo "=== Market: $id ==="
    context markets quotes "$id"
  done

Full trading workflow

Research, simulate, trade, and monitor:
# 1. Check account status
context account status

# 2. Research the market
context markets quotes <market-id>
context markets simulate <market-id> --side yes --amount 100 --amount-type usd

# 3. Place the trade
context orders create \
  --market <market-id> \
  --outcome yes \
  --side buy \
  --price 45 \
  --size 10

# 4. Monitor the order
context orders mine --market <market-id>

Portfolio monitoring

Periodic portfolio check loop:
while true; do
  echo "$(date): Portfolio update"
  context portfolio get --kind active | jq 'length' | xargs -I{} echo "Active positions: {}"
  context portfolio stats | jq '{totalValue, pnl}'
  context portfolio balance | jq '{wallet, settlement}'
  sleep 60
done

Bulk order management

Place a ladder of buy orders:
context orders bulk-create --orders '[
  {"market":"<id>","outcome":"yes","side":"buy","price":40,"size":5},
  {"market":"<id>","outcome":"yes","side":"buy","price":35,"size":5},
  {"market":"<id>","outcome":"yes","side":"buy","price":30,"size":5}
]'
Cancel all open orders on a market:
context orders mine --market <id> | \
  jq -r '.[].nonce' | \
  paste -sd, | \
  xargs -I{} context orders bulk-cancel --nonces {}

Piping and filtering

Find markets with wide spreads:
context markets list --status active | \
  jq -r '.[].id' | \
  while read id; do
    context markets quotes "$id" | \
      jq --arg id "$id" 'select(.ask - .bid > 10) | {id: $id, spread: (.ask - .bid)}'
  done
Export portfolio to CSV:
context portfolio get --kind active | \
  jq -r '.[] | [.marketId, .outcome, .size, .avgPrice] | @csv' > positions.csv

Complete agent setup

One-time setup for a new agent:
# Generate wallet and fund it
context setup
context account mint-test-usdc --amount 5000
context account deposit 5000

# Verify everything is ready
context account status | jq '{isSetup, walletBalance, settlementBalance}'

Market creation

Submit a prediction market draft for oracle review, then wait for approval:
# Submit a prediction market draft for oracle review
context questions agent-submit-and-wait \
  --formatted-question "Will X happen by Y?" \
  --short-question "X by Y?" \
  --market-type binary \
  --evidence-mode live_data \
  --resolution-criteria "Resolves YES if X happens before Y date" \
  --end-time "2026-06-01T00:00:00Z" \
  --explanation "Market tracks whether X will occur"

# The command polls until the oracle approves or rejects
# If approved, the market is created on-chain automatically