mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-18 18:04:32 +08:00
feat(trader): add claw402 wallet key resolution for trader configuration
Implemented a new method, `resolveTraderDataWalletKey`, to retrieve the claw402 wallet key based on the selected AI model and user ID. This enhancement allows for better integration of the claw402 model within the trader configuration, ensuring that the correct wallet key is used for trading operations. The `AutoTraderConfig` struct has been updated to include the new `Claw402WalletKey` field, improving the overall handling of wallet keys in the trading process.
This commit is contained in:
@@ -703,6 +703,8 @@ func (tm *TraderManager) addTraderFromStore(traderCfg *store.Trader, aiModelCfg
|
|||||||
traderConfig.CustomAPIKey = string(aiModelCfg.APIKey)
|
traderConfig.CustomAPIKey = string(aiModelCfg.APIKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
traderConfig.Claw402WalletKey = resolveTraderDataWalletKey(st, traderCfg.UserID, aiModelCfg)
|
||||||
|
|
||||||
// Create trader instance
|
// Create trader instance
|
||||||
at, err := trader.NewAutoTrader(traderConfig, st, traderCfg.UserID)
|
at, err := trader.NewAutoTrader(traderConfig, st, traderCfg.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -741,3 +743,31 @@ func (tm *TraderManager) addTraderFromStore(traderCfg *store.Trader, aiModelCfg
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resolveTraderDataWalletKey(st *store.Store, userID string, selectedModel *store.AIModel) string {
|
||||||
|
if selectedModel != nil && selectedModel.Provider == "claw402" {
|
||||||
|
if walletKey := string(selectedModel.APIKey); walletKey != "" {
|
||||||
|
return walletKey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if st == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
models, err := st.AIModel().List(userID)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warnf("⚠️ Failed to load claw402 wallet for trader data routing: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, model := range models {
|
||||||
|
if model == nil || model.Provider != "claw402" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if walletKey := string(model.APIKey); walletKey != "" {
|
||||||
|
return walletKey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ package trader
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"nofx/kernel"
|
"nofx/kernel"
|
||||||
"nofx/logger"
|
"nofx/logger"
|
||||||
"nofx/mcp"
|
"nofx/mcp"
|
||||||
_ "nofx/mcp/payment"
|
_ "nofx/mcp/payment"
|
||||||
_ "nofx/mcp/provider"
|
_ "nofx/mcp/provider"
|
||||||
"nofx/store"
|
"nofx/store"
|
||||||
"nofx/wallet"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"nofx/trader/aster"
|
"nofx/trader/aster"
|
||||||
"nofx/trader/binance"
|
"nofx/trader/binance"
|
||||||
"nofx/trader/bitget"
|
"nofx/trader/bitget"
|
||||||
@@ -20,6 +19,7 @@ import (
|
|||||||
"nofx/trader/kucoin"
|
"nofx/trader/kucoin"
|
||||||
"nofx/trader/lighter"
|
"nofx/trader/lighter"
|
||||||
"nofx/trader/okx"
|
"nofx/trader/okx"
|
||||||
|
"nofx/wallet"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -93,6 +93,7 @@ type AutoTraderConfig struct {
|
|||||||
CustomAPIURL string
|
CustomAPIURL string
|
||||||
CustomAPIKey string
|
CustomAPIKey string
|
||||||
CustomModelName string
|
CustomModelName string
|
||||||
|
Claw402WalletKey string
|
||||||
|
|
||||||
// Scan configuration
|
// Scan configuration
|
||||||
ScanInterval time.Duration // Scan interval (recommended 3 minutes)
|
ScanInterval time.Duration // Scan interval (recommended 3 minutes)
|
||||||
@@ -335,8 +336,8 @@ func NewAutoTrader(config AutoTraderConfig, st *store.Store, userID string) (*Au
|
|||||||
}
|
}
|
||||||
// Pass claw402 wallet key to strategy engine so nofxos data requests
|
// Pass claw402 wallet key to strategy engine so nofxos data requests
|
||||||
// are routed through claw402 (reuses the same wallet as AI calls)
|
// are routed through claw402 (reuses the same wallet as AI calls)
|
||||||
var claw402Key string
|
claw402Key := config.Claw402WalletKey
|
||||||
if config.AIModel == "claw402" && config.CustomAPIKey != "" {
|
if claw402Key == "" && config.AIModel == "claw402" && config.CustomAPIKey != "" {
|
||||||
claw402Key = config.CustomAPIKey
|
claw402Key = config.CustomAPIKey
|
||||||
}
|
}
|
||||||
strategyEngine := kernel.NewStrategyEngine(config.StrategyConfig, claw402Key)
|
strategyEngine := kernel.NewStrategyEngine(config.StrategyConfig, claw402Key)
|
||||||
|
|||||||
Reference in New Issue
Block a user