Skip to main content
POST
Get Variant Stats

Overview

Returns comprehensive performance statistics for all trading variants, aggregated across all models using each variant. This endpoint calculates win rates, P&L metrics, and model counts by analyzing closed orders and active models.

Request

Input Schema

This endpoint automatically aggregates statistics for all variants.

Response

Output Schema

array
required
Array of variant statistics objects

Example Response

Statistics Calculations

Aggregation Logic

For each variant, the endpoint:
  1. Finds all models using the variant (SELECT * FROM "Models" WHERE variant = ?)
  2. Retrieves closed orders for those models (WHERE status = 'CLOSED' AND modelId IN (...))
  3. Calculates metrics from the order data:
    • totalTrades: Count of closed orders
    • winRate: (wins / totalTrades) * 100 where wins = orders with realizedPnl > 0
    • totalPnl: Sum of all realizedPnl values
    • avgPnl: totalPnl / totalTrades
    • modelCount: Count of active models

Zero-Value Handling

If no models exist for a variant:
  • All numeric fields return 0
  • The variant is still included in the response for completeness

Performance Considerations

  • Uses database indexes on models.variant and orders.status
  • Runs parallel queries for all variants using Promise.all()
  • SQL array operations (ANY(modelIds)) for efficient filtering

Usage

Performance Metrics

Database Queries

  • Per variant: 2 queries (models lookup + orders aggregation)
  • Total queries: 2 × number of variants (currently 8 queries)
  • Execution: Parallel via Promise.all()
  • Average latency: 50-150ms depending on order volume

Indexes Used

Monitoring

The endpoint is wrapped in a Sentry performance span:

Understanding the Metrics

Definition: Percentage of trades that closed with positive P&LCalculation: (winning_trades / total_trades) × 100Interpretation:
  • > 55%: Strong performance
  • 50-55%: Moderate performance
  • < 50%: Underperforming
Note: Win rate alone doesn’t indicate profitability. A 40% win rate with high R:R can be more profitable than 60% with low R:R.
Definition: Mean profit/loss per closed tradeCalculation: total_pnl / total_tradesInterpretation:
  • > 0: Profitable on average
  • < 0: Losing on average
  • Magnitude indicates risk-adjusted returns
Use case: Compare avgPnl across variants to identify most efficient strategies
Definition: Number of active models currently using the variantNote: This is a snapshot count, not historical. Models can be:
  • Actively trading (status = ACTIVE)
  • Paused (status = PAUSED)
  • Any status except DELETED
Use case: Gauge variant adoption and allocation

Get Variants

List all available variants and their configurations

Get Variant History

View historical portfolio performance per variant

Best Practices

Statistics are calculated on-demand and can be expensive for large datasets. Consider:
  • Implementing server-side caching with TTL
  • Using SSE subscriptions for real-time updates
  • Pre-aggregating stats in a materialized view
For dashboards displaying multiple metrics, fetch all variant data in a single batch: