glacez-soa-portfolio
Lane: backend · Repo: glacez/glacez-soa-portfolio · Editing rules: Glacez/SOAs/glacez-soa-portfolio/AGENTS.md
The calculation service: positions, distribution and coherence. It answers questions and does not decide anything — its only writes are the order and transfer state a recomputation produces.
Responsibility
| Area | What it means |
|---|---|
| Positions | compute a position from transactions (orders + transfers), including average price, total cost and upl |
| Distribution | split an instrument's holding across the connexions (exchange credentials, wallets) that hold it |
| Records | read spot and earn balance records as an input to distribution |
| Coherence | validate that a transaction set is consistent; returns a result rather than throwing |
| Prices | local caches backed by findata (currencies, close prices, changes, OHLCV) |
It does not own: strategy logic (core), exchange access (worker), market data (findata), the user-facing API (webservice).
Data it reads and writes
- Reads directly:
Credential,Wallet(the connexions a portfolio spans) — a shared-database read, not a Feign call. - Writes:
TransferandOrder(closed-order state), both as the output of a recomputation. Nothing else in the platform's data is portfolio's to mutate.
See Data ownership for the rule behind that split.
Surface
Feign contracts in api/: PositionRequest, DistributionRequest and friends (Java records). Downstream: findata only — close prices, changes, currency lists, all /v2.
There is no security configuration in this service: authorization is webservice's job, and portfolio assumes a trusted in-cluster caller (see Security model).
Snapshots
GET /users/{username}/snapshots/portfolio (and /current) answers in daily buckets of closed days: a bucket is priced by its day's stored close, and a day only has one once it has ended. The day in progress is not a bucket — it is the live point appended from findata's latest closes — so every range ends on the last closed day, a range that lies entirely inside the day in progress answers empty rather than a zeroed bucket, and the current snapshot's change from the start of the day is the delta against the last closed day.
The position history rows (GET /users/{username}/positions/{instrument}/history) follow the same rule: a row is a closed day priced the same way, the day in progress is only the live point on the ranges that reach it, and a range that lies entirely inside it answers empty.
Caching
currencies (5 min), prices (15 s) and changes (10 min) on a per-process ConcurrentMapCacheManager evicted by @Scheduled. A "stale position" report is usually one of these intervals, not a calculation bug — see ADR-005.
Jobs
None of its own: portfolio is computed on demand from webservice. Its caches evict on a timer, and that is the only scheduled work in the service.