Workspace Structure

Understand every file and folder in your Blave Agent workspace.

Directory Overview

workspace/
├── strategies/          # your strategies
├── examples/            # reference implementations
├── lib/                 # shared library
├── manager/             # portfolio management system
├── cache/               # API data cache (auto-generated)
├── references/          # guides for strategy code & deployment
└── AGENTS.md            # bot behavior rules

strategies/

Each strategy lives in its own subfolder. The bot runs strategy.py on a cron schedule and writes the output files automatically.

strategies/
└── my_strategy/
    ├── strategy.py      # strategy logic
    ├── scan.py          # parameter scan (optional)
    ├── stats.json       # backtest results + daily returns
    ├── state.json       # live position state
    ├── pnl.png          # equity curve chart
    └── orders.jsonl     # order log

lib/

All shared utilities live in lib/. Import from here — never duplicate code in strategy files.

FilePurpose
runner.pyUnified backtest & live runner (Type A and C)
data.pyAll data fetchers — kline, alpha indicators, Taiwan stocks, futures
execute.pyLive state management: load/save/update position, order log
pnl.pyWrite daily returns to stats.json; load all strategies for manager
portfolio.pyAggregate target positions, compute order diff, reconcile
strategy.pyVol targeting helpers: add_realized_vol, apply_vol_scaling
analysis.pyPnL charts, regime analysis, slippage, random B&H benchmark
param_scan.py2D parameter scan: percentile_thresholds, scan_grid, find_plateau, plot_heatmap
validation.pyMonte Carlo Permutation Test (mcpt) for statistical significance
notify.pyTelegram sender: make_sender(), send_text(), send_photo()

manager/

The manager/ folder handles multi-strategy portfolio optimization and order reconciliation. Do not delete any file here when removing individual strategies.

FilePurpose
manager.pyReads all strategies' stats.json, finds weights that maximize portfolio slope/std, writes optimal weights + leverage to portfolio_config.json.
Run: python3 manager/manager.py --target-vol 0.30
reconciler.pyPolls every 5 s; reconciles when a strategy's state.json, the amounts, or the kill switch changes (plus a 5-minute safety pass), then places orders to close the gap between target and actual positions.
Run: bash manager/start_reconciler.sh
flatten.pyMarket-closes every open position on every connected exchange (the workspace Close-all button runs this). Trips the kill switch first so nothing re-opens.
Run: python3 manager/flatten.py
portfolio_config.jsonPer-strategy dollar amounts (the live sizing base), exchange routing, and the optimizer's weights and leverage. Maintained by the tools — never edit by hand.
orders.jsonlOrder history — one line per executed order, with per-leg exchange-confirmed fill price and quantity. Rendered as Order History in the workspace.
Amounts vs weights: the optimizer's weights and leverage are a suggested allocation; what actually sizes live positions is each strategy's dollar amount (target = amount × position), saved from the workspace Trading setup page.

Data Flow

strategy.py ──► state.json ──────────┐
   (cron)       stats.json           ├──► reconciler.py ──► exchange
manager.py ──► portfolio_config.json ┘

The reconciler needs both sources to compute order size: target = amount × position