feat: position sizing follows the strategy config — default 4x equity notional

Positions were stuck at ~equity×1.2 (~$420 on a $500 account) no matter
what the strategy said: both the manager load path and the per-cycle config
reload hardcoded vergex strategies to a 6-position × equity×1.2 book,
silently overriding the configured 10x ratio. Both overrides removed —
sizing now comes from the strategy's own RiskControl (ClampLimits bounds it,
margin auto-reduce keeps the book solvent).

Defaults aligned across all three config sources (backend default template,
quick-create preset, studio unified config): 2 positions × 4x equity
notional at 10x leverage ≈ 80% margin when both are open — concentrated per
the operator's request. Live strategy updated via relaunch; loader log
confirms maxPos=2 posRatio=4.0.
This commit is contained in:
tinkle-community
2026-07-10 19:12:52 +09:00
parent 8c8cd9b61f
commit 7a66d048f3
6 changed files with 23 additions and 28 deletions

View File

@@ -265,8 +265,10 @@ func (s *Server) createDefaultStrategies(userID string, lang string) error {
c.RiskControl.MaxPositions = 2
c.RiskControl.BTCETHMaxLeverage = 10
c.RiskControl.AltcoinMaxLeverage = 10
c.RiskControl.BTCETHMaxPositionValueRatio = 10.0
c.RiskControl.AltcoinMaxPositionValueRatio = 10.0
// 4× equity notional per position: at 10x leverage two full positions
// use ~80% of margin — concentrated but solvent.
c.RiskControl.BTCETHMaxPositionValueRatio = 4.0
c.RiskControl.AltcoinMaxPositionValueRatio = 4.0
c.RiskControl.MaxMarginUsage = 1.0
c.RiskControl.MinConfidence = 78
c.RiskControl.MinRiskRewardRatio = 3.0

View File

@@ -60,10 +60,10 @@ func TestCreateDefaultStrategiesUsesOneReadyToRunClaw402Preset(t *testing.T) {
if trendCfg.RiskControl.BTCETHMaxLeverage != 10 || trendCfg.RiskControl.AltcoinMaxLeverage != 10 {
t.Fatalf("default strategy should use 10x leverage for all Claw402 opens, got risk=%+v", trendCfg.RiskControl)
}
if trendCfg.RiskControl.BTCETHMaxPositionValueRatio != 10 ||
trendCfg.RiskControl.AltcoinMaxPositionValueRatio != 10 ||
if trendCfg.RiskControl.BTCETHMaxPositionValueRatio != 4 ||
trendCfg.RiskControl.AltcoinMaxPositionValueRatio != 4 ||
trendCfg.RiskControl.MaxMarginUsage != 1.0 {
t.Fatalf("default strategy should use full-size 10x notional for Claw402 opens, got risk=%+v", trendCfg.RiskControl)
t.Fatalf("default strategy should size Claw402 opens at 4x equity notional (two positions ≈ 80%% margin at 10x), got risk=%+v", trendCfg.RiskControl)
}
}

View File

@@ -658,15 +658,10 @@ func (tm *TraderManager) addTraderFromStore(traderCfg *store.Trader, aiModelCfg
return fmt.Errorf("failed to parse strategy config for trader %s: %w", traderCfg.Name, err)
}
strategyConfig.ClampLimits()
// Autopilot (vergex_signal/claw402) runs a balanced multi-position book:
// hold several instruments with a smaller per-position notional so multiple
// long/short positions fit the margin. Applied after ClampLimits so it is
// not capped back to the conservative single-position default.
if strategyConfig.CoinSource.SourceType == "vergex_signal" {
strategyConfig.RiskControl.MaxPositions = 6
strategyConfig.RiskControl.BTCETHMaxPositionValueRatio = 1.2
strategyConfig.RiskControl.AltcoinMaxPositionValueRatio = 1.2
}
// Sizing comes from the strategy's own RiskControl (a hardcoded
// 6-position × equity×1.2 override used to live here, silently ignoring
// the user's configuration). ClampLimits bounds the values and the
// margin auto-reduce at order time keeps the book solvent.
logger.Infof("✓ Trader %s loaded strategy config: %s (maxPos=%d, posRatio=%.1f)", traderCfg.Name, strategy.Name, strategyConfig.RiskControl.MaxPositions, strategyConfig.RiskControl.AltcoinMaxPositionValueRatio)
ensureHyperliquidNativeStrategy(traderCfg.Name, exchangeCfg.ExchangeType, strategyConfig)
} else {

View File

@@ -1014,11 +1014,11 @@ func GetDefaultStrategyConfig(lang string) StrategyConfig {
PriceRankingLimit: 10,
},
RiskControl: RiskControlConfig{
MaxPositions: 6, // Hold up to 6 instruments (≈3 long + 3 short) simultaneously (CODE ENFORCED)
MaxPositions: 2, // Concentrated book: two full-size positions (CODE ENFORCED)
BTCETHMaxLeverage: 10, // BTC/ETH exchange leverage (AI guided)
AltcoinMaxLeverage: 10, // TradeFi exchange leverage (AI guided)
BTCETHMaxPositionValueRatio: 1.2, // Per-position notional = equity × 1.2 so several positions fit the margin
AltcoinMaxPositionValueRatio: 1.2, // Per-position notional = equity × 1.2 so several positions fit the margin
BTCETHMaxPositionValueRatio: 4.0, // Per-position notional = equity × 4; at 10x two positions ≈ 80% margin
AltcoinMaxPositionValueRatio: 4.0, // Per-position notional = equity × 4; at 10x two positions ≈ 80% margin
MaxMarginUsage: 1.0, // Claw402 Autopilot intentionally uses full margin when opening
MinPositionSize: 12, // Min 12 USDT per position (CODE ENFORCED)
MinRiskRewardRatio: 3.0, // Min 3:1 profit/loss ratio (AI guided)

View File

@@ -422,15 +422,11 @@ func (at *AutoTrader) reloadStrategyConfigIfChanged() error {
}
strategyConfig.ClampLimits()
// Autopilot (vergex_signal/claw402) runs a balanced multi-position book:
// hold several instruments at once with a smaller per-position notional so
// multiple long/short positions fit the margin. Applied after ClampLimits so
// the book size is not capped back down to the conservative default.
if strategyConfig.CoinSource.SourceType == "vergex_signal" {
strategyConfig.RiskControl.MaxPositions = 6
strategyConfig.RiskControl.BTCETHMaxPositionValueRatio = 1.2
strategyConfig.RiskControl.AltcoinMaxPositionValueRatio = 1.2
}
// NOTE: this used to hardcode the Autopilot book shape (6 positions ×
// equity×1.2 notional), silently overriding whatever the user configured in
// their strategy. Sizing now comes from the strategy's own RiskControl —
// ClampLimits above bounds it (ratio 0.510, leverage caps), and the
// margin auto-reduce at order time keeps the book solvent.
claw402Key := at.config.Claw402WalletKey
if claw402Key == "" && at.config.AIModel == "claw402" && at.config.CustomAPIKey != "" {

View File

@@ -1391,8 +1391,10 @@ export function StrategyStudioPage() {
max_positions: 2,
btc_eth_max_leverage: 10,
altcoin_max_leverage: 10,
btc_eth_max_position_value_ratio: 10,
altcoin_max_position_value_ratio: 10,
// 4× equity notional per position — at 10x leverage two full
// positions use ~80% of margin (concentrated but solvent)
btc_eth_max_position_value_ratio: 4,
altcoin_max_position_value_ratio: 4,
max_margin_usage: 1.0,
min_confidence: 78,
min_risk_reward_ratio: 3,