Implementation Plan: YU08-execution-algo-engine
Goalβ
Add an execution algo engine that slices a parent order into TWAP (time-weighted) or VWAP (volume-weighted) child orders, submits every child through the existing order-entry and risk-gateway path unchanged, and event-sources its own schedule/fill state so a crash resumes from its log.
Workstreamsβ
- New component:
execution-algo-engine- Java 21, Spring Boot (same shape as
account-service/trade-processor),io.nats:jnatsfor NATS pub/sub and JetStream,org.duckdb:duckdb_jdbcfor the VWAP volume-profile query. AlgoOrderService: parent-order creation, TWAP/VWAP bucket scheduling, progress queries.AlgoScheduler:@Scheduledloop submitting due buckets toorder-matcher'sPOST /orders.OrderUpdateSubscriber:/accounts/*/ordersbroadcast subscriber correlating fills byorderId.AlgoEventStore: JetStream-backed append log + durable-consumer replay for crash recovery.VolumeProfileSource:SyntheticVolumeProfileSource(default) andDuckDbVolumeProfileSource.
- Java 21, Spring Boot (same shape as
- Packaging
- Dockerfile, k8s Deployment + Service (
kubernetes-runtimeoverlay), generation hook + render script,scripts/{start,stop,status,test}-state-YU08-execution-algo-engine*.sh.
- Dockerfile, k8s Deployment + Service (
- Validation
- Unit tests: TWAP bucket math, VWAP weighting + synthetic fallback, event-store replay
rebuilding in-memory state, order-update correlation by
orderId. - End-to-end: TWAP parent order run against a local kind cluster (
run-state-kind), children observed accepted byorder-matcher, progress visible via the status endpoint. bench-compareagainst theYU07-historical-tick-storebaseline (mandatory; children flow through the same order-submission path as every other order).
- Unit tests: TWAP bucket math, VWAP weighting + synthetic fallback, event-store replay
rebuilding in-memory state, order-update correlation by
Key decisionsβ
- Separate warm-path Spring Boot service, not a BLP feature; see
research.mdDecision 1. - Children submit through
order-matcher's existingPOST /orders, no bypass; Decision 2. - Child limit price: last price Β± 10bps aggressive offset; Decision 3.
- Own state event-sourced over a new JetStream stream (
TRADERX_ALGO_ENGINE), reusing the existingio.nats:jnatsclient and stream-bootstrap idiom from YU04; Decision 4. - Fill tracking via the existing
/accounts/*/ordersbroadcast subject, correlated byorderId; Decision 5. - TWAP: equal-quantity time buckets, default 10s bucket; Decision 6.
- VWAP: pluggable volume-profile source, synthetic default with automatic DuckDB fallback; Decision 7.
- REST-only parent-order ingress (
POST /algo/orders), no front-end panel; Decision 8.
Exit Criteriaβ
- Spec and tasks are complete and reviewed.
- Generation hook produces expected artifacts and exits successfully.
- Unit tests pass for TWAP/VWAP scheduling, event-store replay, and order-update correlation.
- A TWAP parent order run end to end on kind produces accepted child orders and visible progress.
bench-compareshows no regression against theYU07-historical-tick-storebaseline.- Generated shared file (
kustomization.yaml) retains every ancestor state's content alongside this state's two additions. - State can be published to
code/generated-state-YU08-execution-algo-engine.