mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 00:07:01 +08:00
Improve(interface): replace some struct with interface for testing (#994)
* fix(trader): get peakPnlPct using posKey * fix(docs): keep readme at the same page * improve(interface): replace with interface * refactor mcp --------- Co-authored-by: zbhan <zbhan@freewheel.tv>
This commit is contained in:
@@ -85,8 +85,8 @@ type AutoTrader struct {
|
||||
exchange string // 交易平台名称
|
||||
config AutoTraderConfig
|
||||
trader Trader // 使用Trader接口(支持多平台)
|
||||
mcpClient *mcp.Client
|
||||
decisionLogger *logger.DecisionLogger // 决策日志记录器
|
||||
mcpClient mcp.AIClient
|
||||
decisionLogger logger.IDecisionLogger // 决策日志记录器
|
||||
initialBalance float64
|
||||
dailyPnL float64
|
||||
customPrompt string // 自定义交易策略prompt
|
||||
@@ -131,11 +131,12 @@ func NewAutoTrader(config AutoTraderConfig, database interface{}, userID string)
|
||||
// 初始化AI
|
||||
if config.AIModel == "custom" {
|
||||
// 使用自定义API
|
||||
mcpClient.SetCustomAPI(config.CustomAPIURL, config.CustomAPIKey, config.CustomModelName)
|
||||
mcpClient.SetAPIKey(config.CustomAPIKey, config.CustomAPIURL, config.CustomModelName)
|
||||
log.Printf("🤖 [%s] 使用自定义AI API: %s (模型: %s)", config.Name, config.CustomAPIURL, config.CustomModelName)
|
||||
} else if config.UseQwen || config.AIModel == "qwen" {
|
||||
// 使用Qwen (支持自定义URL和Model)
|
||||
mcpClient.SetQwenAPIKey(config.QwenKey, config.CustomAPIURL, config.CustomModelName)
|
||||
mcpClient = mcp.NewQwenClient()
|
||||
mcpClient.SetAPIKey(config.QwenKey, config.CustomAPIURL, config.CustomModelName)
|
||||
if config.CustomAPIURL != "" || config.CustomModelName != "" {
|
||||
log.Printf("🤖 [%s] 使用阿里云Qwen AI (自定义URL: %s, 模型: %s)", config.Name, config.CustomAPIURL, config.CustomModelName)
|
||||
} else {
|
||||
@@ -143,7 +144,8 @@ func NewAutoTrader(config AutoTraderConfig, database interface{}, userID string)
|
||||
}
|
||||
} else {
|
||||
// 默认使用DeepSeek (支持自定义URL和Model)
|
||||
mcpClient.SetDeepSeekAPIKey(config.DeepSeekKey, config.CustomAPIURL, config.CustomModelName)
|
||||
mcpClient = mcp.NewDeepSeekClient()
|
||||
mcpClient.SetAPIKey(config.DeepSeekKey, config.CustomAPIURL, config.CustomModelName)
|
||||
if config.CustomAPIURL != "" || config.CustomModelName != "" {
|
||||
log.Printf("🤖 [%s] 使用DeepSeek AI (自定义URL: %s, 模型: %s)", config.Name, config.CustomAPIURL, config.CustomModelName)
|
||||
} else {
|
||||
@@ -1205,7 +1207,7 @@ func (at *AutoTrader) GetSystemPromptTemplate() string {
|
||||
}
|
||||
|
||||
// GetDecisionLogger 获取决策日志记录器
|
||||
func (at *AutoTrader) GetDecisionLogger() *logger.DecisionLogger {
|
||||
func (at *AutoTrader) GetDecisionLogger() logger.IDecisionLogger {
|
||||
return at.decisionLogger
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ type AutoTraderTestSuite struct {
|
||||
// Mock 依赖
|
||||
mockTrader *MockTrader
|
||||
mockDB *MockDatabase
|
||||
mockLogger *logger.DecisionLogger
|
||||
mockLogger logger.IDecisionLogger
|
||||
|
||||
// gomonkey patches
|
||||
patches *gomonkey.Patches
|
||||
|
||||
Reference in New Issue
Block a user