API Reference
REST API & SDK Reference
Use @x402/fetch to interact with the Syzy x402 prediction market API. Payment negotiation, signing, and retries are handled automatically.
Installation
Terminal
npm install @x402/fetch @x402/svm @solana/web3.jsClient Setup
TypeScript
import { wrapFetch } from "@x402/fetch";
import { createSvmSigner } from "@x402/svm";
import { Keypair } from "@solana/web3.js";
// Create a signer from your funded Solana keypair
const keypair = Keypair.fromSecretKey(/* your secret key */);
const signer = createSvmSigner(keypair);
// Wrap the global fetch with x402 payment negotiation
const x402Fetch = wrapFetch(fetch, signer);
// Use x402Fetch like normal fetch — it handles 402 payment automatically
const API = "https://api.oyrade.com";API Reference
| Endpoint | Returns | Price |
|---|---|---|
| POST /api/v1/markets/create | CreateMarketResult | $0.50 |
| POST /api/v1/markets/:id/predict | PlacePredictionResult | $0.01+ |
| POST /api/v1/markets/:id/sell | SellResult | $0.01 |
| POST /api/v1/markets/:id/claim | ClaimResult | $0.01 |
| GET /api/v1/markets/:id/resolve | ResolveMarketResult | $0.05 |
| GET /api/v1/markets/:id/privacy-proof | PrivacyProofResult | $0.10 |
| GET /api/v1/markets/:id/news | NewsResult | $0.01 |
| GET /api/v1/markets | ListMarketsResult | Free |
| GET /api/v1/markets/:id | MarketDetail | Free |
| GET /api/v1/positions | PositionsResult | Free |
| GET /api/v1/history | TradeHistoryResult | Free |
| GET /health | HealthResult | Free |
| GET /x402-info | EndpointInfoResult | Free |
POST /api/v1/markets/create→ CreateMarketResultTypeScript
const res = await x402Fetch(`${API}/api/v1/markets/create`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
token_mint: "DfnxGQUsXdDH7DYdroeeSBG8etqTy1kufxBikHwTTGTa",
question: "Will BTC reach $200K by 2027?",
market_name: "BTC 200K 2027",
slug: "btc-200k-2027",
category: "crypto",
end_date: Math.floor(new Date("2027-01-01").getTime() / 1000),
image_url: "https://example.com/btc.png", // optional
oracle_feed: "BTC/USD", // optional
price_target: 200000, // optional
comparison_type: "above", // optional
}),
});
const { data } = await res.json();
// data: { market_id, yes_token_mint, no_token_mint, tx_signature, question, end_date }POST /api/v1/markets/:id/predict→ PlacePredictionResultTypeScript
const res = await x402Fetch(`${API}/api/v1/markets/${marketId}/predict`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
outcome: "YES", // "YES" or "NO"
amount: 0.5, // SOL amount (0.01-100), buckets: 0.1, 0.5, 1, 5, 10
commitment_hash: "a1b2...f6a1", // 64 hex chars, required for privacy
}),
});
const { data } = await res.json();
// data: { prediction_id, commitment, outcome, amount, tokens_received, effective_price,
// yes_price_after, no_price_after }POST /api/v1/markets/:id/sell→ SellResultTypeScript
const res = await x402Fetch(`${API}/api/v1/markets/${marketId}/sell`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
commitment_hash: "a1b2...f6a1",
payout_address: "YourSo1anaWa11etAddress...",
amount: 0.3, // optional: partial sell
}),
});
const { data } = await res.json();
// data: { tx_signature, tokens_sold, sol_received, payout_address }POST /api/v1/markets/:id/claim→ ClaimResultTypeScript
const res = await x402Fetch(`${API}/api/v1/markets/${marketId}/claim`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
commitment_hash: "a1b2...f6a1",
payout_address: "YourSo1anaWa11etAddress...",
}),
});
const { data } = await res.json();
// Win: { claimable: true, tx_signature, sol_received, winning_outcome, payout_address }
// Loss: { claimable: false, reason: "Position lost..." }GET /api/v1/markets/:id/resolve→ ResolveMarketResultTypeScript
const res = await x402Fetch(`${API}/api/v1/markets/${marketId}/resolve`);
const { data } = await res.json();
// Resolved: { resolved: true, winning_outcome, oracle_price, oracle_source, tx_signature, resolved_at }
// Not ready: { resolved: false, reason, end_date }GET /api/v1/markets/:id/privacy-proof→ PrivacyProofResultTypeScript
const hash = "a1b2...f6a1";
const res = await x402Fetch(
`${API}/api/v1/markets/${marketId}/privacy-proof?commitment_hash=${hash}`
);
const { data } = await res.json();
// data: { position_exists, outcome?, amount_range?, merkle_root?, proof_path? }GET /api/v1/markets/:id/news→ NewsResultTypeScript
const res = await x402Fetch(`${API}/api/v1/markets/${marketId}/news`);
const { data } = await res.json();
// data: { news: [{ id, title, description, image_url, url, published_at }] }GET /api/v1/markets→ ListMarketsResultTypeScript
const res = await fetch(`${API}/api/v1/markets`);
const { data } = await res.json();
// data: { markets: [{ market_id, question, market_name, category, yes_price, no_price,
// total_volume_sol, end_date, is_completed, winning_outcome, oracle_feed, created_at,
// market_version }] }GET /api/v1/markets/:id→ MarketDetailTypeScript
const res = await fetch(`${API}/api/v1/markets/${marketId}`);
const { data } = await res.json();
// data: { market_id, question, market_name, slug, category, yes_price, no_price,
// yes_sol_reserves, no_sol_reserves, yes_token_supply, no_token_supply,
// total_volume_sol, end_date, is_completed, winning_outcome, source, image_url, ... }GET /api/v1/positions→ PositionsResultTypeScript
const hashes = "abc123,def456";
const res = await fetch(`${API}/api/v1/positions?commitment_hash=${hashes}`);
const { data } = await res.json();
// data: { positions: [{ commitment_hash, market_id, outcome, tokens_remaining,
// sol_spent, current_value_sol, payout_if_win, status, created_at }] }GET /api/v1/history→ TradeHistoryResultTypeScript
const hashes = "abc123,def456";
const res = await fetch(`${API}/api/v1/history?commitment_hash=${hashes}`);
const { data } = await res.json();
// data: { trades: [{ type, commitment_hash, market_id, outcome, amount_sol,
// tokens, tx_signature, created_at }] }GET /health→ HealthResultTypeScript
const res = await fetch(`${API}/health`);
const { data } = await res.json();
// data: { status: "ok", version: "0.1.0", network: "devnet", uptime: 84321000, market_count: 42 }GET /x402-info→ EndpointInfoResultTypeScript
const res = await fetch(`${API}/x402-info`);
const { data } = await res.json();
// data: { name, description, endpoints: [...], network: "solana-devnet", payment_token: "USDC" }TypeScript Types
All request and response types for the API:
types.ts
// Request types
interface CreateMarketParams {
token_mint: string;
question: string;
market_name: string;
slug: string;
category: string;
end_date: number; // Unix timestamp
image_url?: string;
source?: string;
oracle_feed?: string;
price_target?: number;
comparison_type?: string;
market_version?: number;
collateral_per_pair?: number;
}
interface PlacePredictionParams {
outcome: "YES" | "NO";
amount: number; // SOL (0.01-100), buckets: 0.1, 0.5, 1, 5, 10
commitment_hash: string; // 64 hex chars, required
}
interface SellParams {
commitment_hash: string;
payout_address: string;
amount?: number; // Optional: partial sell
}
interface ClaimParams {
commitment_hash: string;
payout_address: string;
}
// Response types
interface CreateMarketResult {
market_id: string;
yes_token_mint: string;
no_token_mint: string;
tx_signature: string;
question: string;
end_date: number;
}
interface PlacePredictionResult {
prediction_id: string;
commitment: string;
outcome: "YES" | "NO";
amount: number;
tokens_received: number;
effective_price: number;
yes_price_after: number;
no_price_after: number;
}
interface SellResult {
tx_signature: string;
tokens_sold: number;
sol_received: number;
payout_address: string;
}
interface ClaimResult {
claimable: boolean;
tx_signature?: string;
sol_received?: number;
winning_outcome?: "YES" | "NO";
payout_address?: string;
reason?: string;
}
interface ResolveMarketResult {
resolved: boolean;
winning_outcome?: "YES" | "NO";
oracle_price?: number;
oracle_source?: string;
tx_signature?: string;
resolved_at?: string;
reason?: string;
end_date?: number;
}
interface PrivacyProofResult {
position_exists: boolean;
outcome?: "YES" | "NO";
amount_range?: string;
merkle_root?: string;
proof_path?: string[];
}
interface NewsItem {
id: string;
title: string;
description: string;
image_url: string;
url: string;
published_at: string;
}
interface MarketSummary {
market_id: string;
question: string;
market_name: string;
category: string;
yes_price: number;
no_price: number;
total_volume_sol: number;
end_date: number;
is_completed: boolean;
winning_outcome: "YES" | "NO" | null;
oracle_feed: string | null;
created_at: string;
market_version: number;
}
interface MarketDetail extends MarketSummary {
slug: string;
source: string | null;
image_url: string | null;
yes_sol_reserves: number;
no_sol_reserves: number;
yes_token_supply: number;
no_token_supply: number;
}
interface PositionResult {
commitment_hash: string;
market_id: string;
outcome: "YES" | "NO";
tokens_remaining: number;
sol_spent: number;
current_value_sol: number;
payout_if_win: number;
status: string;
created_at: string;
}
interface TradeResult {
type: string;
commitment_hash: string;
market_id: string;
outcome: "YES" | "NO";
amount_sol: number;
tokens: number;
tx_signature: string;
created_at: string;
}
interface HealthResult {
status: "ok";
version: string;
network: string;
uptime: number;
market_count: number;
}
interface EndpointInfoResult {
name: string;
description: string;
endpoints: {
path: string;
method: string;
price_usd: string;
description: string;
}[];
network: string;
payment_token: string;
}Error Handling
Use standard fetch error handling. The @x402/fetch wrapper throws on network errors and payment failures:
Error handling
try {
const res = await x402Fetch(`${API}/api/v1/markets/create`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
token_mint: "DfnxGQUsXdDH7DYdroeeSBG8etqTy1kufxBikHwTTGTa",
question: "Will SOL reach $1000?",
market_name: "SOL 1000",
slug: "sol-1000",
category: "crypto",
end_date: Math.floor(new Date("2027-01-01").getTime() / 1000),
}),
});
if (!res.ok) {
// API returned an error (400, 404, 409, 429, etc.)
const error = await res.json();
console.error("API error:", res.status, error);
return;
}
const { data } = await res.json();
console.log("Market created:", data.market_id);
} catch (error) {
// Network error or x402 payment failure (insufficient USDC, etc.)
console.error("Request failed:", error);
}