Documentation Index
Fetch the complete documentation index at: https://docs.context.markets/llms.txt
Use this file to discover all available pages before exploring further.
Placing your first order
This guide walks through submitting your first order to Context, from setup to execution.
Prerequisites
- Node.js 18+ or Bun
- A wallet with a private key
- An API key — see API keys to create one
- Wallet approved and funded — see Before you trade
Setup
npm install context-markets
import { ContextClient } from "context-markets"
const ctx = new ContextClient({
apiKey: process.env.CONTEXT_API_KEY!,
signer: { privateKey: process.env.PRIVATE_KEY! as `0x${string}` },
})
console.log("Wallet address:", ctx.address)
1. Find a market
const { markets } = await ctx.markets.list({ sortBy: "trending", limit: 5 })
const market = markets[0]
console.log("Market:", market.question)
2. Check the orderbook
const book = await ctx.markets.orderbook(market.id, { depth: 5 })
console.log("\nOrderbook:")
console.log("Asks (sell orders):")
for (const ask of book.asks.slice(0, 3)) {
console.log(` ${ask.price}¢ - ${ask.size} contracts`)
}
console.log("Bids (buy orders):")
for (const bid of book.bids.slice(0, 3)) {
console.log(` ${bid.price}¢ - ${bid.size} contracts`)
}
3. Place the order
The SDK handles EIP-712 signing automatically — just specify what you want to trade:
const { order } = await ctx.orders.create({
marketId: market.id,
outcome: "yes",
side: "buy",
priceCents: 55, // 55¢ per contract
size: 1, // 1 contract
})
console.log("Order placed:", order.nonce)
That’s it — no manual EIP-712 signing, no BigInt encoding, no contract ABIs.
4. Check order status
const { orders } = await ctx.orders.mine(market.id)
console.log("\nYour open orders:")
for (const o of orders) {
console.log(`- ${o.nonce.slice(0, 10)}...`)
console.log(` Status: ${o.status}`)
console.log(` Filled: ${o.percentFilled}%`)
}
5. Cancel if needed
const result = await ctx.orders.cancel(order.nonce)
console.log("Cancelled:", result.success)
Complete script
Here’s the full flow in one file:
import { ContextClient } from "context-markets"
const ctx = new ContextClient({
apiKey: process.env.CONTEXT_API_KEY!,
signer: { privateKey: process.env.PRIVATE_KEY! as `0x${string}` },
})
// Find a market
const { markets } = await ctx.markets.list({ sortBy: "trending", limit: 1 })
const marketId = markets[0].id
// Place order
const { order } = await ctx.orders.create({
marketId,
outcome: "yes",
side: "buy",
priceCents: 55,
size: 1,
})
console.log("Order placed:", order.nonce)
// Check status
const { orders } = await ctx.orders.mine(marketId)
console.log("Open orders:", orders.length)
CONTEXT_API_KEY=your_key PRIVATE_KEY=0xyour_key npx tsx first-order.ts
Next steps
SDK reference
Full SDK documentation
Orders API
Bulk operations, cancel-replace, and more