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{