Skip to main content

Hooks reference

All hooks are exported from @contextwtf/react. Query hooks return TanStack Query results (data, isLoading, error). Mutation hooks return mutate, mutateAsync, isPending, error.

Markets

useMarkets

const { data, isLoading, error } = useMarkets(params?)
List and filter markets. Parameters match ctx.markets.list(): status, category, creator, query, sortBy, sort, limit, cursor.

useMarket

const { data, isLoading, error } = useMarket(marketId: string)
Get a single market by ID.

useOrderbook

const { data, isLoading, error } = useOrderbook(marketId: string, params?)
Live orderbook for a market. Optional depth and outcomeIndex parameters.

useQuotes

const { data, isLoading, error } = useQuotes(marketId: string)
Current bid, ask, and last trade prices for both outcomes.

usePriceHistory

const { data, isLoading, error } = usePriceHistory(marketId: string, params?)
Historical price data. Optional timeframe parameter: "1h", "6h", "1d", "1w", "1M", "all".

useMarketActivity

const { data, isLoading, error } = useMarketActivity(marketId: string, params?)
Market event feed. Optional limit and cursor parameters.

useSimulateTrade

const { data, isLoading, error } = useSimulateTrade(marketId: string, params: {
  side: string, amount: number, amountType?: "usd" | "contracts"
})
Preview trade execution including estimated contracts, average price, and slippage.

useOracle

const { data, isLoading, error } = useOracle(marketId: string)
Oracle resolution data including probability estimates, confidence, and reasoning.

Orders

useOrders

const { data, isLoading, error } = useOrders(params?)
List orders with filters: trader, market, status, limit, cursor.

useMyOrders

const { data, isLoading, error } = useMyOrders(params?)
Your open orders. Optional market filter.

useCreateOrder

const { mutate, mutateAsync, isPending, error } = useCreateOrder()
Place a limit order. Call with { marketId, outcome, side, priceCents, size, expirySeconds? }. Requires connected wallet.

useMarketOrder

const { mutate, mutateAsync, isPending, error } = useMarketOrder()
Place a market order. Call with { marketId, outcome, amount, amountType? }. Requires connected wallet.

useCancelOrder

const { mutate, mutateAsync, isPending, error } = useCancelOrder()
Cancel an open order. Call with the order nonce (string). Requires connected wallet.

useCancelReplaceOrder

const { mutate, mutateAsync, isPending, error } = useCancelReplaceOrder()
Cancel and replace an order atomically. Call with { nonce, priceCents, size }. Requires connected wallet.

Portfolio

usePositions

const { data, isLoading, error } = usePositions(params?)
View positions across markets. Optional address, kind ("all", "active", "won", "lost", "claimable"), market, cursor, pageSize.

useBalance

const { data, isLoading, error } = useBalance(params?)
USDC balance including wallet and settlement balances. Optional address.

useClaimable

const { data, isLoading, error } = useClaimable(params?)
Winnings from resolved markets. Optional address.

usePortfolioStats

const { data, isLoading, error } = usePortfolioStats(params?)
Portfolio value and PnL metrics. Optional address.

Account

useAccountStatus

const { data, isLoading, error } = useAccountStatus()
Wallet status including ETH balance, USDC allowance, operator approval, and whether setup is needed.

useSetupAccount

const { mutate, mutateAsync, isPending, error } = useSetupAccount()
Approve contracts for trading. Call with no arguments. Requires connected wallet.

useDeposit

const { mutate, mutateAsync, isPending, error } = useDeposit()
Deposit USDC into the exchange. Call with amount (number). Requires connected wallet.

useWithdraw

const { mutate, mutateAsync, isPending, error } = useWithdraw()
Withdraw USDC from the exchange. Call with amount (number). Requires connected wallet.