Skip to main content

Agent workflows

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

Market scanner

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

Full trading workflow

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

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

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

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

Portfolio monitoring

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

Bulk order management

Place a ladder of buy orders:
context-cli 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-cli orders mine --market <id> | \
  jq -r '.[].nonce' | \
  paste -sd, | \
  xargs -I{} context-cli orders bulk-cancel --nonces {}

Piping and filtering

Find markets with wide spreads:
context-cli markets list --status active | \
  jq -r '.[].id' | \
  while read id; do
    context-cli markets quotes "$id" | \
      jq --arg id "$id" 'select(.ask - .bid > 10) | {id: $id, spread: (.ask - .bid)}'
  done
Export portfolio to CSV:
context-cli 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-cli setup
context-cli account mint-test-usdc --amount 5000
context-cli account deposit 5000

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