feat(cqrs): harden active order refresh#115
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (64)
📝 WalkthroughWalkthroughThis pull request introduces persistent order lifecycle management with transactional support. It adds an Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RefreshHandler as RefreshOrderStatusHandler
participant ExchangePort
participant Factory as ExchangeOrderLifecycleFactory
participant OrderRepo as IOrderRepository
participant PositionRepo as IPositionRepository
participant PortfolioRepo as IPortfolioRepository
participant TxnUOW as ITransactionalUnitOfWork
participant EventDispatcher
Client->>RefreshHandler: HandleAsync(RefreshOrderStatusCommand)
RefreshHandler->>OrderRepo: GetByIdAsync(orderId)
OrderRepo-->>RefreshHandler: OrderLifecycle
RefreshHandler->>ExchangePort: GetOrderAsync(exchangeOrderId)
ExchangePort-->>RefreshHandler: ExchangeOrderInfo
RefreshHandler->>Factory: Refresh(lifecycle, exchangeOrderInfo)
Factory-->>RefreshHandler: bool (changed)
alt Status Changed or Unapplied Fill
RefreshHandler->>TxnUOW: BeginTransactionAsync()
alt Intent == OpenPosition
RefreshHandler->>PositionRepo: GetByPairAsync(pair)
PositionRepo-->>RefreshHandler: Position
RefreshHandler->>RefreshHandler: Create/Update Position
else Intent == ClosePosition
RefreshHandler->>PositionRepo: GetByIdAsync(posId)
PositionRepo-->>RefreshHandler: Position
RefreshHandler->>RefreshHandler: ApplyCloseFillDelta()
else Intent == ExecuteDca
RefreshHandler->>PositionRepo: GetByIdAsync(posId)
PositionRepo-->>RefreshHandler: Position
RefreshHandler->>RefreshHandler: ApplyDCAFillDelta()
end
RefreshHandler->>PortfolioRepo: GetDefaultAsync()
PortfolioRepo-->>RefreshHandler: Portfolio
RefreshHandler->>RefreshHandler: Update Portfolio Balance
RefreshHandler->>OrderRepo: SaveAsync(orderLifecycle)
RefreshHandler->>PositionRepo: SaveAsync(position)
RefreshHandler->>PortfolioRepo: SaveAsync(portfolio)
RefreshHandler->>TxnUOW: CommitAsync()
TxnUOW-->>RefreshHandler: Result
alt Commit Success
RefreshHandler->>EventDispatcher: DispatchAsync(orderEvents + positionEvents)
else Commit Failure
RefreshHandler->>TxnUOW: RollbackAsync()
RefreshHandler-->>Client: Failure(error)
end
end
RefreshHandler-->>Client: RefreshOrderStatusResult
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
|
Summary
Acceptance Criteria
Changes
ActiveOrderRefreshServiceand kept the legacy submitted refresh contract as a compatible alias.InMemoryCommandDispatchertransaction cleanup and exception unwrapping.Testing
dotnet test tests/IntelliTrader.Application.Tests/IntelliTrader.Application.Tests.csproj --configuration Releasedotnet test tests/IntelliTrader.Infrastructure.Tests/IntelliTrader.Infrastructure.Tests.csproj --configuration Releasedotnet test tests/IntelliTrader.Core.Tests/IntelliTrader.Core.Tests.csproj --configuration Releasedotnet test tests/IntelliTrader.Domain.Tests/IntelliTrader.Domain.Tests.csproj --configuration Releasedotnet build IntelliTrader.sln --configuration Release --no-restoreChecklist
Summary by CodeRabbit
Release Notes
New Features
Infrastructure