Skip to content

Conversation

@xqliu
Copy link
Contributor

@xqliu xqliu commented Nov 3, 2025

功能描述

在创建和编辑 Trader 时,支持配置 AI 扫描决策间隔(scan_interval_minutes),允许用户自定义 AI 决策的执行频率。

修改内容

后端修改 (api/server.go)

  1. CreateTraderRequest 添加 ScanIntervalMinutes 字段
  2. UpdateTraderRequest 添加 ScanIntervalMinutesSystemPromptTemplate 字段
  3. handleCreateTrader 处理扫描间隔默认值(默认 3 分钟)
  4. handleUpdateTrader 支持更新扫描间隔
  5. handleGetTraderConfig 返回结果中添加 scan_interval_minutes 字段

前端修改

类型定义 (web/src/types.ts)

  • CreateTraderRequest 添加 scan_interval_minutes? 可选字段
  • TraderConfigData 添加 scan_interval_minutes 必填字段

配置模态框 (web/src/components/TraderConfigModal.tsx)

  • 本地 TraderConfigData 接口添加 scan_interval_minutes
  • 初始状态设置默认值为 3 分钟
  • 添加 UI 输入框:
    • 范围:1-60 分钟
    • 步进:1 分钟
    • 建议范围提示:3-10 分钟
  • Label:"AI 扫描决策间隔 (分钟)"

交易员页面 (web/src/components/AITradersPage.tsx)

  • handleSaveEditTrader 的更新请求中添加 scan_interval_minutes

社区页面 (web/src/components/landing/CommunitySection.tsx)

  • 修复 TypeScript 编译错误:定义 CardProps 接口
  • 修正 TestimonialCard 组件的 prop 名称(authorauthorName

功能特性

  • ✅ 支持 1-60 分钟的自定义扫描间隔
  • ✅ 默认值为 3 分钟
  • ✅ UI 提供配置建议(3-10 分钟)
  • ✅ 创建和编辑 Trader 时均可配置
  • ✅ 后端自动验证和处理默认值
  • ✅ 修复前端 TypeScript 编译错误

界面截图

配置项位于 Trader 创建/编辑模态框中:

AI 扫描决策间隔 (分钟)  [  3  ]
建议: 3-10分钟

测试步骤

  1. ✅ 创建新 Trader,设置自定义扫描间隔(如 10 分钟)
  2. ✅ 验证 Trader 创建成功
  3. ✅ 编辑现有 Trader,修改扫描间隔为不同值(如 5 分钟)
  4. ✅ 验证修改保存成功,不再提示模型验证错误
  5. ✅ 确认 AI 决策按照新的间隔执行

依赖关系

本 PR 基于 #337 (修复编辑 Trader 时模型验证失败) 构建。

相关 Issue

Related to #335

xqliu added 3 commits November 3, 2025 21:17
Fixed critical bug where 4h kline data was incorrectly stored with
3m kline data, causing data mismatch.

Changes:
- Changed `m.klineDataMap4h.Store(s, klines)` to `klines4h`
- Updated log message to use `len(klines4h)` instead of `len(klines)`

This bug would cause 4h kline queries to return 3m data, leading to
incorrect technical indicator calculations.

Fixes: NoFxAiOS#260
Related: NoFxAiOS#176
## 问题描述
编辑 Trader 配置时,保存提示"AI模型配置不存在或未启用"错误。

## 根本原因
- 数据库存储的模型 ID 是完整格式(如 `admin_deepseek`)
- API 返回时将其转换为 provider 格式(`deepseek`)
- 前端 enabledModels 列表中是完整 ID
- 导致前端用 `deepseek` 查找 `admin_deepseek` 时失败

## 修复方案
移除 handleGetTraderConfig 中的模型 ID 转换逻辑,
返回完整的模型 ID,保持与前端模型列表格式一致。

Fixes NoFxAiOS#335
## 功能描述

在创建和编辑 Trader 时,支持配置 AI 扫描决策间隔(scan_interval_minutes),允许用户自定义 AI 决策的频率。

## 修改内容

### 后端修改 (api/server.go)

1. **CreateTraderRequest** 添加 `ScanIntervalMinutes` 字段
2. **UpdateTraderRequest** 添加 `ScanIntervalMinutes` 字段和 `SystemPromptTemplate` 字段
3. **handleCreateTrader** 处理扫描间隔默认值(默认 3 分钟)
4. **handleUpdateTrader** 支持更新扫描间隔
5. **handleGetTraderConfig** 返回中添加 `scan_interval_minutes` 字段

### 前端修改

#### web/src/types.ts
- `CreateTraderRequest` 添加 `scan_interval_minutes?` 可选字段
- `TraderConfigData` 添加 `scan_interval_minutes` 必填字段

#### web/src/components/TraderConfigModal.tsx
- 本地 `TraderConfigData` 接口添加 `scan_interval_minutes`
- 初始状态设置默认值为 3 分钟
- 添加 UI 输入框(范围 1-60 分钟)
- Label 优化为 "AI 扫描决策间隔 (分钟)"

#### web/src/components/AITradersPage.tsx
- `handleSaveEditTrader` 的更新请求中添加 `scan_interval_minutes`

#### web/src/components/landing/CommunitySection.tsx
- 修复 TypeScript 编译错误:定义 `CardProps` 接口
- 修正 `TestimonialCard` 组件的 prop 名称(author → authorName)

## 功能特性

- ✅ 支持 1-60 分钟的自定义间隔
- ✅ 默认值为 3 分钟
- ✅ UI 提示建议范围:3-10 分钟
- ✅ 创建和编辑时均支持配置
- ✅ 后端验证和处理默认值

## 测试步骤

1. 创建新 Trader,设置自定义扫描间隔(如 10 分钟)
2. 验证 Trader 创建成功
3. 编辑现有 Trader,修改扫描间隔
4. 验证修改保存成功
5. 确认 AI 决策按照新的间隔执行
@xqliu
Copy link
Contributor Author

xqliu commented Nov 3, 2025

功能实现详解

1. 后端实现

数据流程

用户输入 → CreateTraderRequest/UpdateTraderRequest 
         → 验证和默认值处理
         → 存储到数据库 (TraderRecord.ScanIntervalMinutes)
         → GetTraderConfig 返回给前端

关键代码片段

创建 Trader 时的默认值处理

scanIntervalMinutes := req.ScanIntervalMinutes
if scanIntervalMinutes <= 0 {
    scanIntervalMinutes = 3 // 默认3分钟
}

更新 Trader 时保持原值

scanIntervalMinutes := req.ScanIntervalMinutes
if scanIntervalMinutes <= 0 {
    scanIntervalMinutes = existingTrader.ScanIntervalMinutes // 保持原值
}

2. 前端实现

UI 设计

  • 输入类型: 数字输入框 (type="number")
  • 范围限制: min=1, max=60, step=1
  • 默认值: 3 分钟
  • 提示文案: "建议: 3-10分钟"
  • 标签优化: "AI 扫描决策间隔 (分钟)" (比原来的 "扫描间隔" 更明确)

状态管理

const [formData, setFormData] = useState<TraderConfigData>({
  // ... 其他字段
  scan_interval_minutes: 3,  // 默认值
});

3. 额外修复

本 PR 还修复了一个阻塞前端编译的 TypeScript 错误:

CommunitySection.tsx:

  • 定义了缺失的 CardProps 接口
  • 修正了 TestimonialCard 组件的 prop 名称不一致问题

4. 使用场景

场景 推荐间隔 说明
高频交易 3-5 分钟 快速响应市场变化
常规交易 5-10 分钟 平衡决策质量和成本
保守交易 10-30 分钟 降低交易频率和成本
观察模式 30-60 分钟 长周期观察和决策

5. 测试清单

  • 创建 Trader:设置自定义间隔
  • 编辑 Trader:修改间隔值
  • 默认值:不输入时使用 3 分钟
  • 边界值:测试 1 分钟和 60 分钟
  • 保存验证:确认数据正确保存和读取
  • 前端编译:TypeScript 无错误
  • 构建成功:Docker 镜像正常构建

6. 依赖说明

本 PR 依赖 #337(修复模型验证):

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

🤖 Advisory Check Results

These are advisory checks to help improve code quality. They won't block your PR from being merged.

Note: PR title and size checks are handled by the main workflow and may appear in a separate comment.

🔧 Backend Checks

Go Formatting: ⚠️ Needs formatting

Files needing formatting
api/server.go
auth/auth.go
manager/trader_manager.go
trader/aster_trader.go
trader/auto_trader.go
trader/binance_futures.go
trader/hyperliquid_trader.go

Go Vet: ✅ Good
Tests: ✅ Passed

Fix locally:

go fmt ./...      # Format code
go vet ./...      # Check for issues
go test ./...     # Run tests

⚛️ Frontend Checks

Build & Type Check: ✅ Success

Fix locally:

cd web
npm run build  # Test build (includes type checking)

📖 Resources

Questions? Feel free to ask in the comments! 🙏


These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml.

将 SystemPromptTemplate 功能从扫描间隔 PR 中分离出来,
保持 PR 单一职责。

SystemPromptTemplate 功能将在单独的 PR 中处理。
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

🤖 Advisory Check Results

These are advisory checks to help improve code quality. They won't block your PR from being merged.

Note: PR title and size checks are handled by the main workflow and may appear in a separate comment.

🔧 Backend Checks

Go Formatting: ⚠️ Needs formatting

Files needing formatting
api/server.go
auth/auth.go
manager/trader_manager.go
trader/aster_trader.go
trader/auto_trader.go
trader/binance_futures.go
trader/hyperliquid_trader.go

Go Vet: ✅ Good
Tests: ✅ Passed

Fix locally:

go fmt ./...      # Format code
go vet ./...      # Check for issues
go test ./...     # Run tests

⚛️ Frontend Checks

Build & Type Check: ✅ Success

Fix locally:

cd web
npm run build  # Test build (includes type checking)

📖 Resources

Questions? Feel free to ask in the comments! 🙏


These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml.

@xqliu
Copy link
Contributor Author

xqliu commented Nov 3, 2025

✅ 更新:移除 SystemPromptTemplate

已从本 PR 中移除 SystemPromptTemplate 相关修改,以保持 PR 的单一职责。

Revert Commit: 8ad85a4

原因

  1. 单一职责原则:本 PR 专注于扫描间隔配置功能
  2. 更易 Review:减少不相关的代码变更
  3. 独立测试:两个功能可以独立测试和验证

SystemPromptTemplate 功能

已在独立的 PR #339 中处理,包含:

  • 完整的功能说明
  • 使用场景分析
  • 独立的测试计划

本 PR 当前内容

现在本 PR 仅包含:

@SkywalkerJi SkywalkerJi merged commit df83a87 into NoFxAiOS:dev Nov 3, 2025
8 of 10 checks passed
zhouyongyou added a commit to zhouyongyou/nofx that referenced this pull request Nov 3, 2025
- Allow users to customize AI decision scan interval (1-60 minutes)
- Default 3 minutes, recommended range 3-10 minutes
- Support both high-frequency and low-frequency trading strategies
- Improve trading flexibility and API call efficiency
- Merge with existing actual balance query functionality
ForeverInLaw pushed a commit to ForeverInLaw/nofx that referenced this pull request Nov 8, 2025
…fig-v2

feat: 添加 AI 扫描决策间隔配置支持
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants