Architecture
Process shape
/api/v1/agent/* — hit the same service layer. The agent doesn’t have two code paths to keep in sync.
What the agent does NOT do
Strategy evaluation happens insidemangroveai.execution.evaluate(). The agent does not:
- Re-implement signal logic.
- Re-implement risk gates.
- Re-implement position sizing.
- Re-implement cooldowns.
OrderIntent[] to the executor → log.
This is deliberate. If signal semantics changed locally vs. on the platform, paper backtests and live results would diverge. By keeping evaluation upstream, what passes backtest is what runs in live execution.
Cron path
APScheduler runs in-process with a SQLite jobstore so jobs survive restarts. When a strategy is promoted topaper or live, the executor registers a job on the strategy’s timeframe:
Live trade path
Forlive strategies the agent decrypts the wallet’s secret in-process, signs the unsigned transaction returned by mangrovemarkets, broadcasts the signed bytes, and zeroes the secret. The SDK is never given the key — see the safety model for the full contract.
Storage
| What | Where |
|---|---|
| Strategies, evaluations, trades, positions | ./agent-data/agent.db (SQLite) |
| Encrypted wallet secrets | agent.db wallets table |
| Fernet master key (bare-metal) | OS keychain via keyring |
| Fernet master key (Docker) | ./agent-data/master.key (chmod 600, gitignored) |
| Setup state | ./agent-data/ directory |
Project layout
Extending
Adding a new endpoint, MCP tool, signal, or strategy follows the service-layer pattern. The repo’sdocs/contributing.md has the checklist; the trading-bot-specific skills (/create-strategy, /backtest, /custom-signal, /audit-security, /check-alignment, /tool-spec) live in .claude/skills/.