feat: add debate arena and fix multiple issues

- Add AI debate arena for multi-AI trading decisions
- Fix debate consensus calculation and display
- Fix vote parsing to support both <decision> and <final_vote> tags
- Fix JSON field name compatibility (stop_loss/stop_loss_pct)
- Fix symbol validation to prevent AI hallucinating invalid symbols
- Fix Bybit position side display (was uppercase, now lowercase for consistency)
- Fix NOFX logo navigation to home page
- Add detailed logging for debugging trade execution
This commit is contained in:
tinkle-community
2025-12-12 11:24:32 +08:00
parent e5703ffab6
commit f5ae22d85c
14 changed files with 4133 additions and 32 deletions

View File

@@ -3,6 +3,8 @@ package manager
import (
"context"
"fmt"
"nofx/debate"
"nofx/decision"
"nofx/logger"
"nofx/store"
"nofx/trader"
@@ -11,6 +13,27 @@ import (
"time"
)
// TraderExecutorAdapter wraps AutoTrader to implement debate.TraderExecutor
type TraderExecutorAdapter struct {
autoTrader *trader.AutoTrader
}
// ExecuteDecision executes a trading decision
func (a *TraderExecutorAdapter) ExecuteDecision(d *decision.Decision) error {
return a.autoTrader.ExecuteDecision(d)
}
// GetBalance returns account balance
func (a *TraderExecutorAdapter) GetBalance() (map[string]interface{}, error) {
info, err := a.autoTrader.GetAccountInfo()
if err != nil {
return nil, fmt.Errorf("failed to get account info: %w", err)
}
// Log the balance for debugging
logger.Infof("[Debate] GetBalance for trader, result: %+v", info)
return info, nil
}
// CompetitionCache competition data cache
type CompetitionCache struct {
data map[string]interface{}
@@ -696,3 +719,13 @@ func (tm *TraderManager) addTraderFromStore(traderCfg *store.Trader, aiModelCfg
return nil
}
// GetTraderExecutor returns a TraderExecutor for the given trader ID
// This is used by the debate module to execute consensus trades
func (tm *TraderManager) GetTraderExecutor(traderID string) (debate.TraderExecutor, error) {
at, err := tm.GetTrader(traderID)
if err != nil {
return nil, err
}
return &TraderExecutorAdapter{autoTrader: at}, nil
}