Skip to content

Commit 6299c41

Browse files
committed
refactor(decision): replace hardcoded thresholds in buildSystemPrompt with config
完成 @xqliu 的第二處 code review 建議(line 337): **Changes:** 將 buildSystemPrompt 中的硬編碼閾值改為使用配置規則: **Before (硬編碼):** ```go if accountEquity < 20.0 { // ❌ 硬編碼 sb.WriteString(" | BTC/ETH≥12 USDT (⚠️ 小账户模式,降低门槛)") } else if accountEquity < 100.0 { // ❌ 硬編碼 minBTCETH := calculateMinPositionSize("BTCUSDT", accountEquity) sb.WriteString(fmt.Sprintf(" | BTC/ETH≥%.0f USDT (根据账户规模动态调整)", minBTCETH)) } else { sb.WriteString(" | BTC/ETH≥60 USDT") // ❌ 硬編碼 } ``` **After (使用配置):** ```go minBTCETH := calculateMinPositionSize("BTCUSDT", accountEquity) // 使用配置規則的閾值(btcEthSizeRules[1].MinEquity, btcEthSizeRules[2].MinEquity) if accountEquity < btcEthSizeRules[1].MinEquity { // ✅ 從配置讀取 btcEthHint = fmt.Sprintf(" | BTC/ETH≥%.0f USDT (⚠️ 小账户模式,降低门槛)", minBTCETH) } else if accountEquity < btcEthSizeRules[2].MinEquity { // ✅ 從配置讀取 btcEthHint = fmt.Sprintf(" | BTC/ETH≥%.0f USDT (根据账户规模动态调整)", minBTCETH) } else { btcEthHint = fmt.Sprintf(" | BTC/ETH≥%.0f USDT", minBTCETH) // ✅ 動態計算 } ``` **Benefits:** - ✅ **Single Source of Truth**: 閾值統一從 `btcEthSizeRules` 配置讀取 - ✅ **一致性**: buildSystemPrompt 和 calculateMinPositionSize 使用相同配置 - ✅ **易於維護**: 修改閾值只需改一處配置 - ✅ **避免不一致**: 消除硬編碼數字不匹配的風險 **Test Results:** ```bash ✅ go test ./decision -v # 所有測試通過 (26 cases) ✅ go fmt ./... # 格式化完成 ``` **現在兩處都已使用 map 配置:** 1. ✅ Line 337 (buildSystemPrompt) - 本次修復 2. ✅ Line 739 (calculateMinPositionSize) - 上次已修復 Addresses code review feedback from PR NoFxAiOS#907 (完整修復): - Line 337: "Can we have a map for this instead of Ashoc if else?" ✅ - Line 739: "Also a map would be better here." ✅ Co-authored-by: xqliu
1 parent 7616bab commit 6299c41

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

decision/engine.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,19 +335,24 @@ func buildSystemPrompt(accountEquity float64, btcEthLeverage, altcoinLeverage in
335335
sb.WriteString(fmt.Sprintf("4. 杠杆限制: **山寨币最大%dx杠杆** | **BTC/ETH最大%dx杠杆** (⚠️ 严格执行,不可超过)\n", altcoinLeverage, btcEthLeverage))
336336
sb.WriteString("5. 保证金: 总使用率 ≤ 90%\n")
337337

338-
// 6. 开仓金额:根据账户规模动态提示
339-
sb.WriteString("6. 开仓金额: 山寨币≥12 USDT")
340-
if accountEquity < 20.0 {
341-
// 小账户特殊提示
342-
sb.WriteString(" | BTC/ETH≥12 USDT (⚠️ 小账户模式,降低门槛)")
343-
} else if accountEquity < 100.0 {
344-
// 中型账户动态门槛
345-
minBTCETH := calculateMinPositionSize("BTCUSDT", accountEquity)
346-
sb.WriteString(fmt.Sprintf(" | BTC/ETH≥%.0f USDT (根据账户规模动态调整)", minBTCETH))
338+
// 6. 开仓金额:根据账户规模动态提示(使用统一的配置规则)
339+
minBTCETH := calculateMinPositionSize("BTCUSDT", accountEquity)
340+
341+
// 根据账户规模生成不同的提示语
342+
var btcEthHint string
343+
if accountEquity < btcEthSizeRules[1].MinEquity {
344+
// 小账户模式(< 20U)
345+
btcEthHint = fmt.Sprintf(" | BTC/ETH≥%.0f USDT (⚠️ 小账户模式,降低门槛)", minBTCETH)
346+
} else if accountEquity < btcEthSizeRules[2].MinEquity {
347+
// 中型账户(20-100U)
348+
btcEthHint = fmt.Sprintf(" | BTC/ETH≥%.0f USDT (根据账户规模动态调整)", minBTCETH)
347349
} else {
348-
// 大账户标准门槛
349-
sb.WriteString(" | BTC/ETH≥60 USDT")
350+
// 大账户(≥100U)
351+
btcEthHint = fmt.Sprintf(" | BTC/ETH≥%.0f USDT", minBTCETH)
350352
}
353+
354+
sb.WriteString("6. 开仓金额: 山寨币≥12 USDT")
355+
sb.WriteString(btcEthHint)
351356
sb.WriteString("\n\n")
352357

353358
// 3. 输出格式 - 动态生成

0 commit comments

Comments
 (0)