Feat/8/trade 매칭엔진 및 Trade 체결 구현#9
Conversation
- 체결 정보 저장을 위한 Trade 엔티티 추가 (maker/taker, buy/sell 구분) - TradeRepository: 마켓별 체결 내역 조회 추가
- OrderBookEntry: 오더북 항목 record (orderId, userId, price, remainingQuantity, sequence) - MatchResult: 체결 결과 record (maker/taker/buy/sell 정보, price, quantity, quoteAmount) - MemoryOrderBook: BUY는 높은 가격 우선, SELL은 낮은 가격 우선 PriorityQueue - MatchingEngine: 마켓별 오더북 관리, self-trade 방지, 부분 체결 지원
- Order: fill() 메서드 추가 (수량 업데이트, FILLED/PARTIALLY_FILLED 상태 전환) - CreateOrderResponse: List<Trade> 받아 TradeResult로 변환, liquidity(MAKER/TAKER) 포함 - OrderService: createOrder에 매칭 및 정산 연결, cancelOrder에 오더북 제거 추가 - settle(): 체결 시 Order 수량 업데이트, Trade 저장, Wallet 정산 (BUY→BTC 지급, SELL→KRW 지급)
- @beforeeach로 MatchingEngine 오더북 초기화 (테스트 간 상태 격리) - BUY/SELL 전량 체결: 체결 후 wallet 정산 검증 - BUY/SELL 부분 체결: seller FILLED, buyer PARTIALLY_FILLED 검증 - self-trade 방지: 동일 유저 BUY/SELL 매칭 불가 검증
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR implements a complete order matching engine with in-memory order books using priority queues, integrates matching into order creation, and persists trade records with wallet settlement. The implementation flows from creating domain contracts (MatchResult, Trade), through the priority-queue-based matching algorithm, orchestration via MatchingEngine, integration into OrderService with settlement logic, and API response mapping with integration test coverage. ChangesMatching Engine and Trade Settlement
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
LGTM?? |
Summary
Changes
Domain
Matching Engine
Settlement
Test plan
관련 이슈
closes #8
Summary by CodeRabbit