fix(prompts): correct confidence scale from 0-1 to 0-100 to match backend schema (#564)

## Problem

The prompts specified confidence range as 0-1 (float), but the backend code
expects 0-100 (integer). This causes JSON parsing errors when AI outputs
values like 0.85:

```
Error: json: cannot unmarshal number 0.85 into Go struct field Decision.confidence of type int
Result: confidence defaults to 0
```

## Root Cause

**Backend Definition** (decision/engine.go:103):
```go
Confidence int `json:"confidence,omitempty"` // 信心度 (0-100)
```

**Prompts (before fix)**:
- adaptive.txt: "confidence (信心度 0-1)"
- nof1.txt: "confidence (float, 0-1)"

**buildHardSystemPrompt** (decision/engine.go:336):
```go
sb.WriteString("- `confidence`: 0-100(开仓建议≥75)\n")
```

The dynamic system prompt was correct, but the base prompts contradicted it.

## Solution

Update prompt files to use consistent 0-100 integer scale:

### adaptive.txt
- `confidence (信心度 0-1)` → `confidence (信心度 0-100)`
- `<0.85` → `<85`
- `0.85-0.90` → `85-90`
- etc.

### nof1.txt
- `confidence (float, 0-1)` → `confidence (int, 0-100)`
- `0.0-0.3` → `0-30`
- `0.3-0.6` → `30-60`
- etc.

## Impact

-  Fixes JSON parsing errors when AI outputs float values
-  Aligns prompts with backend schema
-  Consistent with buildHardSystemPrompt() output format
-  No breaking changes (backend already expects 0-100)

## Testing

```bash
# Verify backend expects 0-100
grep "Confidence int" decision/engine.go
# Output: Confidence int `json:"confidence,omitempty"` // 信心度 (0-100)

# Verify buildHardSystemPrompt uses 0-100
grep "confidence.*0-100" decision/engine.go
# Output: sb.WriteString("- `confidence`: 0-100(开仓建议≥75)\n")

# Build test
go build ./decision/...  #  PASS
```

## Related

- Addresses schema mismatch mentioned in Issue #557
- Note: confidence field is currently not validated by backend (validateDecision
  does not check confidence value), but correct schema prevents parsing errors

---

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
0xYYBB | ZYY | Bobo
2025-11-06 00:35:53 +08:00
committed by GitHub
parent 1542374b73
commit 724366a894
2 changed files with 10 additions and 10 deletions

View File

@@ -393,12 +393,12 @@
- 明确的市场信号,证明交易逻辑失效
- 例如: "BTC跌破$100k""RSI跌破30""资金费率转负"
4. **confidence** (信心度 0-1)
4. **confidence** (信心度 0-100)
- 使用客观评分公式计算(基础分 60 + 条件加减分)
- <0.85: 禁止开仓
- 0.85-0.90: 风险预算 1.5%
- 0.90-0.95: 风险预算 2%
- >0.95: 风险预算 2.5%(谨慎使用,警惕过度自信)
- <85: 禁止开仓
- 85-90: 风险预算 1.5%
- 90-95: 风险预算 2%
- >95: 风险预算 2.5%(谨慎使用,警惕过度自信)
5. **risk_usd** (风险金额)
- 计算公式: |入场价 - 止损价| × 仓位数量 × 杠杆

View File

@@ -94,11 +94,11 @@ For EVERY trade decision, you MUST specify:
- Examples: "BTC breaks below $100k", "RSI drops below 30", "Funding rate flips negative"
- Must be objective and observable
4. **confidence** (float, 0-1): Your conviction level in this trade
- 0.0-0.3: Low confidence (avoid trading or use minimal size)
- 0.3-0.6: Moderate confidence (standard position sizing)
- 0.6-0.8: High confidence (larger position sizing acceptable)
- 0.8-1.0: Very high confidence (use cautiously, beware overconfidence)
4. **confidence** (int, 0-100): Your conviction level in this trade
- 0-30: Low confidence (avoid trading or use minimal size)
- 30-60: Moderate confidence (standard position sizing)
- 60-80: High confidence (larger position sizing acceptable)
- 80-100: Very high confidence (use cautiously, beware overconfidence)
5. **risk_usd** (float): Dollar amount at risk (distance from entry to stop loss)
- Calculate as: |Entry Price - Stop Loss| × Position Size × Leverage