Prediction Markets
BetaThis example demonstrates how to query prediction markets to discover trending markets, view odds, and understand market data.
The Code
import {
Chaos,
WALLET_MODEL,
extractText,
extractBlocks,
isTableBlock,
isTransactionActionBlock,
type Response,
type RequestMetadata,
} from '@chaoslabs/ai-sdk';
const config = {
apiKey: process.env.CHAOS_STAGING_API_KEY || 'your-api-key',
baseUrl: process.env.CHAOS_STAGING_URL || 'https://ai-staging.chaoslabs.co',
};
const walletConfig: RequestMetadata = {
user_id: 'example-user',
session_id: `example-session-${Date.now()}`,
wallet_id: process.env.TEST_PORTFOLIO_ID || '0x...',
};
async function main() {
const chaos = new Chaos({
apiKey: config.apiKey,
baseUrl: config.baseUrl,
timeout: 120000,
});
// Query trending prediction markets
const response = await chaos.chat.responses.create({
model: WALLET_MODEL,
input: [{ type: 'message', role: 'user', content: 'What are the hottest prediction markets right now?' }],
metadata: walletConfig,
});
if (response.status === 'failed') {
console.error('Failed:', response.error);
return;
}
console.log('Agent Response:', extractText(response));
const blocks = extractBlocks(response);
// Display market tables
const tables = blocks.filter(isTableBlock);
for (const table of tables) {
console.log(`\n${table.title}`);
console.log(`Columns: ${table.tableHeaders.join(', ')}`);
for (const row of table.tableRows.slice(0, 5)) {
console.log(` ${row.join(' | ')}`);
}
if (table.tableRows.length > 5) {
console.log(` ... and ${table.tableRows.length - 5} more markets`);
}
}
}
main();Common Prediction Market Queries
The AI understands various prediction market queries:
Trending Markets
- "What are the hottest prediction markets right now?"
- "Show me the highest volume markets"
- "What's trending on Polymarket?"
Crypto Predictions
- "Show me prediction markets for crypto prices"
- "Bitcoin price predictions"
- "Will ETH hit $5000?"
Category-Specific
- "Sports prediction markets"
- "Political prediction markets"
- "Crypto prediction markets"
Understanding Market Data
Prediction market responses include key metrics:
| Metric | Description |
|---|---|
| 24h Volume | Trading volume in the last 24 hours |
| Total Volume | All-time trading volume |
| Liquidity | Available liquidity in the market |
| Odds/Probability | Current implied probability |
const tables = blocks.filter(isTableBlock);
for (const table of tables) {
// Typical headers: Market Question, 24h Volume, Total Volume, Liquidity
const headers = table.tableHeaders;
// Find column indices
const questionIdx = headers.findIndex(h => h.includes('Market') || h.includes('Question'));
const volumeIdx = headers.findIndex(h => h.includes('24h'));
const totalIdx = headers.findIndex(h => h.includes('Total'));
console.log('Top Markets by Volume:');
for (const row of table.tableRows.slice(0, 5)) {
console.log(` ${row[questionIdx]}`);
console.log(` 24h: ${row[volumeIdx]} | Total: ${row[totalIdx]}`);
}
}Example Response
A typical response for trending markets includes:
Table: Top Prediction Markets by Volume
Columns: Market Question, 24h Volume, Total Volume, Liquidity
Super Bowl Champion 2026 | $983.1K | $688.3M | $5.0M
Democratic Presidential Nominee | $5.1M | $526.3M | $23.2M
Fed decision in January? | $12.9M | $477.0M | $15.4M
Bitcoin above $110k on Jan 31? | $2.8M | $57.8M | $2.7MSupported Platforms
The Chaos AI aggregates data from major prediction market platforms:
| Platform | Status | Description |
|---|---|---|
| Polymarket | ✓ Supported | Largest crypto prediction market |
| Kalshi | Planned | CFTC-regulated prediction exchange |
| Manifold | Planned | Play-money prediction markets |
Next Steps
- Explore perpetuals trading
- Review error handling for production code