Phase 1: SQLite persistence layer

- Add modernc.org/sqlite (pure Go, no CGO)
- db/ package: trades, orders, config_log tables + CRUD
- Trade persistence: every closed trade saved to SQLite
- Restart recovery: open positions restored from DB
- Automatic migration on startup
This commit is contained in:
jackyu66git
2026-05-03 17:28:08 +08:00
parent 189fc0d9b6
commit b09314f317
7 changed files with 457 additions and 5 deletions
+10 -1
View File
@@ -11,6 +11,7 @@ import (
"syscall"
"time"
"exchange-monitor/db"
"exchange-monitor/exchange"
)
@@ -34,8 +35,16 @@ func main() {
store := NewPriceStore()
notifier := NewNotifier(cfg.TelegramBotToken, cfg.TelegramChatID)
// Initialize SQLite database
database, err := db.Open("")
if err != nil {
log.Printf("[DB] Failed to open database: %v", err)
} else {
defer database.Close()
}
// Initialize trader
trader := NewTrader(cfg)
trader := NewTrader(cfg, database)
if trader.IsConfigured() {
modeLabel := trader.ModeLabel()
log.Printf("[Trader] %s mode: automated trading ENABLED (threshold >= %.2f%%, $%.0f/trade)",