mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-12 07:16:56 +08:00
feat: dynamic crypto detection, trade history tool, fix 9 ticker leaks
- Agent gatherContext: expand from 10 hardcoded symbols to 38+ known symbols plus dynamic XXXUSDT pattern extraction (caps at 5 to avoid slow context) - Add get_trade_history tool: LLM can now query closed trades with PnL summary (win rate, total PnL, recent N trades across all traders) - Fix ticker.Stop() leak in ALL 9 exchange order_sync goroutines: OKX, Hyperliquid, Aster, Bybit, KuCoin, Gate, Bitget, Lighter, Binance — tickers were never stopped when traders were stopped, leaking goroutines
This commit is contained in:
@@ -399,17 +399,42 @@ func (a *Agent) gatherContext(text string) string {
|
||||
var parts []string
|
||||
upper := strings.ToUpper(text)
|
||||
|
||||
// Crypto — try to get real-time data
|
||||
cryptoSymbols := []string{"BTC", "ETH", "SOL", "BNB", "XRP", "DOGE", "ADA", "AVAX", "DOT", "LINK"}
|
||||
for _, sym := range cryptoSymbols {
|
||||
// Crypto — detect symbols dynamically
|
||||
// 1. Check known popular symbols (fast path)
|
||||
// 2. Extract any "XXXUSDT" pattern from text (catches arbitrary pairs)
|
||||
knownSymbols := []string{
|
||||
"BTC", "ETH", "SOL", "BNB", "XRP", "DOGE", "ADA", "AVAX", "DOT", "LINK",
|
||||
"PEPE", "SHIB", "ARB", "OP", "SUI", "APT", "SEI", "TIA", "JUP", "WIF",
|
||||
"NEAR", "ATOM", "FTM", "MATIC", "INJ", "RENDER", "FET", "TAO", "WLD",
|
||||
"AAVE", "UNI", "LDO", "MKR", "CRV", "PENDLE", "ENA", "ONDO", "TRUMP",
|
||||
}
|
||||
matched := make(map[string]bool)
|
||||
for _, sym := range knownSymbols {
|
||||
if strings.Contains(upper, sym) {
|
||||
md, err := market.Get(sym + "USDT")
|
||||
if err == nil {
|
||||
parts = append(parts, fmt.Sprintf("[%s/USDT Real-time]\nPrice: $%.4f | 1h: %+.2f%% | 4h: %+.2f%% | RSI7: %.1f | EMA20: %.4f | MACD: %.6f | Funding: %.4f%%",
|
||||
sym, md.CurrentPrice, md.PriceChange1h, md.PriceChange4h, md.CurrentRSI7, md.CurrentEMA20, md.CurrentMACD, md.FundingRate*100))
|
||||
matched[sym] = true
|
||||
}
|
||||
}
|
||||
// Also extract "XXXUSDT" patterns for coins not in the known list
|
||||
for _, word := range strings.Fields(upper) {
|
||||
word = strings.Trim(word, ".,!?;:()[]{}\"'")
|
||||
if strings.HasSuffix(word, "USDT") && len(word) > 4 && len(word) <= 15 {
|
||||
sym := strings.TrimSuffix(word, "USDT")
|
||||
if len(sym) >= 2 && len(sym) <= 10 {
|
||||
matched[sym] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// Cap at 5 symbols to avoid slow context gathering
|
||||
count := 0
|
||||
for sym := range matched {
|
||||
if count >= 5 { break }
|
||||
md, err := market.Get(sym + "USDT")
|
||||
if err == nil && md.CurrentPrice > 0 {
|
||||
parts = append(parts, fmt.Sprintf("[%s/USDT Real-time]\nPrice: $%.4f | 1h: %+.2f%% | 4h: %+.2f%% | RSI7: %.1f | EMA20: %.4f | MACD: %.6f | Funding: %.4f%%",
|
||||
sym, md.CurrentPrice, md.PriceChange1h, md.PriceChange4h, md.CurrentRSI7, md.CurrentEMA20, md.CurrentMACD, md.FundingRate*100))
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
// A-share / stocks — try Sina Finance (dynamic search as fallback)
|
||||
stockCode, stockName := resolveStockCodeDynamic(text)
|
||||
|
||||
Reference in New Issue
Block a user