alt/agent-ops/rules/project/domain/domain-model/rules.md

4.3 KiB

domain last_rule_review_commit last_rule_updated_at
domain-model 704f1eb232 2026-06-24

domain-model

목적 / 책임

ALT의 핵심 business vocabulary를 Go 타입으로 표현한다. Market, instrument, price, bar, backtest run, strategy, portfolio state, paper account, live trading account/order/risk/audit, and analysis result concepts stay transport- and storage-free here.

포함 경로

  • packages/domain/ - shared Go domain model module
  • packages/domain/market/ - market, venue, currency, instrument, OHLCV bar types
  • packages/domain/backtest/ - backtest run spec, run state, result types
  • packages/domain/trading/ - broker-neutral live trading account, order, risk, capability, and audit types

제외 경로

  • packages/contracts/ - external protobuf schema representation
  • services/api/ - socket transport and API boundary
  • services/worker/ - execution and scheduled job boundary

주요 구성 요소

  • market.Instrument - tradable instrument identity and provider symbol mapping
  • market.AssetType and market.VenueMetadata - venue/market/currency metadata for KR and US market data
  • market.UniverseSelector - provider import universe vocabulary
  • market.ProviderCapability and market.ProviderCapabilityRule - provider/venue/asset type/timeframe capability matrix
  • market.Bar - timeframe OHLCV market data point
  • backtest.RunSpec - strategy, market, timeframe, period inputs for a run
  • backtest.InputSelector - optional instrument/symbol selector for backtest bar source filtering
  • backtest.Run - backtest lifecycle state
  • backtest.Result - backtest financial summary, trades, positions, summary metrics, and equity curve
  • backtest.Strategy, backtest.StrategyInput, backtest.OrderIntent - strategy execution vocabulary
  • backtest.PortfolioState, backtest.Fill, backtest.Position - portfolio accounting state and fill application
  • backtest.PaperAccount, backtest.RiskSettings, backtest.CheckRisk, and backtest.FillOrderOnDailyBar - paper trading simulation vocabulary and daily OHLC fill semantics
  • backtest.TotalReturn - decimal return calculation helper backed by rational arithmetic
  • trading.OrderIntent, trading.AccountSnapshot, trading.PositionSnapshot, and trading.BrokerCapability - broker-neutral live trading vocabulary
  • trading.RiskPolicy, trading.KillSwitchState, trading.EvaluateRisk - live risk and kill switch decision vocabulary
  • trading.AuditEvent, trading.AuditFilter, trading.HasRawSecretKey - sanitized live operation audit vocabulary

유지할 패턴

  • Domain type names should stay concise and market-neutral unless a market-specific rule is unavoidable.
  • Decimal values are represented as strings through market.Decimal; avoid float types for prices and quantities.
  • Portfolio and return calculations use exact decimal/rational conversion, not floating point arithmetic.
  • Keep package dependencies inward: domain packages should not import API, worker, CLI, Flutter, protobuf generated code, database drivers, or proto-socket.
  • Keep provider and broker vocabularies open string types where external systems may introduce new values.
  • Treat account IDs in trading as operator aliases or internal identifiers; raw broker account numbers, tokens, and provider bodies must be stripped before domain objects are created.
  • Keep provider capability decisions in domain-model, while provider-specific fetch/auth behavior remains in worker adapters.

다른 도메인과의 경계

  • contracts: domain-model owns internal Go vocabulary; contracts owns protobuf wire schema and compatibility.
  • worker: domain-model defines the shapes; worker executes imports, normalization, backtests, paper/live trading, persistence, provider calls, scheduler work, and socket mapping.
  • api: domain-model may be mapped to responses, but API transport details stay outside this module.

금지 사항

  • Do not add persistence annotations, socket parser logic, or environment configuration here.
  • Do not introduce generated protobuf code into this package.
  • Do not use float32 or float64 for money, price, or quantity values.
  • Do not store raw account numbers, access tokens, app secrets, authorization headers, or raw external provider payloads in domain objects or audit payloads.