atrade/src/main/kotlin/report/database/ReportTables.kt
2026-04-16 15:48:23 +09:00

77 lines
3.1 KiB
Kotlin

package report.database
import org.jetbrains.exposed.sql.Table
// 💡 [신규] 설정 변경 이력 전용 테이블
object ConfigHistoryTable : Table("config_history") {
val id = integer("id").autoIncrement()
val updatedAt = varchar("updated_at", 50) // 마지막 수정 시간
val configJson = text("config_json") // 설정값 JSON
override val primaryKey = PrimaryKey(id)
}
// [1] 자산 스냅샷 마스터 (설정 필드 제거)
object AssetSnapshotTable : Table("asset_snapshots") {
val id = integer("id").autoIncrement()
val date = varchar("date", 10)
val snapshotType = varchar("type", 20)
val totalAsset = long("total_asset")
val totalProfitRate = double("profit_rate")
val deposit = long("deposit")
val appliedConfigJson = text("applied_config")
val remark = varchar("remark", 255).nullable()
override val primaryKey = PrimaryKey(id)
}
// [2] 보유 종목 상세 (UnifiedStockHolding 기준)
object SnapshotHoldingsTable : Table("snapshot_holdings") {
val id = integer("id").autoIncrement()
val snapshotId = reference("snapshot_id", AssetSnapshotTable.id)
val code = varchar("code", 20)
val name = varchar("name", 100)
val quantity = integer("quantity")
val avgPrice = double("avg_price")
val positionId = varchar("position_id", 50).nullable().index()
val currentPrice = double("current_price")
val profitRate = double("profit_rate")
val evalAmount = long("eval_amount")
val isDomestic = bool("is_domestic")
val isTodayEntry = bool("is_today_entry") // 당일 진입 여부
override val primaryKey = PrimaryKey(id)
}
// [3] 매매 이력 및 결정 근거 (TradingDecision + 수정된 TradeHistoryTable)
object TradeHistoryTable : Table("trade_history") {
val id = integer("id").autoIncrement()
val orderNo = varchar("order_no", 50).uniqueIndex()
val stockCode = varchar("stock_code", 20)
val stockName = varchar("stock_name", 100)
val orderTime = varchar("order_time", 50)
val isBuy = bool("is_buy")
val status = varchar("status", 20)
val orderQty = integer("order_qty").default(0)
val reason = text("reason") // AI 판단 전문
val currentPrice = double("current_price").nullable() // 결정 당시 가격
val aiScore = double("ai_score").nullable() // 종합 점수
val newsScore = double("news_score").nullable()
val systemScore = double("system_score").nullable()
val financialScore = double("financial_score").nullable()
val technicalScore = double("technical_score").nullable()
val investmentGrade = text("investment_grade").nullable() // 투자 등급 (S, A, B...)
val holdingAvgPrice = double("holding_avg_price").default(0.0)
override val primaryKey = PrimaryKey(id)
}
// [4] 체결 상세 (그대로 유지)
object ExecutionDetailsTable : Table("execution_details") {
val id = integer("id").autoIncrement()
val tradeId = reference("trade_id", TradeHistoryTable.id)
val execTime = varchar("exec_time", 50)
val price = double("price")
val quantity = integer("quantity")
override val primaryKey = PrimaryKey(id)
}