Skip to content

feat(cqrs): add projected position read model#122

Merged
blackms merged 1 commit into
mainfrom
codex/projected-position-read-model
Apr 26, 2026
Merged

feat(cqrs): add projected position read model#122
blackms merged 1 commit into
mainfrom
codex/projected-position-read-model

Conversation

@blackms

@blackms blackms commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a durable JSON-backed position read model projected from position domain events.
  • Moves position query handlers to the read-side IPositionReadModel port instead of the write-side repository.
  • Enriches PositionPartiallyClosed events with exact remaining state so partial-close projections stay consistent with the aggregate.

Acceptance Criteria

  • Given a position event, when it is dispatched, then it updates a persistent projection.
  • Given position queries, when they are handled, then they read from the read model and not IPositionRepository.
  • Given a restart, when the read model file exists, then queries reload projected state.

Changes

  • IPositionReadModel and PositionReadModelEntry define the application read-side port.
  • JsonPositionReadModel persists active/closed position projections and handles open, DCA, partial-close, and close events.
  • PositionReadModelProjectionHandler wires domain events into the projection writer.
  • Position query handlers now map projected read-model entries and still resolve live prices through IExchangePort for active positions.
  • PositionPartiallyClosed carries remaining cost, fees, average price, and entry count for exact projection after FIFO reductions.

Testing

  • Added/updated Application query handler tests for read-model-backed position queries.
  • Added Infrastructure projection tests for open+DCA persistence, partial close exactness, and closed-position filtering.
  • Added Domain test for partial-close event remaining-state snapshot.
  • Verified with dotnet test IntelliTrader.sln --no-restore.

Checklist

  • Tests pass
  • Coverage maintained
  • Linter clean
  • Documentation updated (not user-facing)

@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@blackms has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 54 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 39 minutes and 54 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 27c7765b-fad2-459d-8bf9-83ccaf2b0808

📥 Commits

Reviewing files that changed from the base of the PR and between 0d7bdec and ad26997.

📒 Files selected for processing (13)
  • IntelliTrader.Application/Ports/Driven/IPositionReadModel.cs
  • IntelliTrader.Application/Trading/Handlers/PositionQueryHandlers.cs
  • IntelliTrader.Domain/Trading/Aggregates/Position/Position.cs
  • IntelliTrader.Domain/Trading/Events/PositionPartiallyClosed.cs
  • IntelliTrader.Infrastructure/Adapters/Persistence/ReadModels/IPositionReadModelProjectionWriter.cs
  • IntelliTrader.Infrastructure/Adapters/Persistence/ReadModels/JsonPositionReadModel.cs
  • IntelliTrader.Infrastructure/Adapters/Persistence/ReadModels/PositionReadModelProjectionHandler.cs
  • IntelliTrader.Infrastructure/AppModule.cs
  • tests/IntelliTrader.Application.Tests/Trading/Handlers/PositionQueryHandlerTests.cs
  • tests/IntelliTrader.Application.Tests/Trading/Handlers/PositionReadModelQueryHandlerTests.cs
  • tests/IntelliTrader.Domain.Tests/Trading/Aggregates/PositionTests.cs
  • tests/IntelliTrader.Infrastructure.Tests/Adapters/Persistence/PositionReadModelProjectionTests.cs
  • tests/IntelliTrader.Infrastructure.Tests/Integration/InfrastructureTestFixture.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/projected-position-read-model

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@blackms blackms merged commit 77865a8 into main Apr 26, 2026
2 checks passed
@blackms blackms deleted the codex/projected-position-read-model branch April 26, 2026 21:20
@codecov

codecov Bot commented Apr 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.92090% with 64 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rs/Persistence/ReadModels/JsonPositionReadModel.cs 79.93% 35 Missing and 23 partials ⚠️
...lication/Trading/Handlers/PositionQueryHandlers.cs 80.95% 0 Missing and 4 partials ⚠️
...e/ReadModels/PositionReadModelProjectionHandler.cs 85.71% 0 Missing and 1 partial ⚠️
IntelliTrader.Infrastructure/AppModule.cs 83.33% 1 Missing ⚠️
Files with missing lines Coverage Δ
...der.Application/Ports/Driven/IPositionReadModel.cs 100.00% <100.00%> (ø)
...der.Domain/Trading/Aggregates/Position/Position.cs 91.48% <100.00%> (+1.56%) ⬆️
...r.Domain/Trading/Events/PositionPartiallyClosed.cs 86.00% <100.00%> (+17.57%) ⬆️
...e/ReadModels/PositionReadModelProjectionHandler.cs 85.71% <85.71%> (ø)
IntelliTrader.Infrastructure/AppModule.cs 87.91% <83.33%> (-0.20%) ⬇️
...lication/Trading/Handlers/PositionQueryHandlers.cs 89.81% <80.95%> (+0.09%) ⬆️
...rs/Persistence/ReadModels/JsonPositionReadModel.cs 79.93% <79.93%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant