first commit

This commit is contained in:
hayato5246
2026-03-31 19:32:59 +09:00
commit d10b794c9f
78 changed files with 1671595 additions and 0 deletions

69
models/autotrade.go Normal file
View File

@@ -0,0 +1,69 @@
package models
import "time"
// AutoTradeRule 자동매매 규칙
type AutoTradeRule struct {
ID string `json:"id"`
Name string `json:"name"`
// 활성화 여부
Enabled bool `json:"enabled"`
// 진입 조건 (ScannerService 신호 기반)
MinRiseScore int `json:"minRiseScore"` // 최소 상승점수 (0~100, 기본 60)
MinCntrStr float64 `json:"minCntrStr"` // 최소 체결강도 (기본 110)
RequireBullish bool `json:"requireBullish"` // AI 호재(Sentiment=="호재") 필요 여부
// 주문 설정
OrderAmount int64 `json:"orderAmount"` // 1종목당 주문금액(원)
MaxPositions int `json:"maxPositions"` // 동시 최대 보유 종목 수 (기본 3)
// 청산 조건
StopLossPct float64 `json:"stopLossPct"` // 손절 % (예: -3.0)
TakeProfitPct float64 `json:"takeProfitPct"` // 익절 % (예: 5.0)
MaxHoldMinutes int `json:"maxHoldMinutes"` // 최대 보유 시간(분, 0=무제한)
ExitBeforeClose bool `json:"exitBeforeClose"` // 장 마감 전 청산(15:20 기준)
CreatedAt time.Time `json:"createdAt"`
}
// AutoTradePosition 자동매매 포지션
type AutoTradePosition struct {
Code string `json:"code"`
Name string `json:"name"`
BuyPrice int64 `json:"buyPrice"` // 매수 체결가
Qty int64 `json:"qty"` // 수량
OrderNo string `json:"orderNo"` // 매수 주문번호
EntryTime time.Time `json:"entryTime"` // 진입 시각
RuleID string `json:"ruleId"` // 규칙 ID
StopLoss int64 `json:"stopLoss"` // 절대 손절가
TakeProfit int64 `json:"takeProfit"` // 절대 익절가
// 상태: "pending"=체결 대기 | "open"=보유중 | "closed"=청산완료
Status string `json:"status"`
ExitTime time.Time `json:"exitTime,omitempty"`
ExitPrice int64 `json:"exitPrice,omitempty"`
// 청산 사유: "익절"|"손절"|"시간초과"|"장마감"|"긴급"
ExitReason string `json:"exitReason,omitempty"`
}
// AutoTradeLog 자동매매 이벤트 로그
type AutoTradeLog struct {
At time.Time `json:"at"`
Level string `json:"level"` // "info"|"warn"|"error"
Message string `json:"message"`
Code string `json:"code"` // 관련 종목코드 (없으면 "")
}
// ThemeRef 감시 소스로 선택된 테마 참조
type ThemeRef struct {
Code string `json:"code"` // 테마 코드
Name string `json:"name"` // 테마 이름 (UI 표시용)
}
// AutoTradeWatchSource 자동매매 감시 소스 설정
type AutoTradeWatchSource struct {
UseScanner bool `json:"useScanner"` // 체결강도 자동감지 사용
SelectedThemes []ThemeRef `json:"selectedThemes"` // 감시할 테마 목록
}

12
models/disclosure.go Normal file
View File

@@ -0,0 +1,12 @@
package models
// Disclosure DART 공시 항목
type Disclosure struct {
RceptNo string `json:"rceptNo"` // 접수번호
CorpName string `json:"corpName"` // 회사명
ReportNm string `json:"reportNm"` // 보고서명 (공시 제목)
RceptDt string `json:"rceptDt"` // 접수일자 (YYYYMMDD)
FlrNm string `json:"flrNm"` // 공시 제출인명
URL string `json:"url"` // DART 상세 URL (서버에서 조합)
Tag string `json:"tag"` // 이벤트 분류 태그
}

15
models/kospi200.go Normal file
View File

@@ -0,0 +1,15 @@
package models
// Kospi200Stock 코스피200 구성종목 (ka20002 응답)
type Kospi200Stock struct {
Code string `json:"code"` // stk_cd
Name string `json:"name"` // stk_nm
CurPrc int64 `json:"curPrc"` // cur_prc
PredPreSig string `json:"predPreSig"` // pred_pre_sig (2:상승 3:보합 5:하락)
PredPre int64 `json:"predPre"` // pred_pre 전일대비
FluRt float64 `json:"fluRt"` // flu_rt 등락률
Volume int64 `json:"volume"` // now_trde_qty 현재거래량
Open int64 `json:"open"` // open_pric
High int64 `json:"high"` // high_pric
Low int64 `json:"low"` // low_pric
}

9
models/news.go Normal file
View File

@@ -0,0 +1,9 @@
package models
// NewsItem 뉴스 기사 항목
type NewsItem struct {
Title string `json:"title"` // 기사 제목 (HTML 태그 제거됨)
URL string `json:"url"` // 원문 URL
PublishedAt string `json:"publishedAt"` // 발행일시 (RFC1123Z)
Source string `json:"source"` // 출처 (도메인)
}

96
models/stock.go Normal file
View File

@@ -0,0 +1,96 @@
package models
import "time"
// StockPrice 주식 현재가 정보
type StockPrice struct {
Code string `json:"code"` // 종목코드 (예: 005930)
Name string `json:"name"` // 종목명 (예: 삼성전자)
CurrentPrice int64 `json:"currentPrice"` // 현재가
ChangePrice int64 `json:"changePrice"` // 전일 대비 등락 금액
ChangeRate float64 `json:"changeRate"` // 등락률 (%)
Volume int64 `json:"volume"` // 누적 거래량 (13)
TradeMoney int64 `json:"tradeMoney"` // 누적 거래대금 (14)
High int64 `json:"high"` // 고가
Low int64 `json:"low"` // 저가
Open int64 `json:"open"` // 시가
TradeTime string `json:"tradeTime"` // 체결시각 (20, HHMMSS)
TradeVolume int64 `json:"tradeVolume"` // 체결량 (15)
AskPrice1 int64 `json:"askPrice1"` // 최우선매도호가 (27)
BidPrice1 int64 `json:"bidPrice1"` // 최우선매수호가 (28)
MarketStatus string `json:"marketStatus"` // 장구분 (290)
CntrStr float64 `json:"cntrStr"` // 체결강도
Market string `json:"market"` // 시장구분 (KOSPI / KOSDAQ)
UpdatedAt time.Time `json:"updatedAt"` // 마지막 업데이트 시각
}
// CandleData 캔들(봉) 데이터 (일봉/분봉 공통)
type CandleData struct {
Time int64 `json:"time"` // Unix 타임스탬프 (Lightweight Charts 형식)
Open int64 `json:"open"`
High int64 `json:"high"`
Low int64 `json:"low"`
Close int64 `json:"close"`
Volume int64 `json:"volume"`
}
// StockInfo 종목 기본 정보 (검색용)
type StockInfo struct {
Code string `json:"code"`
Name string `json:"name"`
Market string `json:"market"` // KOSPI / KOSDAQ
}
// AskingPrice 호가 정보
type AskingPrice struct {
SellPrices []int64 `json:"sellPrices"` // 매도 호가 (낮은→높은 순)
SellVolumes []int64 `json:"sellVolumes"`
BuyPrices []int64 `json:"buyPrices"` // 매수 호가 (높은→낮은 순)
BuyVolumes []int64 `json:"buyVolumes"`
}
// OrderBookEntry 개별 호가 항목
type OrderBookEntry struct {
Price int64 `json:"price"` // 호가
Volume int64 `json:"volume"` // 잔량
}
// OrderBook 실시간 호가창 (0D)
// Asks[0]=매도1호가(최우선), Asks[9]=매도10호가
// Bids[0]=매수1호가(최우선), Bids[9]=매수10호가
type OrderBook struct {
Code string `json:"code"`
AskTime string `json:"askTime"` // 21: 호가시간 (HHMMSS)
Asks []OrderBookEntry `json:"asks"` // 매도호가 1~10
Bids []OrderBookEntry `json:"bids"` // 매수호가 1~10
TotalAskVol int64 `json:"totalAskVol"` // 121: 매도호가총잔량
TotalBidVol int64 `json:"totalBidVol"` // 125: 매수호가총잔량
ExpectedPrc int64 `json:"expectedPrc"` // 23: 예상체결가
ExpectedVol int64 `json:"expectedVol"` // 24: 예상체결수량
}
// ProgramTrading 종목프로그램매매 실시간 데이터 (0w)
type ProgramTrading struct {
Code string `json:"code"`
SellVolume int64 `json:"sellVolume"` // 202: 매도수량
SellAmount int64 `json:"sellAmount"` // 204: 매도금액
BuyVolume int64 `json:"buyVolume"` // 206: 매수수량
BuyAmount int64 `json:"buyAmount"` // 208: 매수금액
NetBuyVolume int64 `json:"netBuyVolume"` // 210: 순매수수량
NetBuyAmount int64 `json:"netBuyAmount"` // 212: 순매수금액
}
// MarketStatus 장운영 상태 (0s)
type MarketStatus struct {
StatusCode string `json:"statusCode"` // 215: 장운영구분 코드
StatusName string `json:"statusName"` // 해석된 이름 (예: 장 중, 장 마감)
Time string `json:"time"` // 20: 체결시간
}
// StockMeta 종목 메타데이터 (0g)
type StockMeta struct {
Code string `json:"code"`
UpperLimit int64 `json:"upperLimit"` // 305: 상한가
LowerLimit int64 `json:"lowerLimit"` // 306: 하한가
BasePrice int64 `json:"basePrice"` // 307: 기준가
}

31
models/theme.go Normal file
View File

@@ -0,0 +1,31 @@
package models
// ThemeGroup 테마그룹 정보 (ka90001 응답)
type ThemeGroup struct {
Code string `json:"code"` // thema_grp_cd
Name string `json:"name"` // thema_nm
StockCount int `json:"stockCount"` // stk_num
FluSig string `json:"fluSig"` // flu_sig (2:상승 5:하락 3:보합)
FluRt float64 `json:"fluRt"` // flu_rt
RisingCount int `json:"risingCount"` // rising_stk_num
FallCount int `json:"fallCount"` // fall_stk_num
PeriodRt float64 `json:"periodRt"` // dt_prft_rt
MainStock string `json:"mainStock"` // main_stk
}
// ThemeDetail 테마구성종목 응답 (ka90002)
type ThemeDetail struct {
FluRt float64 `json:"fluRt"` // 테마 등락률
PeriodRt float64 `json:"periodRt"` // 기간수익률
Stocks []ThemeStock `json:"stocks"`
}
// ThemeStock 테마 구성종목
type ThemeStock struct {
Code string `json:"code"` // stk_cd
Name string `json:"name"` // stk_nm
CurPrc int64 `json:"curPrc"` // cur_prc
FluSig string `json:"fluSig"` // flu_sig
PredPre int64 `json:"predPre"` // pred_pre
FluRt float64 `json:"fluRt"` // flu_rt
}

13
models/token.go Normal file
View File

@@ -0,0 +1,13 @@
package models
import "time"
// TokenResponse 키움증권 토큰 발급 응답
type TokenResponse struct {
Token string `json:"token"` // 액세스 토큰
TokenType string `json:"token_type"` // "bearer"
ExpiresAt string `json:"expires_dt"` // 만료 일시 (YYYYMMDDHHmmss)
ReturnCode int `json:"return_code"`
ReturnMsg string `json:"return_msg"`
ExpiresTime time.Time `json:"-"` // 파싱된 만료 시각
}

13
models/websocket.go Normal file
View File

@@ -0,0 +1,13 @@
package models
// WSMessage WebSocket 메시지 공통 구조
type WSMessage struct {
Type string `json:"type"` // "subscribe" | "unsubscribe" | "price" | "error"
Code string `json:"code"` // 종목코드
Data interface{} `json:"data"` // StockPrice 또는 에러 메시지
}
// WSError WebSocket 에러 메시지 데이터
type WSError struct {
Message string `json:"message"`
}