mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-03 02:50:59 +08:00
fix(auto_trader): trader's stop channel isn't set when restarting (#779)
* fix(auto_trader): trader's stop channel isn't set when restarting * fix stopping trader immediately --------- Co-authored-by: zbhan <zbhan@freewheel.tv>
This commit is contained in:
@@ -239,10 +239,15 @@ func NewAutoTrader(config AutoTraderConfig, database interface{}, userID string)
|
||||
// Run 运行自动交易主循环
|
||||
func (at *AutoTrader) Run() error {
|
||||
at.isRunning = true
|
||||
at.stopMonitorCh = make(chan struct{})
|
||||
at.startTime = time.Now()
|
||||
|
||||
log.Println("🚀 AI驱动自动交易系统启动")
|
||||
log.Printf("💰 初始余额: %.2f USDT", at.initialBalance)
|
||||
log.Printf("⚙️ 扫描间隔: %v", at.config.ScanInterval)
|
||||
log.Println("🤖 AI将全权决定杠杆、仓位大小、止损止盈等参数")
|
||||
at.monitorWg.Add(1)
|
||||
defer at.monitorWg.Done()
|
||||
|
||||
// 启动回撤监控
|
||||
at.startDrawdownMonitor()
|
||||
@@ -261,6 +266,9 @@ func (at *AutoTrader) Run() error {
|
||||
if err := at.runCycle(); err != nil {
|
||||
log.Printf("❌ 执行失败: %v", err)
|
||||
}
|
||||
case <-at.stopMonitorCh:
|
||||
log.Printf("[%s] ⏹ 收到停止信号,退出自动交易主循环", at.name)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user