Sway Documentation
Build on a gasless, non-custodial prediction market with transparent, automatic on-chain resolution — for people, wallets, and AI agents alike.
Get Started →// No SDK required — Sway is a plain REST API.
const SWAY = 'https://api.swaytrade.xyz';
// 1. Read the live deployment (chain + fee policy)
const dep = await fetch(`${SWAY}/deployment`).then(r => r.json());
console.log(dep.chain_id, dep.fee_bps); // 84532 150
// 2. Browse open markets
const markets = await fetch(`${SWAY}/markets`).then(r => r.json());
const m = markets[0];
console.log(m.question, m.resolver, m.voided);# No SDK required — Sway is a plain REST API.
import requests
SWAY = "https://api.swaytrade.xyz"
# 1. Read the live deployment (chain + fee policy)
dep = requests.get(f"{SWAY}/deployment").json()
print(dep["chain_id"], dep["fee_bps"]) # 84532 150
# 2. Browse open markets
markets = requests.get(f"{SWAY}/markets").json()
m = markets[0]
print(m["question"], m["resolver"], m["voided"])Get familiar with Sway
Learn the fundamentals, explore the API, and start building on a prediction market designed to be transparent and verifiable end-to-end.
Quickstart
Set up your environment and make your first API call in minutes.
Core Concepts
Understand markets, outcomes, oracles, and non-custodial escrow.
API Reference
Explore REST endpoints, WebSocket streams, and authentication.
SDKs
Official Python and TypeScript libraries for faster development.
Quickstart
Fetch market data, read the fee policy, and stream live prices — in a few requests, with nothing to install.
Base URL
Every REST call hits a single host. The beta runs on Base Sepolia.
1 · Read the deployment
/deployment is the source of truth for the active chain, the contract addresses, and the live fee policy. Read it once at startup and cache it.
const dep = await fetch('https://api.swaytrade.xyz/deployment').then(r => r.json());
// { chain_id: 84532, fee_bps: 150, fee_mode: 'flat',
// resolver, reportable_resolver, escrow, exchange, relayer_ready: true }dep = requests.get("https://api.swaytrade.xyz/deployment").json()
# {'chain_id': 84532, 'fee_bps': 150, 'fee_mode': 'flat',
# 'escrow': '0x…', 'exchange': '0x…', 'relayer_ready': True}2 · List & read markets
GET /markets returns every live market; GET /markets/{'{'}id{'}'} returns one. Each row carries its question, the bound resolver, and status flags (resolved, voided, archived).
const markets = await fetch('https://api.swaytrade.xyz/markets').then(r => r.json());
const m = markets.find(x => !x.resolved && !x.archived);
const market = await fetch(`https://api.swaytrade.xyz/markets/${m.market_id}`).then(r => r.json());markets = requests.get("https://api.swaytrade.xyz/markets").json()
m = next(x for x in markets if not x["resolved"] and not x["archived"])
market = requests.get(f"https://api.swaytrade.xyz/markets/{m['market_id']}").json()3 · Stream live prices
Subscribe to the WebSocket for real-time fills and odds. See WebSockets for the full event set.
const ws = new WebSocket('wss://api.swaytrade.xyz/agent/stream');
ws.onmessage = (e) => {
const ev = JSON.parse(e.data);
if (ev.type === 'fill') console.log('fill', ev.market_id, ev.price);
};Markets & Events
A market is a single yes/no question about the world, with a defined close time and a resolution source.
Each market has a stable market_id (keccak256(questionId, resolver, seq)), a human question, a close time (trading ends), and a bound resolver that settles it. Related markets group into events — e.g. a multi-candidate race is several mutually-exclusive yes/no markets shown as one field.
Outcomes & Shares
Every market has two outcomes — ● Yes and ● No. You hold outcome shares; a winning share redeems for $1.00, a losing share for $0. Price is the market's implied probability, quoted 0–1 (e.g. 0.55 = 55%). Buying Yes is Sway Yes; buying No is Sway No.
Resolution & Oracles
Sway resolves markets automatically and on-chain wherever possible. A market is bound to one of four resolver tiers:
| Tier | How it settles | Example |
|---|---|---|
| Api3 | A Tier-1 API3 dAPI price feed read on-chain at close. | "ETH ≥ $4,000 by Friday?" |
| Signed | An AirnodeHub-signed attestation verified on-chain (EIP-191). | Esports, crypto headers |
| Optimistic | A bonded assertion with a dispute window → committee vote. | Subjective / news |
| Reportable | Operator-reported outcome (testnet / bootstrapping). | Manual markets |
If a market can't resolve (e.g. an oracle was never configured), it can be voided to a 50/50 refund — no funds are ever stranded. See Void & Refunds.
Non-custody & Escrow
Sway never holds your money. Your balance lives in your own Safe smart account; collateral for open positions sits in an on-chain Escrow contract, backed 1:1. Every market surfaces "Held in escrow, not by Sway" with the escrow address and a verifiable transaction + block. Non-custodial and verifiable — shown, not claimed.
Collateral
Markets are collateralized in a single stablecoin per deployment.
The beta uses Circle USDC on Base Sepolia (6 decimals). Prices, sizes, and fees are quoted in 6-decimal fixed point — 550000 = $0.55, 100000000 = 100 shares. Deposits can arrive same-chain or cross-chain (Circle CCTP / intents), and are always converted to the deployment's collateral at the door.
Orders & Settlement
Orders are EIP-712 signed by your Safe and submitted to POST /orders/signed. The relayer matches and settles them on-chain, gaslessly. Every order carries a signed max-fee cap (maxFee) — the protocol can never charge above what you signed.
// Shape of a signed limit order (see Authentication for signing).
await fetch('https://api.swaytrade.xyz/orders/signed', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
order: {
trader: safeAddress,
marketId,
outcome: 1, // 1 = Yes, 2 = No
price: 550000, // 0.55 (6dp)
size: 100000000, // 100 shares (6dp)
maxFee, // signed fee cap (A2)
nonce, deadline,
},
signature, // EIP-712 / ERC-1271 from the Safe
}),
});Void & Refunds
Every market has a refund path. If a market can't be resolved, it is voided: both sides redeem a 50/50 refund of the collateral they staked, and any fee charged is refunded. No position is ever permanently frozen (invariant INV-11).
REST Reference
Public reads need no auth. Trading uses signed orders; operator routes are token-gated.
api.swaytrade.xyz.Authentication
Three access modes:
- Public reads —
GET /markets,/deployment, prices: no auth. - Trading — orders are EIP-712 signed by your Safe smart account (ERC-1271). No API key; the signature is the auth.
- Agents — programmatic traders use a scoped API key (
Authorization: Bearer …), owner-bound to a Safe, with per-key caps. See Agent API.
WebSockets
A single stream pushes live fills and odds as markets move.
const ws = new WebSocket('wss://api.swaytrade.xyz/agent/stream');
ws.onmessage = (e) => {
const ev = JSON.parse(e.data);
switch (ev.type) {
case 'fill': console.log('fill', ev.market_id, ev.outcome, ev.price); break;
case 'odds': console.log('odds', ev.market_id, ev.yes); break;
}
};# pip install websockets
import asyncio, json, websockets
async def main():
async with websockets.connect("wss://api.swaytrade.xyz/agent/stream") as ws:
async for raw in ws:
ev = json.loads(raw)
if ev["type"] == "fill":
print("fill", ev["market_id"], ev["price"])
asyncio.run(main())Fees & Rebates
A single, transparent taker fee — read from chain, capped by your signature, and shared back to makers and referrers.
| Component | Value | Notes |
|---|---|---|
| Taker fee | 1.5% (150 bps) | An extra debit at settlement — the winner's $1.00 payout is never shaved. |
| Maker rebate | 30% of the fee | Accrues to the resting order that got filled. |
| Referral | 10% of the fee | Accrues to the referrer of the taker. |
| Signed cap | per order | Every order carries a maxFee you sign — the protocol can't charge above it. |
The live fee is read on-chain from the FeePolicy contract (GET /fees/summary echoes it), so it's always verifiable. Rebates accrue off-chain and are paid out automatically.
Agent API
AI agents are first-class traders on Sway — they trade right next to people.
An agent authenticates with a scoped API key (issued, rotated, and revoked from your console), owner-bound to a Safe with per-key caps and allowlists. The /agent/* surface mirrors the trading API, adds the live stream, and offers optional metered premium data (x402). A built-in runaway halt caps per-window activity so a misbehaving agent can't run away.
const res = await fetch('https://api.swaytrade.xyz/agent/markets', {
headers: { Authorization: `Bearer ${process.env.SWAY_AGENT_KEY}` },
});SDKs
fetch / requests. Watch the Changelog.Partner Integration
System Status
Live uptime for the API, relayer, oracles, and funding rails will be published at status.swaytrade.xyz.
Changelog
Notable platform changes. Full history lives in the repository.
| 2026-11-26 | Api3 void-escape live — any market now has a guaranteed on-chain refund path. |
| 2026-11-25 | Signed-order fee cap (per-order maxFee) and multisig governance. |
| 2026-11-24 | Fee-aware settlement with maker rebates & referrals. |
| 2026-11-20 | Agent tier — scoped API keys, live stream, runaway halt. |