Load trader V4 artifacts from manifests

This commit is contained in:
Codex
2026-06-26 22:07:43 +08:00
parent 6bbedda97d
commit 4e5f49d6fe
11 changed files with 598 additions and 151 deletions
+49 -42
View File
@@ -1,65 +1,72 @@
# quant-trader-service
Clean P0 rebuild of the Trader-style strategy service.
Trader V4 P0 decision service.
## Scope
This implementation follows the desktop design documents in
`/Users/zach/Desktop/app/trader`:
The service follows the V4 Trader documents under `/Users/zach/Desktop/app/trader`.
P0 only allows `REPLAY_SIM` and `SHADOW`; `PAPER`, `REAL`, real fills, and old
strategy-service contracts are rejected.
- `00-操盘手Trader新策略服务概要设计-20260622.md`
- `03-Trader服务详细设计说明书-20260623.md`
## Implemented Surface
P0 keeps the service in replay/shadow preparation mode:
- Spring Boot service under `com.quantai.trader`
- strict P0 runtime guard for run mode, execution mode, and trading switch
- JSON artifact loader for model bundle manifest, PM config manifest, and model output policy
- five-model output contract: Direction, Entry, Continue, Exit, Risk
- dynamic PM sizing with side-aware stop/target price calculation
- Risk Gate for hard blockers and forced close decisions
- JDBC persistence for run, cycle, model output, PM decision, risk decision, action, evidence, and outbox
- Flyway V1 schema for the V4 P0 tables
- health, replay-cycle, and feedback endpoints
- JaCoCo line coverage gate at 90%
- no real trading
- no old V3 `latest/promoted` path
- no `SCALE_IN` action surface
- no real App feedback by default
- no model training that can control live size
## Local Database
## Implemented P0 Surface
Default configuration:
- Spring Boot P0 service under `com.quantai.trader`
- Playbook YAML loading, validation, normalized JSON, SHA-256 definition hash
- MySQL 8 Flyway DDL for the P0 trader tables
- Core domain records for cycles, actions, entry plans, risk, evidence, feedback, samples, and reports
- State-machine guardrails for initial entry, planned legs, and management actions
- Dynamic position sizing from signal, execution quality, and risk scores
- Risk gate that records every allow/block decision
- Evidence appender and proxy-only training sample exporter
- Async replay-run registry and report contract
- MyBatis-Plus repositories aligned with `quant-app-server`
- Deterministic JSONL replay fixtures for accepted, rejected, blocked, and hard-fail paths
- Feedback endpoint that returns `TRADER_FEEDBACK_DISABLED` unless explicitly enabled
- Focused unit and MVC tests
```text
jdbc:mysql://127.0.0.1:3306/quant_trader
username: quant_trader
password: quant_trader
```
Override with `TRADER_DB_URL`, `TRADER_DB_USERNAME`, and `TRADER_DB_PASSWORD`.
## Artifact Root
Default artifact root:
```text
/Users/zach/Desktop/quant-strategy-training-data/trader-v4/artifact_bundle
```
Required files:
```text
manifests/model_bundle_manifest.json
manifests/position_manager_manifest.json
model_output_policy.json
```
The loader requires the configured model/calibration/PM version triple to match
the manifests, all five model families to be present, and the model/PM manifests
to be `ACTIVE`.
## Commands
```bash
mvn test
mvn spring-boot:run
mvn clean test
TRADER_DB_USERNAME=quant_trader TRADER_DB_PASSWORD=quant_trader SERVER_PORT=18080 mvn spring-boot:run
```
The service uses MySQL through MyBatis-Plus. Configure the database with
`TRADER_DB_URL`, `TRADER_DB_USERNAME`, and `TRADER_DB_PASSWORD` when the local
defaults are not available.
Replay acceptance fixtures live under `src/test/resources/replay-fixtures`.
They are deterministic P0 contract samples, not a profitability backtest corpus.
## HTTP
```text
GET /api/trader/health
GET /api/trader/playbooks
GET /api/trader/playbooks/{playbookId}
POST /api/trader/replay/runs
GET /api/trader/replay/runs/{runId}
POST /api/trader/replay/runs/{runId}/cancel
GET /api/trader/replay/runs/{runId}/report
POST /api/trader/replay/cycles
POST /api/trader/feedback
```
Remark: `/api/trader/feedback` is intentionally disabled in P0 unless
`trader.integration.http-feedback-enabled=true`.
`/api/trader/feedback` is disabled by default in P0 and still rejects
`PAPER_APP`, `REAL_APP`, and any real fill when explicitly enabled for tests.