fix: parse flat result_summary structure per updated API doc
The API result_summary is a flat object with top-level fields (total_positions, win_rate, profit_factor, net_pnl, sharpe_ratio, etc.) not a nested backtest_metadata/instruments map. This was causing all metrics to parse as None/zero for every completed run. - Rewrite BacktestResult::from_response() to read flat fields directly - Replace parse_ratio_value/parse_decimal_str with a single parse_number() that accepts both JSON numbers and decimal strings - Populate winning_positions, losing_positions, total_fees, avg_bars_in_trade (previously always None) - Simplify from_response signature — exchange/base/quote no longer needed - Add expected_count and coverage_pct to CandleCoverage struct - Update all example sell rules to use position_quantity instead of "0.01" - Note that "9999" is a valid sell-all alias (auto-capped by the API) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -107,6 +107,8 @@ Buy a fixed number of base units (semantic alias for a decimal string):
|
||||
```json
|
||||
{{"kind":"position_quantity"}}
|
||||
```
|
||||
Alternatively, `"9999"` works for exits: sell quantities are automatically capped to the open
|
||||
position size, so a large fixed number is equivalent to `position_quantity`.
|
||||
|
||||
NEVER use placeholder strings like `"ATR_SIZED"`, `"FULL_BALANCE"`, `"all"`, `"dynamic"` —
|
||||
these are rejected immediately.
|
||||
@@ -251,7 +253,7 @@ Common mistakes to NEVER make:
|
||||
}}
|
||||
]
|
||||
}},
|
||||
"then": {{"side": "sell", "quantity": "0.01"}}
|
||||
"then": {{"side": "sell", "quantity": {{"kind": "position_quantity"}}}}
|
||||
}}
|
||||
]
|
||||
}}
|
||||
@@ -302,7 +304,7 @@ Common mistakes to NEVER make:
|
||||
}}
|
||||
]
|
||||
}},
|
||||
"then": {{"side": "sell", "quantity": "0.01"}}
|
||||
"then": {{"side": "sell", "quantity": {{"kind": "position_quantity"}}}}
|
||||
}}
|
||||
]
|
||||
}}
|
||||
@@ -364,7 +366,7 @@ Common mistakes to NEVER make:
|
||||
}}
|
||||
]
|
||||
}},
|
||||
"then": {{"side": "sell", "quantity": "0.01"}}
|
||||
"then": {{"side": "sell", "quantity": {{"kind": "position_quantity"}}}}
|
||||
}}
|
||||
]
|
||||
}}
|
||||
@@ -449,7 +451,7 @@ The MACD line is `EMA(12) - EMA(26)`; the signal line is `EMA(9)` of the MACD li
|
||||
}}
|
||||
]
|
||||
}},
|
||||
"then": {{"side": "sell", "quantity": "0.01"}}
|
||||
"then": {{"side": "sell", "quantity": {{"kind": "position_quantity"}}}}
|
||||
}}
|
||||
]
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user