STK10-03 투자자별 거래실적 수집·영속화

작업 내용

투자자별 거래실적(개인·외국인·기관 종목별 순매수) 수직 슬라이스를 구현한다. marketflow 도메인 패키지에 새 파일만 추가해 다른 팩터 티켓과 파일 교집합이 없다.

  • domain: InvestorTrading Entity (Rich Domain), InvestorTradingRepository·InvestorTradingGateway interface
  • infrastructure/krx: KrxInvestorTradingGatewayImpl — 해당 bld로 KrxMdcClient 호출, JSON → Entity 파싱
  • infrastructure/mysql: InvestorTradingRepositoryImpl — 전종목 ~1,750행을 통계당 1회 JDBC 벌크 upsert(INSERT … ON DUPLICATE KEY UPDATE), 행 단위 save 금지

다이어그램

처리 흐름

sequenceDiagram
    participant DS as MarketFlowDomainService
    participant Gw as KrxInvestorTradingGatewayImpl
    participant Client as KrxMdcClient
    participant Repo as InvestorTradingRepositoryImpl
    DS->>Gw: fetch(baseDate)
    Gw->>Client: getJsonData(bld, baseDate)
    Client-->>Gw: rows
    Gw-->>DS: List<InvestorTrading>
    DS->>Repo: upsertAll(list)

클래스 의존

flowchart LR
    Impl[KrxInvestorTradingGatewayImpl] -.implements.-> Gw[InvestorTradingGateway]
    Impl --> Client[KrxMdcClient]
    RepoImpl[InvestorTradingRepositoryImpl] -.implements.-> Repo[InvestorTradingRepository]

테스트 케이스

  • KRX JSON을 InvestorTrading Entity로 파싱한다 (외국인·기관·개인 순매수 매핑)
  • 동일 (symbol, base_date) 재적재 시 멱등 upsert된다
  • 전종목을 통계당 1회 벌크 upsert로 적재한다 (행 단위 save 미사용)
  • 필드 누락·빈 응답 시 빈 리스트로 graceful 처리한다
  • 순매수 부호(매도 우위 음수)가 보존된다