From 7a0612b2dbec8cd2665f76c8cfa46a4f5c6d6221 Mon Sep 17 00:00:00 2001 From: nobody <878822589@qq.com> Date: Wed, 29 Oct 2025 12:23:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=BD=93API=20URL=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4=E5=B8=81=E7=A7=8D?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=8C=E9=81=BF=E5=85=8D=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加默认主流币种列表(BTC、ETH、SOL、BNB、XRP、DOGE、ADA、HYPE) - 在GetCoinPool()中检查coin_pool_api_url,为空时直接返回默认列表 - 在GetOITopPositions()中检查oi_top_api_url,为空时跳过OI Top数据 - 更新README文档,说明API URL可选配置和默认币种列表 - 修复:避免空URL导致的循环请求和"unsupported protocol scheme"错误 --- README.md | 7 +++++-- README.zh-CN.md | 7 +++++-- pool/coin_pool.go | 48 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 08dbd4ef..5c5fb6d0 100644 --- a/README.md +++ b/README.md @@ -250,8 +250,11 @@ Create `config.json` file (use `config.json.example` as template): - `binance_api_key/secret_key`: Each trader uses independent Binance account - `initial_balance`: Initial balance (for calculating P/L%) - `scan_interval_minutes`: Decision cycle (recommended 3-5 minutes) -- `coin_pool_api_url`: AI500 coin pool API (optional) -- `oi_top_api_url`: OI Top open interest API (optional) +- `coin_pool_api_url`: AI500 coin pool API (optional, if empty, uses default mainstream coins) +- `oi_top_api_url`: OI Top open interest API (optional, if empty, OI Top data is skipped) + +**Default Coin List** (used when APIs are not configured): +- BTC, ETH, SOL, BNB, XRP, DOGE, ADA, HYPE ### 5. Run the System diff --git a/README.zh-CN.md b/README.zh-CN.md index 4684f8d4..20c0f50a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -250,8 +250,11 @@ cd .. - `binance_api_key/secret_key`: 每个trader使用独立的币安账户 - `initial_balance`: 初始余额(用于计算盈亏%) - `scan_interval_minutes`: 决策周期(建议3-5分钟) -- `coin_pool_api_url`: AI500币种池API(可选) -- `oi_top_api_url`: OI Top持仓量API(可选) +- `coin_pool_api_url`: AI500币种池API(可选,留空时使用默认主流币种) +- `oi_top_api_url`: OI Top持仓量API(可选,留空时跳过OI Top数据) + +**默认币种列表**(当API未配置时使用): +- BTC、ETH、SOL、BNB、XRP、DOGE、ADA、HYPE ### 5. 运行系统 diff --git a/pool/coin_pool.go b/pool/coin_pool.go index b88b865b..35c4bc64 100644 --- a/pool/coin_pool.go +++ b/pool/coin_pool.go @@ -8,9 +8,22 @@ import ( "net/http" "os" "path/filepath" + "strings" "time" ) +// defaultMainstreamCoins 默认主流币种池(当AI500和OI Top都失败时使用) +var defaultMainstreamCoins = []string{ + "BTCUSDT", + "ETHUSDT", + "SOLUSDT", + "BNBUSDT", + "XRPUSDT", + "DOGEUSDT", + "ADAUSDT", + "HYPEUSDT", +} + // CoinPoolConfig 币种池配置 type CoinPoolConfig struct { APIURL string @@ -65,6 +78,12 @@ func SetOITopAPI(apiURL string) { // GetCoinPool 获取币种池列表(带重试和缓存机制) func GetCoinPool() ([]CoinInfo, error) { + // 检查API URL是否配置 + if strings.TrimSpace(coinPoolConfig.APIURL) == "" { + log.Printf("⚠️ 未配置币种池API URL,使用默认主流币种列表") + return convertSymbolsToCoins(defaultMainstreamCoins), nil + } + maxRetries := 3 var lastErr error @@ -99,8 +118,9 @@ func GetCoinPool() ([]CoinInfo, error) { return cachedCoins, nil } - log.Printf("❌ 无法加载缓存数据: %v", err) - return nil, fmt.Errorf("获取币种池失败(API重试%d次后,缓存也不可用): %w", maxRetries, lastErr) + // 缓存也失败,使用默认主流币种 + log.Printf("⚠️ 无法加载缓存数据(最后错误: %v),使用默认主流币种列表", lastErr) + return convertSymbolsToCoins(defaultMainstreamCoins), nil } // fetchCoinPool 实际执行币种池请求 @@ -321,6 +341,19 @@ func endsWith(s, suffix string) bool { return s[len(s)-len(suffix):] == suffix } +// convertSymbolsToCoins 将币种符号列表转换为CoinInfo列表 +func convertSymbolsToCoins(symbols []string) []CoinInfo { + coins := make([]CoinInfo, 0, len(symbols)) + for _, symbol := range symbols { + coins = append(coins, CoinInfo{ + Pair: symbol, + Score: 0, + IsAvailable: true, + }) + } + return coins +} + // ========== OI Top(持仓量增长Top20)数据 ========== // OIPosition 持仓量数据 @@ -366,6 +399,12 @@ var oiTopConfig = struct { // GetOITopPositions 获取持仓量增长Top20数据(带重试和缓存) func GetOITopPositions() ([]OIPosition, error) { + // 检查API URL是否配置 + if strings.TrimSpace(oiTopConfig.APIURL) == "" { + log.Printf("⚠️ 未配置OI Top API URL,跳过OI Top数据获取") + return []OIPosition{}, nil // 返回空列表,不是错误 + } + maxRetries := 3 var lastErr error @@ -400,8 +439,9 @@ func GetOITopPositions() ([]OIPosition, error) { return cachedPositions, nil } - log.Printf("❌ 无法加载OI Top缓存数据: %v", err) - return nil, fmt.Errorf("获取OI Top数据失败(API重试%d次后,缓存也不可用): %w", maxRetries, lastErr) + // 缓存也失败,返回空列表(OI Top是可选的) + log.Printf("⚠️ 无法加载OI Top缓存数据(最后错误: %v),跳过OI Top数据", lastErr) + return []OIPosition{}, nil } // fetchOITop 实际执行OI Top请求 From ccfa48688b63fab4be20c3e656b025ba098d4077 Mon Sep 17 00:00:00 2001 From: nobody <878822589@qq.com> Date: Wed, 29 Oct 2025 12:59:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0use=5Fdefault=5Fc?= =?UTF-8?q?oins=E5=BC=80=E5=85=B3=EF=BC=8C=E7=AE=80=E5=8C=96=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=B8=81=E7=A7=8D=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增use_default_coins配置项:true=使用默认8个主流币种,false=使用API币种池 - 更直观的配置方式,新手可直接设置true快速开始 - 优先级:use_default_coins > coin_pool_api_url > 缓存 > 默认列表 - 更新所有语言版本README(en/zh-CN/ru/uk)添加配置说明 - 更新config.json.example示例文件 --- README.md | 5 +++-- README.ru.md | 15 +++++++++++++++ README.uk.md | 15 +++++++++++++++ README.zh-CN.md | 5 +++-- config.json.example | 1 + config/config.go | 1 + main.go | 6 ++++++ pool/coin_pool.go | 25 +++++++++++++++++++------ 8 files changed, 63 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5c5fb6d0..ad7e7046 100644 --- a/README.md +++ b/README.md @@ -250,10 +250,11 @@ Create `config.json` file (use `config.json.example` as template): - `binance_api_key/secret_key`: Each trader uses independent Binance account - `initial_balance`: Initial balance (for calculating P/L%) - `scan_interval_minutes`: Decision cycle (recommended 3-5 minutes) -- `coin_pool_api_url`: AI500 coin pool API (optional, if empty, uses default mainstream coins) +- `use_default_coins`: **true** = Use default 8 mainstream coins | **false** = Use API coin pool (recommended for beginners: true) +- `coin_pool_api_url`: AI500 coin pool API (optional, ignored when use_default_coins=true) - `oi_top_api_url`: OI Top open interest API (optional, if empty, OI Top data is skipped) -**Default Coin List** (used when APIs are not configured): +**Default Coin List** (when `use_default_coins: true`): - BTC, ETH, SOL, BNB, XRP, DOGE, ADA, HYPE ### 5. Run the System diff --git a/README.ru.md b/README.ru.md index ff43f489..f8f8e2b9 100644 --- a/README.ru.md +++ b/README.ru.md @@ -173,12 +173,27 @@ cd .. "initial_balance": 1000.0 } ], + "use_default_coins": false, "coin_pool_api_url": "http://x.x.x.x:xxx/api/ai500/list?auth=ВАШ_AUTH", "oi_top_api_url": "http://x.x.x.x:xxx/api/oi/top?auth=ВАШ_AUTH", "api_server_port": 8080 } ``` +**Примечания к конфигурации:** +- `traders`: Настройте 1-N трейдеров (один AI или соревнование нескольких AI) +- `id`: Уникальный идентификатор трейдера (используется для директории логов) +- `ai_model`: "qwen" или "deepseek" +- `binance_api_key/secret_key`: Каждый трейдер использует независимый аккаунт Binance +- `initial_balance`: Начальный баланс (для расчета P/L%) +- `scan_interval_minutes`: Цикл принятия решений (рекомендуется 3-5 минут) +- `use_default_coins`: **true** = Использовать 8 основных монет по умолчанию | **false** = Использовать API пул монет (рекомендуется для новичков: true) +- `coin_pool_api_url`: API пула монет AI500 (опционально, игнорируется при use_default_coins=true) +- `oi_top_api_url`: API открытого интереса OI Top (опционально, если пусто, данные OI Top пропускаются) + +**Список монет по умолчанию** (когда `use_default_coins: true`): +- BTC, ETH, SOL, BNB, XRP, DOGE, ADA, HYPE + ### 5. Запуск системы **Запуск backend (система AI торговли + API сервер):** diff --git a/README.uk.md b/README.uk.md index 5889a1b1..f9b08699 100644 --- a/README.uk.md +++ b/README.uk.md @@ -173,12 +173,27 @@ cd .. "initial_balance": 1000.0 } ], + "use_default_coins": false, "coin_pool_api_url": "http://x.x.x.x:xxx/api/ai500/list?auth=ВАШ_AUTH", "oi_top_api_url": "http://x.x.x.x:xxx/api/oi/top?auth=ВАШ_AUTH", "api_server_port": 8080 } ``` +**Примітки до конфігурації:** +- `traders`: Налаштуйте 1-N трейдерів (один AI або змагання кількох AI) +- `id`: Унікальний ідентифікатор трейдера (використовується для директорії логів) +- `ai_model`: "qwen" або "deepseek" +- `binance_api_key/secret_key`: Кожен трейдер використовує незалежний акаунт Binance +- `initial_balance`: Початковий баланс (для розрахунку P/L%) +- `scan_interval_minutes`: Цикл прийняття рішень (рекомендується 3-5 хвилин) +- `use_default_coins`: **true** = Використовувати 8 основних монет за замовчуванням | **false** = Використовувати API пул монет (рекомендується для новачків: true) +- `coin_pool_api_url`: API пулу монет AI500 (опціонально, ігнорується при use_default_coins=true) +- `oi_top_api_url`: API відкритого інтересу OI Top (опціонально, якщо порожньо, дані OI Top пропускаються) + +**Список монет за замовчуванням** (коли `use_default_coins: true`): +- BTC, ETH, SOL, BNB, XRP, DOGE, ADA, HYPE + ### 5. Запуск системи **Запуск backend (система AI торгівлі + API сервер):** diff --git a/README.zh-CN.md b/README.zh-CN.md index 20c0f50a..077fd6cc 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -250,10 +250,11 @@ cd .. - `binance_api_key/secret_key`: 每个trader使用独立的币安账户 - `initial_balance`: 初始余额(用于计算盈亏%) - `scan_interval_minutes`: 决策周期(建议3-5分钟) -- `coin_pool_api_url`: AI500币种池API(可选,留空时使用默认主流币种) +- `use_default_coins`: **true** = 使用默认8个主流币种 | **false** = 使用API币种池(新手推荐:true) +- `coin_pool_api_url`: AI500币种池API(可选,当use_default_coins=true时忽略) - `oi_top_api_url`: OI Top持仓量API(可选,留空时跳过OI Top数据) -**默认币种列表**(当API未配置时使用): +**默认币种列表**(当 `use_default_coins: true` 时): - BTC、ETH、SOL、BNB、XRP、DOGE、ADA、HYPE ### 5. 运行系统 diff --git a/config.json.example b/config.json.example index 4b29cbbf..3a6392a0 100644 --- a/config.json.example +++ b/config.json.example @@ -21,6 +21,7 @@ "scan_interval_minutes": 3 } ], + "use_default_coins": false, "coin_pool_api_url": "http://x.x.x.x:x/api/ai500/list?auth=", "oi_top_api_url": "http://x.x.x.x:x/api/oi/top?auth=", "api_server_port": 8080, diff --git a/config/config.go b/config/config.go index e427a226..489b0a83 100644 --- a/config/config.go +++ b/config/config.go @@ -23,6 +23,7 @@ type TraderConfig struct { // Config 总配置 type Config struct { Traders []TraderConfig `json:"traders"` + UseDefaultCoins bool `json:"use_default_coins"` // 是否使用默认主流币种列表 CoinPoolAPIURL string `json:"coin_pool_api_url"` OITopAPIURL string `json:"oi_top_api_url"` APIServerPort int `json:"api_server_port"` diff --git a/main.go b/main.go index c5791e88..b956209b 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,12 @@ func main() { log.Printf("✓ 配置加载成功,共%d个trader参赛", len(cfg.Traders)) fmt.Println() + // 设置是否使用默认主流币种 + pool.SetUseDefaultCoins(cfg.UseDefaultCoins) + if cfg.UseDefaultCoins { + log.Printf("✓ 已启用默认主流币种列表(BTC、ETH、SOL、BNB、XRP、DOGE、ADA、HYPE)") + } + // 设置币种池API URL if cfg.CoinPoolAPIURL != "" { pool.SetCoinPoolAPI(cfg.CoinPoolAPIURL) diff --git a/pool/coin_pool.go b/pool/coin_pool.go index 35c4bc64..6675013c 100644 --- a/pool/coin_pool.go +++ b/pool/coin_pool.go @@ -26,15 +26,17 @@ var defaultMainstreamCoins = []string{ // CoinPoolConfig 币种池配置 type CoinPoolConfig struct { - APIURL string - Timeout time.Duration - CacheDir string + APIURL string + Timeout time.Duration + CacheDir string + UseDefaultCoins bool // 是否使用默认主流币种 } var coinPoolConfig = CoinPoolConfig{ - APIURL: "", - Timeout: 30 * time.Second, // 增加到30秒 - CacheDir: "coin_pool_cache", + APIURL: "", + Timeout: 30 * time.Second, // 增加到30秒 + CacheDir: "coin_pool_cache", + UseDefaultCoins: false, // 默认不使用 } // CoinPoolCache 币种池缓存 @@ -76,8 +78,19 @@ func SetOITopAPI(apiURL string) { oiTopConfig.APIURL = apiURL } +// SetUseDefaultCoins 设置是否使用默认主流币种 +func SetUseDefaultCoins(useDefault bool) { + coinPoolConfig.UseDefaultCoins = useDefault +} + // GetCoinPool 获取币种池列表(带重试和缓存机制) func GetCoinPool() ([]CoinInfo, error) { + // 优先检查是否启用默认币种列表 + if coinPoolConfig.UseDefaultCoins { + log.Printf("✓ 已启用默认主流币种列表") + return convertSymbolsToCoins(defaultMainstreamCoins), nil + } + // 检查API URL是否配置 if strings.TrimSpace(coinPoolConfig.APIURL) == "" { log.Printf("⚠️ 未配置币种池API URL,使用默认主流币种列表")