fix: handle empty AI500 coin list gracefully instead of error

This commit is contained in:
tinkle-community
2026-01-23 20:12:11 +08:00
parent 2f54d1d4c0
commit b5716ff3cb
3 changed files with 11 additions and 1 deletions

View File

@@ -447,6 +447,7 @@ func (e *StrategyEngine) GetCandidateCoins() ([]CandidateCoin, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// 空列表是正常情况,直接返回
return e.filterExcludedCoins(coins), nil return e.filterExcludedCoins(coins), nil
case "oi_top": case "oi_top":
@@ -466,6 +467,7 @@ func (e *StrategyEngine) GetCandidateCoins() ([]CandidateCoin, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// 空列表是正常情况,直接返回
return e.filterExcludedCoins(coins), nil return e.filterExcludedCoins(coins), nil
case "mixed": case "mixed":

View File

@@ -73,8 +73,10 @@ func (c *Client) fetchAI500() ([]CoinData, error) {
return nil, fmt.Errorf("API returned failure status") return nil, fmt.Errorf("API returned failure status")
} }
// 空列表是正常情况,不是错误
if len(response.Data.Coins) == 0 { if len(response.Data.Coins) == 0 {
return nil, fmt.Errorf("coin list is empty") log.Printf(" AI500 returned empty coin list (no coins meet criteria currently)")
return []CoinData{}, nil
} }
// Set IsAvailable flag // Set IsAvailable flag

View File

@@ -534,6 +534,12 @@ func (at *AutoTrader) runCycle() error {
return fmt.Errorf("failed to build trading context: %w", err) return fmt.Errorf("failed to build trading context: %w", err)
} }
// 如果没有候选币种,友好提示并跳过本周期
if len(ctx.CandidateCoins) == 0 {
logger.Infof(" No candidate coins available, skipping this cycle")
return nil
}
// Save equity snapshot independently (decoupled from AI decision, used for drawing profit curve) // Save equity snapshot independently (decoupled from AI decision, used for drawing profit curve)
at.saveEquitySnapshot(ctx) at.saveEquitySnapshot(ctx)