Files
stocksearch/models/autotrade.go
hayato5246 00ffc6b54c
Some checks failed
Build Push and Restart Compose / deploy (push) Failing after 1m42s
프론트엔드 추가 및 자동매매 로직 개선:
- Svelte 기반 프론트엔드 프로젝트 초기 설정 추가 (`vite`, `tailwindcss` 등 포함).
- "자동매매" 주요 상태 및 규칙 관리 페이지 구현.
- 1차/2차 손절 및 익절 조건 평가 로직 추가(`calcStopTargets`, `evalExitReason` 등).
- 포지션 상세 로그 및 WebSocket 기반 실시간 로그 스트림 추가.
- API 서비스 및 Frontend 간 Proxy 설정(Vite 서버).
- 세션 체크를 위한 `CheckSession` 핸들러 추가.
2026-04-05 20:30:52 +09:00

77 lines
3.3 KiB
Go

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)
// 청산 조건
// 2중 손절 구조:
// 1차 - StopLoss1Pct 에 StopLoss1Count 회 터치 시 매도
// 2차 - StopLossPct 에 닿으면 즉시 매도 (StopLoss1Count==0 이면 단일 손절)
StopLoss1Pct float64 `json:"stopLoss1Pct"` // 1차 손절 % (예: -2.0, 0=비활성)
StopLoss1Count int `json:"stopLoss1Count"` // 1차 손절 터치 횟수 (예: 3)
StopLossPct float64 `json:"stopLossPct"` // 2차 손절 % (예: -4.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
StopLoss1 int64 `json:"stopLoss1"` // 절대 1차 손절가 (0=비활성)
StopLoss1Touches int `json:"stopLoss1Touches"` // 1차 손절가 터치 누적 횟수
StopLoss int64 `json:"stopLoss"` // 절대 2차 손절가 (즉시 매도)
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"` // 감시할 테마 목록
}