From 40190a2b8b64fa9a935f88d14944fdef9b06f8d2 Mon Sep 17 00:00:00 2001 From: PorunC <09982.misaka@gmail.com> Date: Wed, 29 Oct 2025 20:29:51 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20Add=20configurable=20leverage=20setting?= =?UTF-8?q?s=20for=20BTC/ETH=20and=20altcoins=20(v2.0.3)=20-=20Add=20Lever?= =?UTF-8?q?ageConfig=20struct=20with=20btc=5Feth=5Fleverage=20and=20altcoi?= =?UTF-8?q?n=5Fleverage=20fields=20-=20Set=20default=20leverage=20to=205x?= =?UTF-8?q?=20(safe=20for=20Binance=20subaccounts)=20-=20Add=20validation?= =?UTF-8?q?=20warnings=20for=20leverage=20>5x=20(subaccount=20restrictions?= =?UTF-8?q?)=20-=20Update=20config.json.example=20with=20leverage=20config?= =?UTF-8?q?uration=20Breaking=20changes:=20-=20None=20(backward=20compatib?= =?UTF-8?q?le=20with=20default=205x=20leverage)=20Migration:=20-=20Existin?= =?UTF-8?q?g=20configs=20will=20auto-default=20to=205x=20leverage=20(safe)?= =?UTF-8?q?=20-=20Main=20accounts=20can=20increase=20to=2020x=20(altcoins)?= =?UTF-8?q?=20or=2050x=20(BTC/ETH)=20in=20config.json=20-=20Subaccounts=20?= =?UTF-8?q?must=20keep=20leverage=20=E2=89=A45x=20to=20avoid=20trade=20fai?= =?UTF-8?q?lures=20Co-Authored-By:=20tinkle-community=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json.example | 4 ++++ config/config.go | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/config.json.example b/config.json.example index eb817ea6..d1897508 100644 --- a/config.json.example +++ b/config.json.example @@ -13,6 +13,10 @@ "scan_interval_minutes": 3 } ], + "leverage": { + "btc_eth_leverage": 5, + "altcoin_leverage": 5 + }, "use_default_coins": true, "coin_pool_api_url": "", "oi_top_api_url": "", diff --git a/config/config.go b/config/config.go index efaf7a75..561f1fc6 100644 --- a/config/config.go +++ b/config/config.go @@ -20,6 +20,12 @@ type TraderConfig struct { ScanIntervalMinutes int `json:"scan_interval_minutes"` } +// LeverageConfig 杠杆配置 +type LeverageConfig struct { + BTCETHLeverage int `json:"btc_eth_leverage"` // BTC和ETH的杠杆倍数(主账户建议5-50,子账户≤5) + AltcoinLeverage int `json:"altcoin_leverage"` // 山寨币的杠杆倍数(主账户建议5-20,子账户≤5) +} + // Config 总配置 type Config struct { Traders []TraderConfig `json:"traders"` @@ -30,6 +36,7 @@ type Config struct { MaxDailyLoss float64 `json:"max_daily_loss"` MaxDrawdown float64 `json:"max_drawdown"` StopTradingMinutes int `json:"stop_trading_minutes"` + Leverage LeverageConfig `json:"leverage"` // 杠杆配置 } // LoadConfig 从文件加载配置 @@ -100,6 +107,20 @@ func (c *Config) Validate() error { c.APIServerPort = 8080 // 默认8080端口 } + // 设置杠杆默认值(适配币安子账户限制,最大5倍) + if c.Leverage.BTCETHLeverage <= 0 { + c.Leverage.BTCETHLeverage = 5 // 默认5倍(安全值,适配子账户) + } + if c.Leverage.BTCETHLeverage > 5 { + fmt.Printf("⚠️ 警告: BTC/ETH杠杆设置为%dx,如果使用子账户可能会失败(子账户限制≤5x)\n", c.Leverage.BTCETHLeverage) + } + if c.Leverage.AltcoinLeverage <= 0 { + c.Leverage.AltcoinLeverage = 5 // 默认5倍(安全值,适配子账户) + } + if c.Leverage.AltcoinLeverage > 5 { + fmt.Printf("⚠️ 警告: 山寨币杠杆设置为%dx,如果使用子账户可能会失败(子账户限制≤5x)\n", c.Leverage.AltcoinLeverage) + } + return nil }