자산 현황 및 자동매매 페이지 제거:
Some checks failed
Build Push and Restart Compose / deploy (push) Failing after 11m20s
Some checks failed
Build Push and Restart Compose / deploy (push) Failing after 11m20s
- `/templates/pages/asset.html`, `/templates/pages/autotrade.html` HTML 템플릿 삭제. - `/static/js/asset.js`, `/static/js/autotrade.js` 클라이언트 스크립트 제거. - 관련 함수 및 초기화 로직 삭제 (자산 조회 및 자동매매 기능 비활성화).
This commit is contained in:
@@ -66,6 +66,23 @@ func GetAutoTradeService() *AutoTradeService {
|
||||
SelectedThemes: []models.ThemeRef{},
|
||||
},
|
||||
}
|
||||
// DB에서 데이터 복원
|
||||
if rules := dbLoadRules(); len(rules) > 0 {
|
||||
autoTradeService.rules = rules
|
||||
log.Printf("DB에서 규칙 %d개 로드", len(rules))
|
||||
}
|
||||
if positions := dbLoadActivePositions(); len(positions) > 0 {
|
||||
autoTradeService.positions = positions
|
||||
log.Printf("DB에서 활성 포지션 %d개 로드", len(positions))
|
||||
}
|
||||
if ws := dbLoadWatchSource(); ws != nil {
|
||||
autoTradeService.watchSource = *ws
|
||||
log.Printf("DB에서 감시소스 로드")
|
||||
}
|
||||
if logs := dbLoadRecentLogs(maxLogEntries); len(logs) > 0 {
|
||||
autoTradeService.logs = logs
|
||||
log.Printf("DB에서 로그 %d건 로드", len(logs))
|
||||
}
|
||||
}
|
||||
return autoTradeService
|
||||
}
|
||||
@@ -93,6 +110,7 @@ func (s *AutoTradeService) SetWatchSource(ws models.AutoTradeWatchSource) {
|
||||
s.mu.Lock()
|
||||
s.watchSource = ws
|
||||
s.mu.Unlock()
|
||||
dbUpsertWatchSource(ws)
|
||||
|
||||
sources := "없음"
|
||||
if ws.UseScanner && len(ws.SelectedThemes) > 0 {
|
||||
@@ -245,6 +263,7 @@ func (s *AutoTradeService) AddRule(rule models.AutoTradeRule) models.AutoTradeRu
|
||||
s.mu.Lock()
|
||||
s.rules = append(s.rules, rule)
|
||||
s.mu.Unlock()
|
||||
dbInsertRule(rule)
|
||||
s.addLog("info", "", fmt.Sprintf("규칙 추가: %s", rule.Name))
|
||||
return rule
|
||||
}
|
||||
@@ -258,6 +277,7 @@ func (s *AutoTradeService) UpdateRule(id string, updated models.AutoTradeRule) b
|
||||
updated.ID = id
|
||||
updated.CreatedAt = r.CreatedAt
|
||||
s.rules[i] = updated
|
||||
dbUpdateRule(updated)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -271,6 +291,7 @@ func (s *AutoTradeService) DeleteRule(id string) bool {
|
||||
for i, r := range s.rules {
|
||||
if r.ID == id {
|
||||
s.rules = append(s.rules[:i], s.rules[i+1:]...)
|
||||
dbDeleteRule(id)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -284,6 +305,7 @@ func (s *AutoTradeService) ToggleRule(id string) (bool, bool) {
|
||||
for i, r := range s.rules {
|
||||
if r.ID == id {
|
||||
s.rules[i].Enabled = !r.Enabled
|
||||
dbUpdateRule(s.rules[i])
|
||||
return true, s.rules[i].Enabled
|
||||
}
|
||||
}
|
||||
@@ -311,6 +333,24 @@ func (s *AutoTradeService) GetPositions() []*models.AutoTradePosition {
|
||||
return result
|
||||
}
|
||||
|
||||
// GetTrades 종료된 거래 내역 반환 (DB에서 조회, 없으면 메모리에서 필터)
|
||||
func (s *AutoTradeService) GetTrades(limit int) []*models.AutoTradePosition {
|
||||
if trades := dbLoadClosedPositions(limit); trades != nil {
|
||||
return trades
|
||||
}
|
||||
// DB 없으면 메모리에서 closed 포지션 반환
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
var result []*models.AutoTradePosition
|
||||
for _, p := range s.positions {
|
||||
if p.Status == "closed" {
|
||||
cp := *p
|
||||
result = append(result, &cp)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// GetLogs 최근 로그 반환
|
||||
func (s *AutoTradeService) GetLogs() []models.AutoTradeLog {
|
||||
s.mu.RLock()
|
||||
@@ -322,6 +362,11 @@ func (s *AutoTradeService) GetLogs() []models.AutoTradeLog {
|
||||
|
||||
// GetStats 오늘 통계 반환 (매매 횟수, 손익)
|
||||
func (s *AutoTradeService) GetStats() (tradeCount int, totalPL int64) {
|
||||
// DB가 있으면 DB에서 조회 (종료된 포지션 포함)
|
||||
if db != nil {
|
||||
return dbGetTodayStats()
|
||||
}
|
||||
// DB 없으면 메모리에서 계산
|
||||
today := time.Now().Truncate(24 * time.Hour)
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
@@ -532,6 +577,7 @@ func (s *AutoTradeService) checkEntries() {
|
||||
s.cooldown[code] = time.Now()
|
||||
s.mu.Unlock()
|
||||
|
||||
dbInsertPosition(pos)
|
||||
s.addLog("info", code, fmt.Sprintf("매수 주문 접수: %s %d주 (주문번호: %s, RiseScore: %d)", sig.Name, qty, result.OrderNo, sig.RiseScore))
|
||||
}
|
||||
}
|
||||
@@ -648,6 +694,7 @@ func (s *AutoTradeService) checkPending() {
|
||||
p.StopLoss = stopLoss
|
||||
p.TakeProfit = takeProfit
|
||||
p.Status = "open"
|
||||
dbUpdatePosition(p)
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
@@ -709,6 +756,7 @@ func (s *AutoTradeService) executeSell(pos *models.AutoTradePosition, reason str
|
||||
p.ExitTime = time.Now()
|
||||
p.ExitPrice = exitPrice
|
||||
p.ExitReason = reason
|
||||
dbUpdatePosition(p)
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
@@ -771,6 +819,11 @@ func (s *AutoTradeService) addLog(level, code, message string) {
|
||||
broadcaster := s.logBroadcaster
|
||||
s.mu.Unlock()
|
||||
|
||||
// debug 로그는 DB에 저장하지 않음 (빈도 높음)
|
||||
if level != "debug" {
|
||||
dbInsertLog(entry)
|
||||
}
|
||||
|
||||
// WS 브로드캐스트 (락 밖에서 호출해 데드락 방지)
|
||||
if broadcaster != nil {
|
||||
broadcaster(entry)
|
||||
@@ -873,6 +926,7 @@ func (s *AutoTradeService) evalExitReason(code string, pos *models.AutoTradePosi
|
||||
if p, ok := s.positions[code]; ok && p.Status == "open" {
|
||||
p.StopLoss1Touches++
|
||||
touches = p.StopLoss1Touches
|
||||
dbUpdatePosition(p)
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user