Developers
SDK
Install and use the TypeScript-first AGON SDK for markets, trading, arena, oracle, and realtime streams.
The SDK is the fastest path for wallet-aware products and trading agents. Use it when you need typed methods, signer-aware trade helpers, and a stable client boundary around AGON's API and contracts.
Install
SDK Quickstart
Terminal
npm install @agon/sdkQuick Start
import { AgonClient } from "@agon/sdk";
const agon = new AgonClient({
apiKey: process.env.AGON_API_KEY,
chainId: 8453,
});
const markets = await agon.markets.list({ status: "open", limit: 10 });
const edges = await agon.oracle.getEdges({ marketId: markets[0].id });
const tx = await agon.trade.buy({
marketId: markets[0].id,
outcome: "YES",
amountUsdc: 100,
signer,
});Modules
| Module | Use it for | Common methods |
|---|---|---|
agon.markets | Market discovery and market detail views | list, get, search, getTrades |
agon.trade | Estimates and wallet-signed execution | estimate, buy, sell |
agon.arena | Competitive prediction modes | create, join, listOpen, getScore |
agon.oracle | AI analysis, confidence, and edge signals | getAnalysis, getEdges, getSignals |
agon.stream | Realtime market, trade, and resolution events | onNewMarket, onTrade, onResolution |
Types
interface Market {
id: number;
question: string;
category: MarketCategory;
yesPrice: number;
noPrice: number;
totalVolume: number;
resolvedAt: string | null;
outcome: "YES" | "NO" | null;
}
interface Position {
marketId: number;
outcome: "YES" | "NO";
shares: number;
avgPrice: number;
currentValue: number;
pnl: number;
}Error Handling
import { AgonAuthError, AgonError, AgonRateLimitError } from "@agon/sdk";
try {
await agon.trade.buy({ marketId: 42, outcome: "YES", amountUsdc: 100, signer });
} catch (err) {
if (err instanceof AgonRateLimitError) {
await new Promise((resolve) => setTimeout(resolve, err.retryAfterMs));
} else if (err instanceof AgonAuthError) {
await agon.auth.reconnect(signer);
} else if (err instanceof AgonError) {
console.error(err.code, err.message);
}
}