From af6f6d5930bfe5068d7defc9d133cfd5a6917330 Mon Sep 17 00:00:00 2001 From: shinchan-zhai Date: Wed, 25 Mar 2026 10:08:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20auto-reuse=20claw402=20wallet=20for=20n?= =?UTF-8?q?ofxos=20data=20=E2=80=94=20no=20extra=20config=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a trader uses claw402 as AI provider, the same wallet private key is now automatically used to route nofxos data API calls (AI500, OI, NetFlow, etc.) through claw402 payment as well. Users don't need to configure anything extra — if they already set up claw402 for AI, data APIs automatically go through claw402 too. --- kernel/engine.go | 16 ++++++++++++---- trader/auto_trader.go | 8 +++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/kernel/engine.go b/kernel/engine.go index 3fd95106..147cdceb 100644 --- a/kernel/engine.go +++ b/kernel/engine.go @@ -186,8 +186,9 @@ type StrategyEngine struct { nofxosClient *nofxos.Client } -// NewStrategyEngine creates strategy execution engine -func NewStrategyEngine(config *store.StrategyConfig) *StrategyEngine { +// NewStrategyEngine creates strategy execution engine. +// claw402WalletKey is optional — if provided, nofxos data requests are routed through claw402. +func NewStrategyEngine(config *store.StrategyConfig, claw402WalletKey ...string) *StrategyEngine { // Create NofxOS client with API key from config apiKey := config.Indicators.NofxOSAPIKey if apiKey == "" { @@ -195,8 +196,15 @@ func NewStrategyEngine(config *store.StrategyConfig) *StrategyEngine { } client := nofxos.NewClient(nofxos.DefaultBaseURL, apiKey) - // If claw402 wallet key is available, route nofxos requests through claw402 - if walletKey := os.Getenv("CLAW402_WALLET_KEY"); walletKey != "" { + // If claw402 wallet key is provided (from trader's AI config), route through claw402 + walletKey := "" + if len(claw402WalletKey) > 0 { + walletKey = claw402WalletKey[0] + } + if walletKey == "" { + walletKey = os.Getenv("CLAW402_WALLET_KEY") + } + if walletKey != "" { claw402URL := os.Getenv("CLAW402_URL") if claw402URL == "" { claw402URL = "https://claw402.ai" diff --git a/trader/auto_trader.go b/trader/auto_trader.go index 5874af02..42d6a13f 100644 --- a/trader/auto_trader.go +++ b/trader/auto_trader.go @@ -333,7 +333,13 @@ func NewAutoTrader(config AutoTraderConfig, st *store.Store, userID string) (*Au if config.StrategyConfig == nil { return nil, fmt.Errorf("[%s] strategy not configured", config.Name) } - strategyEngine := kernel.NewStrategyEngine(config.StrategyConfig) + // Pass claw402 wallet key to strategy engine so nofxos data requests + // are routed through claw402 (reuses the same wallet as AI calls) + var claw402Key string + if config.AIModel == "claw402" && config.CustomAPIKey != "" { + claw402Key = config.CustomAPIKey + } + strategyEngine := kernel.NewStrategyEngine(config.StrategyConfig, claw402Key) logger.Infof("✓ [%s] Using strategy engine (strategy configuration loaded)", config.Name) return &AutoTrader{