Commit Graph

224 Commits

Author SHA1 Message Date
ZhouYongyou
04419b47e6 fix: 修复编辑交易员时「AI模型配置不存在或未启用」错误
问题:
- 编辑交易员并修改系统提示词模板时,保存失败
- 错误提示:AI模型配置不存在或未启用

根本原因:
1. 后端 API 返回的 ai_model 被截断(admin_deepseek → deepseek)
2. 前端验证时找不到对应的模型 ID(enabledModels 存的是完整 ID)
3. API 缺少 system_prompt_template 字段

修复内容:
- api/server.go: 移除 AI model ID 截断逻辑,返回完整 ID
- api/server.go: 在 handleGetTraderConfig 中添加 system_prompt_template 字段
- web/src/types.ts: TraderConfigData 接口添加 system_prompt_template 字段
- web/src/components/AITradersPage.tsx: 添加 fallback 机制和详细日志

测试:
- 编辑交易员 → 修改系统提示词模板 → 保存成功
- Console 输出验证日志,不再报错
2025-11-02 04:51:30 +08:00
ZhouYongyou
8faa2b3494 refactor: 恢復模板加載失敗時的簡化版本 fallback
## 問題
之前修改將模板加載失敗時改為返回空字符串,但:
- 上層函數沒有檢測空字符串的邏輯
- 空字符串會直接傳給 AI API,導致錯誤
- 極端情況下系統無法運行

## 解決方案
恢復原始邏輯,保留內置簡化版本作為最後防線:
```
用戶模板失敗 → default 失敗 → 使用內置簡化版本
"你是专业的加密货币交易AI。请根据市场数据做出交易决策。"
```

## 差異對比
### 之前(不安全)
```go
if default 加載失敗 {
    return ""  //  上層未檢測,會傳空字符串給 AI
}
```

### 現在(安全)
```go
if default 加載失敗 {
    sb.WriteString("你是专业的加密货币交易AI。请根据市场数据做出交易决策。\n\n")
    //  有最後防線,極端情況下仍能運行
}
```

## 測試驗證
-  Go 編譯成功
-  Docker build 成功
-  邏輯恢復到原始穩定版本

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 01:27:44 +08:00
ZhouYongyou
1fb5ecb89c chore: 移除未實現功能的設計文檔
DYNAMIC_TP_SL_PROPOSAL.md 是動態止盈止損功能的設計文檔,
但功能尚未實現,保留在代碼庫中可能造成困擾(誤以為已完成)。

當需要實現該功能時,可以從 git 歷史中恢復(commit bac5744)。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 01:23:47 +08:00
ZhouYongyou
bac5744039 refactor: 移除 engine.go 冗餘硬編碼策略,優化模板系統
## 問題
用戶反饋:「怎麼 engine.go 還寫入了這些?... 有必要嗎?」

**根本原因**:
- prompts/ 目錄下已有 default.txt (114行) 和 adaptive.txt (259行)
- engine.go 卻硬編碼了 183 行 adaptive 策略作為 fallback
- 這導致:
  1. 重複維護兩份相同的策略內容
  2. templateLoaded 標記多餘(模板系統本身已有 fallback)
  3. 如果 default.txt 都加載失敗,說明文件系統有嚴重問題,不應繼續交易

## 解決方案

### 1. 移除冗餘硬編碼
- 刪除 183 行硬編碼 adaptive 策略(271-453 行)
- 移除 templateLoaded 標記及其邏輯

### 2. 簡化模板加載邏輯
```go
// 之前(複雜)
templateLoaded := false
if 模板加載成功 {
    templateLoaded = true
}
if !templateLoaded {
    追加 183 行硬編碼策略  //  冗餘
}

// 現在(簡潔)
if 用戶模板加載失敗 {
    嘗試 default.txt  //  已經是 fallback
}
if default.txt 也失敗 {
    返回空字符串,上層應停止交易  //  安全
}
```

### 3. 新增動態止盈止損設計文檔
創建 `DYNAMIC_TP_SL_PROPOSAL.md`,記錄:
- 用戶反饋:「建议加个 adjust tp sl 或者给 close 加个 quantity」
- 問題分析:策略提到追蹤止損,但 AI 無法執行
- 解決方案:添加 `adjust_stop_loss`, `adjust_take_profit`, `partial_close` actions
- 實施步驟:修改 Decision 結構、執行邏輯、模板說明

## 測試驗證
-  Go 編譯成功
-  Docker build 成功
-  模板系統邏輯清晰(用戶模板 → default → 報錯)
-  代碼減少 183 行(更易維護)

## 檔案變更
- `decision/engine.go`: -183 行硬編碼策略
- `DYNAMIC_TP_SL_PROPOSAL.md`: +300 行設計文檔

## 後續工作
- [ ] 實現 adjust_stop_loss action
- [ ] 實現 partial_close action
- [ ] 更新模板文件說明新 actions

---

感謝 @user 指出這個設計缺陷!🙏

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 01:18:57 +08:00
ZhouYongyou
a2411d2843 refactor: 優化 engine.go 模板加載邏輯,避免策略重複
## 問題
- 之前邏輯:加載模板 → 無條件追加硬編碼策略
- 結果:選擇 adaptive 模板時,會收到重複的策略內容
  * adaptive.txt: 259 行
  * 硬編碼: 184 行
  * 總計:443 行重複指導 

## 解決方案
使用 templateLoaded 標記追蹤模板加載狀態:
-  模板成功 → 使用模板,跳過硬編碼
-  模板失敗 → 使用硬編碼作為 fallback

## 變更內容
1. 添加 templateLoaded bool 變量
2. 硬編碼策略包裹在 `if !templateLoaded {}` 中(277-463 行)
3. 硬約束和輸出格式始終追加(不受影響)
4. 添加日誌追蹤模板使用情況

## 測試驗證
-  Go 編譯成功
-  Docker build 成功
-  向後兼容(模板失敗時回退到硬編碼)

## 架構改進
```
加載流程:
1. 嘗試加載指定模板(如 adaptive)
2. 失敗 → 嘗試 default
3. 仍失敗 → 使用硬編碼
4. 追加硬約束(動態生成)
5. 追加輸出格式(動態生成)
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 01:09:37 +08:00
ZhouYongyou
b908fac92f feat: 創建 adaptive.txt 自適應雙策略模板
新增 prompts/adaptive.txt 模板,包含:

## 核心特性
- 市場狀態判斷(震盪/趨勢,多指標交叉驗證)
- 雙策略系統:
  * 策略 A: 震盪交易(高勝率低盈虧比)
  * 策略 B: 趨勢跟隨(中等勝率高盈虧比)
- 技術位優先止盈機制(EMA20、前高前低、整數關口)
- 動態追踪止損(鎖定利潤,避免回撤)
- 夏普比率自我進化(交易質量 > 交易頻率)

## 使用方式
用戶可在 Web UI 選擇此模板,或繼續使用 default/nof1

## 技術實現
- 259 行完整策略指導
- 與現有模板系統兼容
- engine.go 保留硬編碼作為 fallback

相關文檔:TEMPLATE_MIGRATION_PLAN.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 01:06:11 +08:00
ZhouYongyou
6553b81b94 fix: config.json.example 缺少 coin_pool_api_url 和 oi_top_api_url 字段
- 问题:config.json.example 与 main.go 的 ConfigFile 结构不一致
- 影响:新用户复制 example 时会缺少必要的配置字段
- 修复:添加 coin_pool_api_url 和 oi_top_api_url(空字符串)

相关提交:517d0ca (admin_mode config)
2025-11-02 00:40:21 +08:00
ZhouYongyou
b1e4a7598a fix: 修复中文引号导致的 Go 编译错误
问题:
- Go 语言不识别中文双引号 ""
- 导致编译失败:syntax error: unexpected name

修复:
- 将所有中文双引号 "" 替换为英文单引号 ''
- 影响行:287, 365-369

错误示例:
- 错误:"趋势市场"
- 正确:'趋势市场'

🤖 Generated with Claude Code
2025-11-02 00:25:25 +08:00
ZhouYongyou
a58be23a29 fix: 修正盈亏百分比计算错误(未考虑杠杆)
问题:
- 旧算法只计算价格变化百分比,未考虑杠杆倍数
- 例:10倍杠杆,价格涨1% → 显示+1%(错误),实际应该是+10%
- 导致 AI 收到错误的盈亏数据,影响决策

修复:
- 使用实际盈亏除以保证金计算百分比
- 公式:pnlPct = (unrealizedPnl / marginUsed) * 100
- 优点:
  ✓ 考虑杠杆倍数
  ✓ 使用 API 提供的实际盈亏(含手续费、资金费率)
  ✓ 更准确反映真实盈亏百分比

示例对比:
- 入场:100,000,当前:101,000(+1%),10倍杠杆
- 旧算法:显示 +1%(错误)
- 新算法:显示 +10%(正确)

感谢用户反馈 @1711z

🤖 Generated with Claude Code
2025-11-02 00:23:59 +08:00
Z
f02c5df2b6 Merge branch 'tinkle-community:dev' into dev 2025-11-02 00:08:58 +08:00
ZhouYongyou
88a7055561 feat: 添加技术位优先止盈 + 追踪止损(阶段1)
解决问题:
- 固定百分比止盈经常在技术位前回撤
- 浮盈没有保护机制,从 +1.5% 回撤到止损

核心改进:
1. 技术位优先止盈:
   - 震荡策略:技术位 < 2% → 止盈设在技术位前 0.1%
   - 趋势策略:技术位 < 5% → 止盈设在技术位前 0.2%
   - 技术位识别:EMA20、最近高低点、整数关口

2. 追踪止损机制:
   - 震荡:浮盈 0.8% → 止损移到成本价,浮盈 1.2% → 止损移到 +0.5%
   - 趋势:浮盈 2% → 止损移到成本价,浮盈 5% → 止损移到 +2.5%
   - 价格接近技术位 → 主动平仓避免回撤

3. 分批止盈预留:
   - 趋势策略:技术位在 5-10% → 分两批止盈
   - 为阶段2分批止盈做准备

预期效果:
- 减少"快到止盈就回撤"的情况
- 锁定浮盈,避免全部回撤
- 提高实际盈亏比

实施方式:纯提示词改进,基于已有数据(EMA20、K线高低点)

🤖 Generated with Claude Code
2025-11-02 00:03:20 +08:00
SkywalkerJi
6c03d247e1 Docker port mapping prompts. 2025-11-02 00:03:19 +08:00
tinkle-community
775446d939 Merge pull request #201 from SkywalkerJi/dev
Mapping the prompts folder in Docker.
2025-11-01 22:33:30 +08:00
SkywalkerJi
24a9a4b2a3 Merge remote-tracking branch 'refs/remotes/origin/dev' into dev 2025-11-01 22:31:09 +08:00
SkywalkerJi
cee927a46d Docker port mapping prompts. 2025-11-01 22:28:49 +08:00
Z
e51cbf4092 Merge branch 'tinkle-community:dev' into dev 2025-11-01 21:03:57 +08:00
ZhouYongyou
e708c99db2 feat: 添加自适应双策略系统(震荡 + 趋势)
根据 ADAPTIVE_STRATEGY_DESIGN.md 方案 A(简单版)实现:

新增功能:
1. 市场状态判断(3个指标交叉验证):
   - 多时间框架一致性(15m/1h/4h MACD 方向)
   - 价格波动率(最近 10 根 K线波动幅度)
   - 买卖压力极端值(BuySellRatio 连续性)

2. 双策略系统:
   - 策略 A(震荡交易):止盈 1-2%,止损 0.8-1%,盈亏比 1:1.5-1:2
   - 策略 B(趋势跟随):止盈 5-10%,止损 1.5-2%,盈亏比 1:3-1:5

3. 策略选择指导:AI 必须在思维链中明确说明市场状态判断和策略选择

改进效果:
- 让 AI 根据市场状态动态调整止盈止损
- 震荡市场快进快出,趋势市场让利润奔跑
- 预期提升胜率和盈亏比,降低最大回撤

实施方式:纯提示词改进(无代码变更),耗时 30 分钟

🤖 Generated with Claude Code
2025-11-01 20:40:31 +08:00
tinkle-community
17c927b04a Merge pull request #194 from Icyoung/dev
Remote auth for prompt templates
2025-11-01 20:34:32 +08:00
tinkle-community
37dff0b3f0 Merge pull request #192 from Icyoung/dev
Dev Bug fix
2025-11-01 20:28:06 +08:00
icy
2cc91d1701 Remote auth for prompt templates 2025-11-01 20:25:55 +08:00
Z
4fbb4ecea5 Merge branch 'dev' into dev 2025-11-01 20:17:20 +08:00
icy
2538d2f928 Merge branch 'dev' of https://github.com/tinkle-community/nofx 2025-11-01 20:09:17 +08:00
tinkle-community
6659625da1 Merge pull request #189 from SkywalkerJi/dev
Supports custom system prompts and custom models.
2025-11-01 19:49:26 +08:00
SkywalkerJi
798133e479 Merge branch 'tinkle-community:dev' into dev 2025-11-01 20:46:33 +09:00
SkywalkerJi
4250c11ddf Supports custom system prompts and custom models. 2025-11-01 19:45:54 +08:00
icy
01ee3d57d9 Fixed i18n lint 2025-11-01 19:39:27 +08:00
icy
996b152eba Resolve merge conflicts in AITradersPage.tsx
- Fixed import statement conflict (using 'type Language')
- Merged exchange configuration logic preserving support for multiple exchange types
- Kept comprehensive form handling for Binance, Hyperliquid, Aster, and OKX exchanges
- Updated security warning messages to use proper translation keys

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 19:01:44 +08:00
icy
f413f87f39 Fixed health check; Fixed dex config; Add rank trader info view; 2025-11-01 18:58:32 +08:00
SkywalkerJi
5be7106eb2 Rename the model. 2025-11-01 17:10:36 +08:00
SkywalkerJi
7bc936880c Reordering system prompts. 2025-11-01 16:25:36 +08:00
tinkle-community
c24a9e57cb Merge pull request #177 from SkywalkerJi/dev
Fixed the custom model URL. Added functionality for custom model names.
2025-11-01 16:13:37 +08:00
SkywalkerJi
ebe7882205 Merge branch 'tinkle-community:dev' into dev 2025-11-01 17:09:55 +09:00
SkywalkerJi
48d1320209 * Fixed the custom model URL.
*   Added functionality for custom model names.
2025-11-01 16:09:15 +08:00
tinkle-community
2d99dda666 Merge pull request #172 from SkywalkerJi/dev
Eliminating Model Shorting Bias.
2025-11-01 14:55:26 +08:00
SkywalkerJi
db782eb314 Eliminating Model Shorting Bias. 2025-11-01 14:44:07 +08:00
tinkle
faa6818092 merge main fix Conflict 2025-11-01 13:14:22 +08:00
tinkle-community
a090040519 Merge pull request #162 from tangmengqiu/fix/i18n-english-display
Fix/i18n english display
2025-11-01 12:20:25 +08:00
tangmengqiu
7bde647112 fix: Remove duplicate selectExchange key in translations
Fixed TypeScript compilation error TS1117 caused by duplicate
'selectExchange' key in both English and Chinese translation objects.

The key was already defined in the "AI Traders Management" section,
so removed the duplicate from "AI Traders Page - Additional" section.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-01 00:02:00 -04:00
tangmengqiu
8bc06ae619 fix: Complete i18n implementation for English language display
This commit addresses the issue where switching to English still showed Chinese text in many UI elements.

Changes made:
- Added 40+ missing translation keys to translations.ts for both English and Chinese
- Updated App.tsx to use t() function for all hardcoded text (logout button, loading message)
- Updated AITradersPage.tsx extensively:
  - Replaced all alert/confirm messages with translation keys
  - Updated status labels (inUse, enabled, configured)
  - Updated all modal components (SignalSource, ModelConfig, ExchangeConfig)
  - Added language prop to all modal components
  - Replaced all Chinese UI text with translation function calls

The implementation now properly supports language switching between English and Chinese throughout the entire application.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-31 23:58:44 -04:00
tinkle-community
0a8ed95140 Merge pull request #160 from hrzisme/update-readme-narrative-team
Simplify team intro and clarify contact channels
2025-11-01 11:31:16 +08:00
ZhouYongyou
0b9d696853 添加震荡交易策略 + 买卖压力分析
**核心功能**:
- 新增买卖压力数据解析(TakerBuyVolume, BuySellRatio)
- 重写系统提示词为震荡交易策略
- 添加连续放量检测功能(2-3根K线)

**技术细节**:
- market/data.go: 解析币安 K线 item[9] 为主动买入量
- decision/engine.go: 震荡区间识别 + 区间边界入场逻辑
- IntradayData: 新增 Volumes 和 BuySellRatios 数组
2025-11-01 11:30:50 +08:00
nobody
5adb171bc7 Simplify team intro and clarify contact channels
- Remove job descriptions, keep only names and Twitter handles
- Investment: DM Tinkle or Zack
- Partnerships: DM official Twitter @nofx_ai
2025-11-01 11:28:11 +08:00
tinkle-community
601af7ba7f Merge pull request #159 from hrzisme/update-readme-narrative-team
Update readme narrative team
2025-11-01 11:05:09 +08:00
nobody
736d455771 Add official Twitter account @nofx_ai to all READMEs 2025-11-01 10:53:58 +08:00
nobody
c5b1e98995 Update multilingual READMEs: Reposition as Agentic Trading OS with team info 2025-11-01 10:49:48 +08:00
tinkle-community
d1dde246a9 Merge pull request #156 from hrzisme/update-readme-narrative-team
Update README.md
2025-11-01 10:46:36 +08:00
nobody
df4db71306 Update README: Add Zack's Twitter handle and refine team/funding info 2025-11-01 10:41:37 +08:00
nobody
f2b04707f7 Update README.md 2025-11-01 10:30:24 +08:00
Z
1cc43cec60 Merge branch 'tinkle-community:dev' into dev 2025-11-01 02:57:18 +08:00
tinkle-community
b87fcb62bd Merge pull request #151 from Icyoung/dev
Dev 竞赛fix、交易员新增参数
2025-11-01 02:42:42 +08:00