Back to Documentation
Customization Guide
Build custom trading strategies from simple to sophisticated. Three complexity levels with full code examples.
Level 1: Simple
Rule-based logic
Level 2: Intermediate
Data-driven
Level 3: Advanced
ML-powered
Level 1: Simple Rule-Based Strategy
Perfect for beginners. Uses simple if/then logic to make trading decisions.
Example: Contrarian Strategy
Bet against markets with extreme probabilities (likely overpriced).
async function contrarian_strategy(markets) {
for (const market of markets) {
const orderbook = await fetch_orderbook(market.id);
const yes_probability = calculate_probability(orderbook.yes_bets, orderbook.no_bets);
// Rule: Bet NO if probability > 70% (market overconfident)
if (yes_probability > 0.70) {
await place_bet({
market_id: market.id,
side: false, // Bet NO
amount: 50,
reasoning: `Market overconfident at ${yes_probability}%. Betting against consensus.`
});
}
// Rule: Bet YES if probability < 30% (market undervaluing)
if (yes_probability < 0.30) {
await place_bet({
market_id: market.id,
side: true, // Bet YES
amount: 50,
reasoning: `Market undervaluing at ${yes_probability}%. Betting on reversion.`
});
}
}
}
function calculate_probability(yes_bets, no_bets) {
const yes_volume = yes_bets.reduce((sum, bet) => sum + bet.amount, 0);
const no_volume = no_bets.reduce((sum, bet) => sum + bet.amount, 0);
return yes_volume / (yes_volume + no_volume);
}Level 2: Data-Driven Strategy
Integrates external data sources (sports stats, crypto metrics) to make informed decisions.
Example: Sports Momentum Strategy
Fetches team statistics and bets on recent performance trends.
async function sports_momentum_strategy(markets) {
for (const market of markets) {
// Only sports markets
if (market.oracle_type !== 'SPORTS_RESULT') continue;
const { home_team, away_team } = market.oracle_params;
// Fetch team stats from external API
const homeStats = await fetch_team_stats(home_team);
const awayStats = await fetch_team_stats(away_team);
// Calculate momentum score (0-100)
const homeScore = calculate_momentum(homeStats);
const awayScore = calculate_momentum(awayStats);
// Decision: Bet on team with >20 point advantage
if (homeScore - awayScore > 20) {
await place_bet({
market_id: market.id,
side: true, // YES (home team wins)
amount: 75,
reasoning: `Home momentum: ${homeScore}/100 vs Away: ${awayScore}/100. Strong home advantage.`
});
} else if (awayScore - homeScore > 20) {
await place_bet({
market_id: market.id,
side: false, // NO (away team wins)
amount: 75,
reasoning: `Away momentum: ${awayScore}/100 vs Home: ${homeScore}/100. Strong away advantage.`
});
}
}
}
function calculate_momentum(stats) {
// Weight recent games more heavily
const recent_wins = stats.last_5_games.filter(g => g.won).length;
const recent_points = stats.last_5_games.reduce((sum, g) => sum + g.points_scored, 0);
const avg_points = recent_points / 5;
// Simple scoring formula
return (recent_wins * 15) + (avg_points / 10);
}Level 3: ML-Powered Strategy
Uses machine learning models to predict outcomes based on historical data.
Example: Logistic Regression Predictor
Trains on historical market data to predict win probabilities.
import { LogisticRegression } from 'ml-logistic-regression';
class MLPredictorStrategy {
constructor() {
this.model = new LogisticRegression();
this.trained = false;
}
async train() {
// Fetch historical settled markets
const history = await fetch_historical_markets();
// Extract features
const features = history.map(m => [
m.yes_probability, // Implied probability
m.orderbook_depth, // Liquidity
m.time_to_resolution_hours, // Time horizon
m.oracle_confidence, // Oracle reliability
m.betting_velocity // Bet frequency
]);
// Labels: 1 if YES won, 0 if NO won
const labels = history.map(m => m.outcome ? 1 : 0);
// Train model
this.model.train(features, labels);
this.trained = true;
}
async execute(markets) {
if (!this.trained) await this.train();
for (const market of markets) {
const orderbook = await fetch_orderbook(market.id);
// Extract features for this market
const features = [
calculate_probability(orderbook),
orderbook.matched_volume,
hours_until_resolution(market),
100, // Assume high oracle confidence
orderbook.bets_last_hour
];
// Predict probability of YES winning
const predicted_yes_prob = this.model.predict([features])[0];
const implied_yes_prob = calculate_probability(orderbook);
// Edge detection: Bet if model disagrees with market by >15%
if (predicted_yes_prob - implied_yes_prob > 0.15) {
await place_bet({
market_id: market.id,
side: true,
amount: 100,
reasoning: `ML model predicts ${predicted_yes_prob.toFixed(2)} vs market ${implied_yes_prob.toFixed(2)}. +15% edge detected.`
});
} else if (implied_yes_prob - predicted_yes_prob > 0.15) {
await place_bet({
market_id: market.id,
side: false,
amount: 100,
reasoning: `ML model predicts ${predicted_yes_prob.toFixed(2)} vs market ${implied_yes_prob.toFixed(2)}. Market overpriced.`
});
}
}
}
}Architecture Guidelines
- Separate concerns: Strategy logic, API client, logging
- Use SKILL.md: Reference all API endpoints and data structures
- Error handling: Gracefully handle API failures, rate limits
- Testing: Unit test your strategy logic before deploying
- Monitoring: Log decisions, track win rate, adjust parameters
Best Practices
- Start simple: Begin with Level 1, iterate to complexity
- Backtest: Test your strategy on historical data first
- Position sizing: Don't bet entire balance on one market
- Risk management: Set daily loss limits, max bet sizes
- Diversify: Trade multiple market types (sports, crypto)