mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-06-06 05:51:19 +08:00
fix: initial balance calculation and UI improvements
- Fix initial balance using available_balance instead of total_equity - Fix WSMonitor nil pointer by starting market monitor before loading traders - Add strategy name display on traders list and dashboard pages - Various position sync and trading improvements
This commit is contained in:
20
main.go
20
main.go
@@ -11,10 +11,12 @@ import (
|
||||
"nofx/market"
|
||||
"nofx/mcp"
|
||||
"nofx/store"
|
||||
"nofx/trader"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
@@ -94,6 +96,13 @@ func main() {
|
||||
auth.SetJWTSecret(cfg.JWTSecret)
|
||||
logger.Info("🔑 JWT secret configured")
|
||||
|
||||
// Start WebSocket market monitor FIRST (before loading traders that may need market data)
|
||||
// This ensures WSMonitorCli is initialized before any trader tries to access it
|
||||
go market.NewWSMonitor(150).Start(nil)
|
||||
logger.Info("📊 WebSocket market monitor started")
|
||||
// Give WebSocket monitor time to initialize
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Create TraderManager and BacktestManager
|
||||
traderManager := manager.NewTraderManager()
|
||||
mcpClient := newSharedMCPClient()
|
||||
@@ -102,7 +111,12 @@ func main() {
|
||||
logger.Warnf("⚠️ Failed to restore backtest history: %v", err)
|
||||
}
|
||||
|
||||
// Load all traders from database to memory
|
||||
// Start position sync manager (detects manual closures, TP/SL triggers)
|
||||
positionSyncManager := trader.NewPositionSyncManager(st, 0) // 0 = use default 10s interval
|
||||
positionSyncManager.Start()
|
||||
defer positionSyncManager.Stop()
|
||||
|
||||
// Load all traders from database to memory (may auto-start traders with IsRunning=true)
|
||||
if err := traderManager.LoadTradersFromStore(st); err != nil {
|
||||
logger.Fatalf("❌ Failed to load traders: %v", err)
|
||||
}
|
||||
@@ -127,10 +141,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Start WebSocket market monitor (get market data for all USDT perpetual contracts)
|
||||
go market.NewWSMonitor(150).Start(nil)
|
||||
logger.Info("📊 WebSocket market monitor started")
|
||||
|
||||
// Start API server
|
||||
server := api.NewServer(traderManager, st, cryptoService, backtestManager, cfg.APIServerPort)
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user