Files
KisStock/backend/tables.md
2026-02-02 23:13:28 +09:00

3.9 KiB

BatchuKis Database Schema Definition

이 문서는 데이터베이스 설계를 위한 테이블 명세서입니다. 모든 컬럼명은 models.md의 필드명과 일치해야 합니다.


1. System & Config (설정 제어)

1.1 api_settings (전체 시스템 설정)

  • Primary Key: id (INTEGER, ALWAYS 1)
  • Columns:
    • appKey, appSecret, accountNumber: TEXT
    • useTelegram, useNaverNews: BOOLEAN
    • telegramToken, telegramChatId: TEXT
    • naverClientId, naverClientSecret: TEXT
    • kisApiDelayMs, newsScrapIntervalMin: INTEGER
    • preferredNewsAiId, preferredStockAiId, preferredNewsJudgementAiId, preferredAutoBuyAiId, preferredAutoSellAiId: TEXT (FK to ai_configs.id)

1.2 ai_configs (AI 엔진 프로필 저장소)

  • Primary Key: id (TEXT)
  • Columns: name, providerType, modelName, baseUrl (TEXT)

2. Account & Portfolio (자산 데이터)

2.1 account_status (계좌 요약 정보)

  • Primary Key: id (INTEGER, ALWAYS 1)
  • Columns: totalAssets, buyingPower, dailyProfit, dailyProfitRate (REAL)
  • Update Frequency: API 동기화 마다 갱신.

2.2 holdings (보유 자산 목록)

  • Primary Key: stockCode (TEXT)
  • Columns: stockName (TEXT), quantity (INTEGER), avgPrice, currentPrice, profit, profitRate, marketValue (REAL)

3. Market & Discovery (시세 및 탐색 데이터)

3.1 master_stocks (전체 종목 마스터)

  • Primary Key: code (TEXT)
  • Columns:
    • name, market (TEXT)
    • per, pbr, roe, marketCap, dividendYield (REAL)
    • memo (TEXT), isHidden (BOOLEAN)
  • 용도: 종목 검색, 메타데이터 제공 및 사용자 설정(메모/숨김) 저장.

3.2 news_cache (뉴스 및 분석 캐시)

  • Primary Key: news_id (TEXT - URL 해시 등)
  • Columns:
    • title, description, link, pubDate: TEXT
    • sentiment: TEXT
    • relatedThemes, relatedStocks: TEXT (JSON Array)
  • 용도: 동일 뉴스에 대한 중복 AI 분석 방지 및 히스토리 제공.

3.3 discovery_ranking_cache (발굴 랭킹 데이터)

  • Primary Key: category + market (Composite)
  • Columns: updated_at (DATETIME), items_json (TEXT - StockItem[] JSON)

3.4 stock_stats (종목별 확장 통계)

  • Primary Key: code (TEXT)
  • Columns:
    • tradingValue (REAL)
    • buyRatio, sellRatio, foreignNetBuy, institutionalNetBuy (INTEGER)
    • aiScoreBuy, aiScoreSell (INTEGER)
  • 용도: StockItem 확장을 위한 분석/수급 데이터 저장.

4. Watchlist (보관함)

4.1 watchlist_groups (그룹 정의)

  • Primary Key: id (TEXT)
  • Columns: name (TEXT), market (TEXT)

4.2 watchlist_items (그룹별 포함 종목)

  • Primary Key: group_id + stock_code (Composite)
  • Columns: added_at (DATETIME)
  • Relationship: group_id -> watchlist_groups.id

5. Trading & Automation (거래 및 자동화)

5.1 trade_history (전체 체결 내역)

  • Primary Key: id (TEXT)
  • Columns:
    • stockCode, stockName, type (TEXT)
    • quantity (INTEGER), price (REAL)
    • timestamp (DATETIME), status (TEXT)

5.2 auto_trade_robots (자동매매 전략 로봇)

  • Primary Key: id (TEXT)
  • Columns:
    • stockCode, stockName, groupId, type, frequency, executionTime, market: TEXT
    • quantity, specificDay: INTEGER
    • trailingPercent: REAL
    • active: BOOLEAN

5.3 reserved_orders (실시간 감시 주문)

  • Primary Key: id (TEXT)
  • Columns:
    • stockCode, stockName, type, monitoringType, trailingType, status, market: TEXT
    • quantity: INTEGER
    • triggerPrice, trailingValue, stopLossValue, highestPrice, lowestPrice: REAL
    • useStopLoss, sellAll: BOOLEAN
    • stopLossType: TEXT
    • createdAt, expiryDate: DATETIME