Get Variant History
Variants
Get Variant History
Retrieve historical portfolio data for each variant over a specified time window
POST
Get Variant History
Overview
Returns time-series portfolio history for all trading variants, aggregated across all models using each variant. The data is grouped by hour and includes an aggregate view combining all variants. This endpoint is optimized for charting and performance visualization.Request
Input Schema
Time window for historical data retrieval
Example Request
Response
Output Schema
Array of variant history entries, one per variant
Combined portfolio history averaging all variants
Example Response
Data Aggregation
Hourly Bucketing
Raw portfolio snapshots are aggregated into hourly buckets:- Query all
portfolioSizerecords within the time window for each variant’s models - Group timestamps by hour (truncate to
YYYY-MM-DDTHH:00:00.000Z) - Average all
netPortfoliovalues within each hour bucket - Sort by timestamp ascending
Multi-Model Aggregation
For variants with multiple models:- All models using the variant are identified via
models.variant = ? - Portfolio values are averaged across models at each timestamp
- This provides a representative “average model” view per variant
Aggregate Calculation
Theaggregate array combines all variants:
- Collect all unique timestamps across all variants
- For each timestamp, average the values from all variants that have data
- This creates an “index” representing the overall platform performance
Empty History Handling
If a variant has no models or no portfolio data:- The variant is included in the response
historyis an empty array[]- This allows UI to display “No data” states per variant
Usage
Performance Optimization
Database Queries
- Index on
("createdAt", "modelId")for fast filtering - Parallel execution via
Promise.all() - Early filtering at database level (not in-memory)
Time Window Performance
| Window | Approx Rows | Query Time | Response Size |
|---|---|---|---|
| 24h | ~100-500 | 50-100ms | ~20KB |
| 7d | ~700-3500 | 150-300ms | ~140KB |
| 30d | ~3000-15000 | 500-1000ms | ~600KB |
Caching Strategy
- Cache
30ddata for longer (historical data rarely changes) - Shorter
staleTimefor24hwindow (more recent = more volatile) - Use SSE to invalidate cache on new portfolio snapshots
Data Interpretation
Portfolio Value
Portfolio Value
Source: Snapshot frequency: Varies by activity
portfolioSize.netPortfolio from databaseCalculation:- During active trading: Every minute
- Idle periods: Hourly scheduled snapshots
Aggregate Index
Aggregate Index
Purpose: Platform-wide performance benchmarkCalculation: Average of all variant values at each timestampUse cases:
- Compare individual variants against overall performance
- Identify outperforming/underperforming strategies
- Visualize strategy diversification benefit
Missing Data Points
Missing Data Points
Causes:
- Variant has no active models
- Models were created after the time window start
- Data retention policy deleted old records
- Empty history arrays for variants with no data
- Aggregate only includes timestamps with at least one variant’s data
- UI should gracefully handle gaps in time series
Related Endpoints
Get Variants
List all available variants and their configurations
Get Variant Stats
View aggregated performance statistics per variant
Best Practices
Time Zones: All timestamps are in UTC (ISO 8601 format). Convert to local time zones in the UI:
Monitoring
The endpoint is tracked via Sentry:- Span duration (target: < 500ms for 7d window)
- Database query count (should equal 2 × number of variants)
- Response payload size (monitor for > 1MB responses)

