feat: simplify Claw402 autopilot trading flow

This commit is contained in:
tinkle-community
2026-06-27 00:37:59 +08:00
parent 961e016d33
commit 24f6421a73
151 changed files with 7453 additions and 41117 deletions

View File

@@ -7,7 +7,7 @@ import (
"nofx/store"
)
func TestCreateDefaultStrategiesUsesReadyToRunUSStockPresets(t *testing.T) {
func TestCreateDefaultStrategiesUsesOneReadyToRunClaw402Preset(t *testing.T) {
st, err := store.New(t.TempDir() + "/nofx.db")
if err != nil {
t.Fatalf("store.New failed: %v", err)
@@ -24,8 +24,8 @@ func TestCreateDefaultStrategiesUsesReadyToRunUSStockPresets(t *testing.T) {
if err != nil {
t.Fatalf("List strategies failed: %v", err)
}
if len(strategies) != 3 {
t.Fatalf("expected 3 default strategies, got %d", len(strategies))
if len(strategies) != 1 {
t.Fatalf("expected 1 default strategy, got %d", len(strategies))
}
byName := map[string]*store.Strategy{}
@@ -43,40 +43,22 @@ func TestCreateDefaultStrategiesUsesReadyToRunUSStockPresets(t *testing.T) {
t.Fatalf("expected exactly one active strategy, got %d", activeCount)
}
trend := byName["美股趋势策略"]
if trend == nil || !trend.IsActive {
t.Fatalf("美股趋势策略 should exist and be active")
defaultStrategy := byName["NOFX Claw402 自动策略"]
if defaultStrategy == nil || !defaultStrategy.IsActive {
t.Fatalf("NOFX Claw402 自动策略 should exist and be active")
}
trendCfg, err := trend.ParseConfig()
trendCfg, err := defaultStrategy.ParseConfig()
if err != nil {
t.Fatalf("trend ParseConfig failed: %v", err)
t.Fatalf("default ParseConfig failed: %v", err)
}
if trendCfg.CoinSource.SourceType != "hyper_rank" || trendCfg.CoinSource.HyperRankCategory != "stock" || trendCfg.CoinSource.HyperRankDirection != "volume" {
t.Fatalf("trend strategy should use Hyperliquid stock volume ranking, got %+v", trendCfg.CoinSource)
if trendCfg.CoinSource.SourceType != "vergex_signal" || trendCfg.CoinSource.VergexLimit != 10 || trendCfg.CoinSource.VergexMarketType != "all" {
t.Fatalf("default strategy should use the Claw402/Vergex all-market signal ranking, got %+v", trendCfg.CoinSource)
}
if trendCfg.CoinSource.UseAI500 || trendCfg.RiskControl.MaxPositions > 2 || trendCfg.RiskControl.MaxMarginUsage > 0.45 {
t.Fatalf("trend strategy should be low-risk Hyperliquid native, got coin=%+v risk=%+v", trendCfg.CoinSource, trendCfg.RiskControl)
t.Fatalf("default strategy should be low-risk Claw402/Vergex native, got coin=%+v risk=%+v", trendCfg.CoinSource, trendCfg.RiskControl)
}
megaCap := byName["美股大盘稳健策略"]
if megaCap == nil {
t.Fatalf("美股大盘稳健策略 should exist")
}
megaCfg, err := megaCap.ParseConfig()
if err != nil {
t.Fatalf("megaCap ParseConfig failed: %v", err)
}
if megaCfg.CoinSource.SourceType != "static" {
t.Fatalf("mega-cap strategy should use static stock symbols, got %+v", megaCfg.CoinSource)
}
wantSymbols := []string{"AAPL-USDC", "MSFT-USDC", "GOOGL-USDC", "AMZN-USDC", "META-USDC"}
if len(megaCfg.CoinSource.StaticCoins) != len(wantSymbols) {
t.Fatalf("unexpected static stock list: %+v", megaCfg.CoinSource.StaticCoins)
}
for i, want := range wantSymbols {
if megaCfg.CoinSource.StaticCoins[i] != want {
t.Fatalf("static stock %d: want %s got %s", i, want, megaCfg.CoinSource.StaticCoins[i])
}
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)
}
}
@@ -140,10 +122,8 @@ func TestCreateDefaultStrategiesMigratesLegacyPresetsWithoutOverridingActiveCust
if byName["均衡策略"] != 0 {
t.Fatalf("legacy preset should be removed, got names=%+v", byName)
}
for _, name := range []string{"美股趋势策略", "美股大盘稳健策略", "美股突破策略"} {
if byName[name] != 1 {
t.Fatalf("expected exactly one %s, got names=%+v", name, byName)
}
if byName["NOFX Claw402 自动策略"] != 1 {
t.Fatalf("expected exactly one NOFX Claw402 自动策略, got names=%+v", byName)
}
if len(activeNames) != 1 || activeNames[0] != "aa" {
t.Fatalf("existing active custom strategy should stay the only active one, got %+v", activeNames)