Implementation:HKUDS AI Trader Generate Cache For Market
| Knowledge Sources | |
|---|---|
| Domains | Web_Development, Data_Pipeline |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
Concrete tool for generating static JSON cache files from trading results for the web dashboard.
Description
The generate_cache_for_market function processes a market configuration, loads portfolio values and position data for each agent, computes a version hash, and writes a structured JSON cache file to docs/data/{market_id}_cache.json. The cache contains agent performance data, portfolio time series, and metadata needed by the frontend JavaScript modules.
The companion main() function iterates over all markets in the YAML config and calls generate_cache_for_market for each.
Usage
Run scripts/precompute_frontend_cache.py after backtesting completes to update the dashboard cache. Can also be run via scripts/regenerate_cache.sh for automated cache regeneration.
Code Reference
Source Location
- Repository: AI-Trader
- File: scripts/precompute_frontend_cache.py
- Lines: L618-684 (generate_cache_for_market), L687-715 (main)
Signature
def generate_cache_for_market(market_id, market_config, config):
"""
Generate a pre-computed JSON cache for one market.
Args:
market_id: Market identifier (e.g., "us", "cn")
market_config: Market-specific configuration dict
config: Full application config dict
Returns:
dict: The generated cache object
"""
def main():
"""Load config and generate caches for all configured markets."""
Import
# Run as script:
# python scripts/precompute_frontend_cache.py
# Or via shell:
# bash scripts/regenerate_cache.sh
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| market_id | str | Yes | Market identifier (e.g., "us", "cn") |
| market_config | dict | Yes | Market configuration from YAML |
| config | dict | Yes | Full application config |
| docs/config.yaml | File | Yes | Dashboard configuration file |
Outputs
| Name | Type | Description |
|---|---|---|
| docs/data/{market_id}_cache.json | File | Pre-computed dashboard cache with agent data, portfolio values, and metrics |
Usage Examples
Generate All Caches
# From repository root:
python scripts/precompute_frontend_cache.py
# Or use the regeneration script:
bash scripts/regenerate_cache.sh