Skip to content

The Factory Layer

glacez-lib-factory is where Glacez decides and where Glacez values. It is a deterministic core: plain domain objects in, plain domain objects out. No database, no HTTP, no scheduler, no Spring bean, no log of its own beyond diagnostics.

The services bring the data. The factories decide what a transaction means, what a strategy does next and what a portfolio is worth. The services then persist or display the result.

Two directions, one module

Direction What it does Entry points
Deciding Replays transactions into positions, evaluates strategy conditions, generates the orders a strategy fires PositionsFactory, TransactionsFromActionFactory, ScalpTransactionsFactory, ClosePositionTransactionsFactory, the condition evaluators, the template factories
Valuing Attaches prices to positions, derives cost basis, market value, ROI, UGL and weights, and aggregates them into snapshots PricesProcessor, DistributionProcessor, PortfolioSnapshotFactory, ConnexionSnapshotFactory, StrategySnapshotFactory, ConnexionBalanceFactory

Map

Class Computes Consumed by
PositionsFactory (+ OrderProcessor, TransferProcessor) The full position ledger: replays every transaction onto a requested time grid, producing total quantity, average price and realized gains per instrument per timestamp portfolio (positions, history, coherence), core and webservice (coherence fixtures)
PricesProcessor Valuation of a position at a price point: cost basis, market value, ROI, UGL; also attaches market changes portfolio snapshots, position service
DistributionProcessor Weight of each position inside the portfolio, per quote portfolio
PortfolioSnapshotFactory Aggregates positions into an end-of-period portfolio snapshot (market value, cost basis, UPL, ROI, distributions) portfolio
ConnexionSnapshotFactory Same aggregation per connexion (exchange account or wallet) webservice
StrategySnapshotFactory Strategy-level snapshot: what the strategy holds and how it performs webservice
ConnexionBalanceFactory Balances per connexion portfolio
TransactionsFromActionFactory (+ ScalpTransactionsFactory, ClosePositionTransactionsFactory) Reads a strategy action with its conditions and produces the order it should place now core
Condition evaluators (orders/evaluator) One class per condition type: price, delta date, EMA, SMA, halving window, change from ATH, currency price change, strategy price change, position ROI, max to buy, max to sell, action executed, action transactions status, orders status called from TransactionsFromActionFactory
ScalpFactory, DcaTemplateFactory, ClosePositionTemplateFactory Builds a Strategy with its Actions from a template webservice (strategy creation)
SimulationsFactory Replays a strategy over historical prices and produces simulated transactions and snapshots simulator
EventFactory Builds the events a strategy or portfolio raises core, worker
CredentialRecordsSynchronizer, WalletRecordsSynchronizer Maps venue payload (exchange records, chain records) into domain transactions core
DepositsFactory Stabilises an imported transaction list: when a transaction would overdraw a position, it generates the missing deposit before it core (inside both synchronizers)

DepositsFactory is the reason an imported history that starts mid-life does not blow up: venues return trades without the funding that preceded them, so the replay creates AUTO_GENERATED deposits to cover each deficit and re-runs until the list is coherent.

Its inputs come from elsewhere

The factories never compute these themselves:

Input Owner
Transactions (orders, transfers) core (venue sync, manual entry)
Prices per instrument per timestamp findata (closes, crosses) and core (latest point)
Market changes (1h, 24h, 7d...) findata
All-time highs findata
EMA and SMA levels per period findata (MovingAverageService), fetched by core for evaluation
Halving schedule findata
The time grid (which timestamps to compute) the caller, per request or per job

That split is deliberate: the factories take the time grid as a parameter instead of deciding it, so the same replay serves a one-day dashboard request and a multi-year history job.

Where the layer stops

  • No I/O of any kind. No repository, no client, no cache.
  • No persistence mapping. The position, snapshot and strategy objects are consumed by the owning service, which decides what to store.
  • No indicator maths. EMA, SMA, changes and ATHs arrive as values; the evaluators only compare them against the thresholds the user set.
  • No arithmetic substrate of its own. All quote math is QuotedValue in glacez-lib-model: four quotes (EUR, BTC, ETH, USD), values normalized to scale 32 and precision 34, isValid() meaning all four quotes positive.

Why the boundary matters

A business rule that lives here is released with the library, not with a service: master builds 0-SNAPSHOT, so a merged change reaches production only after a release/X.Y release plus every consumer's version bump. That is the price of one shared definition of a position and a portfolio, and it is the reason a rule change in this module is a wiki change too.

Related: