Shui
179e5c69bf
fix(bootstrap module): add bootstrap module to meet future function ( #674 )
...
* fix(bootstrap module): add bootstrap module to meet future function
* Fix readme
* Fix panic because log.logger is nil
* fix import
---------
Co-authored-by: zbhan <zbhan@freewheel.tv >
2025-11-07 10:53:10 +08:00
Shui
a8a2b6b849
Revert "fix(web): prevent NaN% display in competition gap calculation ( #633 ) …" ( #676 )
...
This reverts commit 8db6dc3b06 .
2025-11-06 20:58:13 -05:00
0xYYBB | ZYY | Bobo
24e23084be
fix(web): prevent NaN% display in competition gap calculation ( #633 ) ( #670 )
...
**Problem:**
Competition page shows "NaN%" for gap difference when trader P&L
percentages are null/undefined.
**Root Cause:**
Line 227: `const gap = trader.total_pnl_pct - opponent.total_pnl_pct`
- If either value is `undefined` or `null`, result is `NaN`
- Display shows "领先 NaN%" or "落后 NaN%"
**Solution:**
Add null coalescing to default undefined/null values to 0:
```typescript
const gap = (trader.total_pnl_pct ?? 0) - (opponent.total_pnl_pct ?? 0)
```
**Impact:**
- ✅ Gap calculation returns 0 when data is missing (shows 0.00%)
- ✅ Prevents confusing "NaN%" display
- ✅ Graceful degradation for incomplete data
Fixes #633
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-authored-by: tinkle-community <tinklefund@gmail.com >
2025-11-06 20:35:58 -05:00
0xYYBB | ZYY | Bobo
47357dfdbf
fix(prompts): reduce margin usage from 95% to 88% for Hyperliquid liquidation buffer ( #666 )
...
## Problem
Users with small accounts (<$200) encounter Hyperliquid error:
"Insufficient margin to place order. asset=1"
Real case: $98.89 account failed to open position
## Root Cause
5% reserve insufficient for:
- Trading fees (~0.04%)
- Slippage (0.01-0.1%)
- Liquidation margin buffer (Hyperliquid requirement)
Additionally, undefined "Allocation %" parameter caused confusion.
## Solution
1. Reduce margin usage rate from 95% to 88% (reserve 12%)
2. Remove undefined "Allocation %" parameter
3. Add small account example ($98.89) for clarity
## Example ($98.89 account)
Before: $93.95 margin → $4.75 remaining ❌
After: $87.02 margin → $11.87 remaining ✅
## Modified Files
- prompts/adaptive.txt
- prompts/default.txt
- prompts/nof1.txt
## Testing
Verified with $98.89 account on z-dev branch - successful order placement
Fixes #549
2025-11-07 09:19:20 +08:00
ZhouYongyou
05ec599e22
fix(prompts): correct risk_usd formula - remove duplicate leverage multiplication
...
## Problem (Issue #592 )
risk_usd formula incorrectly multiplies leverage twice:
- Incorrect: risk_usd = |Entry - Stop| × Position Size × Leverage ❌
This causes AI to calculate risk as 10x (or leverage倍) higher than actual.
## Root Cause
Position Size already includes leverage effect:
- Position Size (coins) = position_size_usd / price
- position_size_usd = margin × leverage
- Therefore: Position Size = (margin × leverage) / price
Multiplying leverage again amplifies risk calculation by "leverage" times.
## Example
Scenario: $100 margin, 10x leverage, 0.02 BTC position, $500 stop distance
**Correct calculation:**
risk_usd = $500 × 0.02 = $10 ✅
Risk % = 10% of margin (reasonable)
**Incorrect calculation (current):**
risk_usd = $500 × 0.02 × 10 = $100 ❌
Risk % = 100% of margin (completely wrong!)
## Impact
- AI miscalculates risk as "leverage" times higher
- May refuse valid trades thinking risk is too high
- Risk control logic becomes ineffective
- Potential for position sizing errors
## Solution
Correct formula: risk_usd = |Entry - Stop| × Position Size (coins)
Added warnings:
- CN: ⚠️ 不要再乘杠杆:仓位数量已包含杠杆效应
- EN: ⚠️ Do NOT multiply by leverage: Position Size already includes leverage effect
## Modified Files
- prompts/adaptive.txt (line 404)
- prompts/nof1.txt (line 104)
Closes #592
2025-11-07 08:46:37 +08:00
0xYYBB | ZYY | Bobo
4edb94380d
style: convert Traditional Chinese comments to Simplified Chinese ( #662 )
...
## Problem
The codebase contains mixed Traditional Chinese (繁體中文) and Simplified Chinese (简体中文)
in comments and error messages, causing:
- Inconsistent code style
- Reduced readability for mainland Chinese developers
- Maintenance overhead when reviewing diffs
### Affected Files
- **trader/hyperliquid_trader.go**: 8 occurrences
- **trader/binance_futures.go**: 2 occurrences
## Solution
Convert all Traditional Chinese characters to Simplified Chinese to unify code style.
### Conversion Map
| Traditional | Simplified | Context |
|-------------|-----------|---------|
| 處理 | 处理 | "正確處理" → "正确处理" |
| 總資產 | 总资产 | "總資產" → "总资产" |
| 餘額 | 余额 | "可用餘額" → "可用余额" |
| 實現 | 实现 | "未實現盈虧" → "未实现盈亏" |
| 來 | 来 | "僅來自" → "仅来自" |
| 現貨 | 现货 | "現貨餘額" → "现货余额" |
| 單獨 | 单独 | "單獨返回" → "单独返回" |
| 開倉 | 开仓 | "開倉金額" → "开仓金额" |
| 數量 | 数量 | "開倉數量" → "开仓数量" |
| 過 | 过 | "過小" → "过小" |
| 為 | 为 | "後為" → "后为" |
| 後 | 后 | "格式化後" → "格式化后" |
| 建議 | 建议 | "建議增加" → "建议增加" |
| 選擇 | 选择 | "選擇價格" → "选择价格" |
| 幣種 | 币种 | "幣種" → "币种" |
## Changes
### trader/hyperliquid_trader.go (8 locations)
**Line 173-181**: Balance calculation comments
```diff
-// ✅ Step 5: 正確處理 Spot + Perpetuals 余额
-// 重要:Spot 只加到總資產,不加到可用餘額
+// ✅ Step 5: 正确处理 Spot + Perpetuals 余额
+// 重要:Spot 只加到总资产,不加到可用余额
-result["totalWalletBalance"] = totalWalletBalance // 總資產(Perp + Spot)
-result["availableBalance"] = availableBalance // 可用餘額(僅 Perpetuals,不含 Spot)
-result["totalUnrealizedProfit"] = totalUnrealizedPnl // 未實現盈虧(僅來自 Perpetuals)
-result["spotBalance"] = spotUSDCBalance // Spot 現貨餘額(單獨返回)
+result["totalWalletBalance"] = totalWalletBalance // 总资产(Perp + Spot)
+result["availableBalance"] = availableBalance // 可用余额(仅 Perpetuals,不含 Spot)
+result["totalUnrealizedProfit"] = totalUnrealizedPnl // 未实现盈亏(仅来自 Perpetuals)
+result["spotBalance"] = spotUSDCBalance // Spot 现货余额(单独返回)
```
**Line 189-191**: Log output messages
```diff
-log.Printf(" • Perpetuals 可用余额: %.2f USDC (可直接用於開倉)", availableBalance)
-log.Printf(" • 總資產 (Perp+Spot): %.2f USDC", totalWalletBalance)
+log.Printf(" • Perpetuals 可用余额: %.2f USDC (可直接用于开仓)", availableBalance)
+log.Printf(" • 总资产 (Perp+Spot): %.2f USDC", totalWalletBalance)
```
### trader/binance_futures.go (2 locations)
**Line 301, 355**: Error messages for insufficient quantity
```diff
-return nil, fmt.Errorf("开倉數量過小,格式化後為 0 (原始: %.8f → 格式化: %s)。建議增加開倉金額或選擇價格更低的幣種", quantity, quantityStr)
+return nil, fmt.Errorf("开仓数量过小,格式化后为 0 (原始: %.8f → 格式化: %s)。建议增加开仓金额或选择价格更低的币种", quantity, quantityStr)
```
## Testing
- ✅ Compilation: Passes `go build`
- ✅ Verification: No Traditional Chinese characters remain in trader/*.go
- ✅ Functionality: No logic changes, only text updates
## Impact
- ✅ Unified code style (100% Simplified Chinese)
- ✅ Improved readability and maintainability
- ✅ Easier code review for Chinese developers
- ✅ No functional changes or behavior modifications
---
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-authored-by: tinkle-community <tinklefund@gmail.com >
2025-11-06 19:36:14 -05:00
SkywalkerJi
bf0ebf8878
fix: Fixed go vet issues. ( #658 )
...
* Fixed vet ./... errors.
* Fixed ESLint issues.
2025-11-07 02:28:01 +08:00
icy
5e5a1df1a7
feat:path fix
2025-11-07 02:27:49 +08:00
icy
d2f326c336
feat: script fix
2025-11-07 02:23:13 +08:00
icy
7fb2349e1e
feat: script fix
2025-11-07 02:16:29 +08:00
SkywalkerJi
40030fd1b6
Add Terms of Service ( #656 )
...
* Add Privacy Policy
* Add Terms of Service
2025-11-07 02:16:05 +08:00
icy
5bb585a112
feat: crypto script fix
2025-11-07 02:10:42 +08:00
icy
6dc61a4109
feat:migrate for crypto
2025-11-07 01:57:00 +08:00
SkywalkerJi
494754c120
Add Privacy Policy ( #655 )
2025-11-07 01:54:25 +08:00
0xYYBB | ZYY | Bobo
4624382b74
fix(web): restore ESLint, Prettier, and Husky code quality tools ( #648 )
...
## Problem
PR #647 accidentally removed all code quality tools when adding test dependencies:
- ❌ ESLint (9 packages) - code linting
- ❌ Prettier - code formatting
- ❌ Husky - Git hooks
- ❌ lint-staged - pre-commit checks
- ❌ Related scripts (lint, format, prepare)
This significantly impacts code quality and team collaboration.
## Root Cause
When adding test dependencies (vitest, @testing-library/react), the package.json
was incorrectly edited, removing all existing devDependencies.
## Solution
Restore all code quality tools while keeping the new test dependencies:
### ✅ Restored packages:
- @eslint/js
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- eslint + plugins (prettier, react, react-hooks, react-refresh)
- prettier
- husky
- lint-staged
### ✅ Kept test packages:
- @testing-library/jest-dom
- @testing-library/react
- jsdom
- vitest
### ✅ Restored scripts:
```json
{
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "eslint . --ext ts,tsx --fix",
"format": "prettier --write \"src/**/*.{ts,tsx,css,json}\"",
"format:check": "prettier --check \"src/**/*.{ts,tsx,css,json}\"",
"test": "vitest run",
"prepare": "husky"
}
```
### ✅ Restored lint-staged config
## Impact
This fix restores:
- Automated code style enforcement
- Pre-commit quality checks
- Consistent code formatting
- Team collaboration standards
## Testing
- [x] npm install succeeds
- [x] npm run build succeeds
- [x] All scripts are functional
Related-To: PR #647
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-authored-by: tinkle-community <tinklefund@gmail.com >
2025-11-07 01:30:13 +08:00
icy
5616aebc8d
Merge branch 'feature/crypto' of github.com:NoFxAiOS/nofxos into origin/beta
...
# Conflicts:
# config.json.example
# config/config.go
2025-11-07 01:28:47 +08:00
tinkle-community
092a221cf3
update link
2025-11-07 01:26:18 +08:00
icy
4b655c5d9b
feat: crypto for key
2025-11-07 01:25:18 +08:00
0xYYBB | ZYY | Bobo
fd5aab01b1
fix(web): resolve TypeScript type error in crypto.ts and add missing test dependencies ( #647 )
...
```
src/lib/crypto.ts(66,32): error TS2345: Argument of type 'Uint8Array<ArrayBuffer>'
is not assignable to parameter of type 'ArrayBuffer'.
```
`arrayBufferToBase64` function expected `ArrayBuffer` but received `Uint8Array.buffer`.
TypeScript strict type checking flagged the mismatch.
1. Update `arrayBufferToBase64` signature to accept `ArrayBuffer | Uint8Array`
2. Pass `result` directly instead of `result.buffer` (more accurate)
3. Add runtime type check with instanceof
```
error TS2307: Cannot find module 'vitest'
error TS2307: Cannot find module '@testing-library/react'
```
Install missing devDependencies:
- vitest
- @testing-library/react
- @testing-library/jest-dom
✅ Frontend builds successfully
✅ TypeScript compilation passes
✅ No type errors
Related-To: Docker frontend build failures
2025-11-07 01:19:48 +08:00
ZhouYongyou
133570663f
refactor(crypto): simplify to local encryption only (remove KMS)
...
## 🎯 簡化方案(社區友好)
### 移除雲端 KMS
- ❌ 刪除 crypto/aliyun_kms.go
- ❌ 不包含 GCP KMS
- ✅ 僅保留本地 AES-256-GCM 加密
### 更新 SQLite 驅動
- ✅ modernc.org/sqlite(純 Go,無 CGO)
- ✅ 與上游保持一致
## 📦 保留核心功能
✅ crypto/encryption.go - RSA + AES 加密
✅ crypto/secure_storage.go - 數據庫加密層
✅ api/crypto_handler.go - API 端點
✅ web/src/lib/crypto.ts - 前端加密
✅ scripts/migrate_encryption.go - 數據遷移
## 🚀 部署方式
```bash
# 僅需一個環境變量
export NOFX_MASTER_KEY=$(openssl rand -base64 32)
go run main.go
```
## ✅ 優點
- ✅ 零雲服務依賴
- ✅ 簡單易部署
- ✅ 適合社區用戶
- ✅ 保持核心安全功能
2025-11-06 23:58:27 +08:00
ZhouYongyou
4caf34d329
feat(security): add end-to-end encryption for sensitive data
...
## Summary
Add comprehensive encryption system to protect private keys and API secrets.
## Core Components
- `crypto/encryption.go`: RSA-4096 + AES-256-GCM encryption manager
- `crypto/secure_storage.go`: Database encryption layer + audit logs
- `crypto/aliyun_kms.go`: Optional Aliyun KMS integration
- `api/crypto_handler.go`: Encryption API endpoints
- `web/src/lib/crypto.ts`: Frontend two-stage encryption
- `scripts/migrate_encryption.go`: Data migration tool
- `deploy_encryption.sh`: One-click deployment
## Security Architecture
```
Frontend: Two-stage input + clipboard obfuscation
↓
Transport: RSA-4096 + AES-256-GCM hybrid encryption
↓
Storage: Database encryption + audit logs
```
## Features
✅ Zero breaking changes (backward compatible)
✅ Automatic migration of existing data
✅ <25ms overhead per operation
✅ Complete audit trail
✅ Optional cloud KMS support
## Migration
```bash
./deploy_encryption.sh # 5 minutes, zero downtime
```
## Testing
```bash
go test ./crypto -v
```
Related-To: security-enhancement
2025-11-06 23:55:33 +08:00
icy
6f40920a78
feat: improve model/exchange deletion and selection logic
...
- Add soft delete support for AI models
* Add deleted field to ai_models table
* Implement soft delete with sensitive data cleanup
* Filter deleted records in queries
- Replace browser confirm dialogs with custom styled modals
* Create DeleteConfirmModal component with Binance theme
* Add proper warning messages and icons
* Improve user experience with consistent styling
- Fix duplicate model/exchange display in selection dropdowns
* Use supportedModels/supportedExchanges for modal selectors
* Use configuredModels/configuredExchanges for panel display
* Remove redundant selectableModels/selectableExchanges logic
- Enhance data management
* Refresh data after deletion operations
* Proper state cleanup after modal operations
* Clear sensitive data during soft delete
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: tinkle-community <tinklefund@gmail.com >
2025-11-06 22:21:43 +08:00
icy
6692c56f89
feat: improve model/exchange deletion and selection logic
...
- Add soft delete support for AI models
* Add deleted field to ai_models table
* Implement soft delete with sensitive data cleanup
* Filter deleted records in queries
- Replace browser confirm dialogs with custom styled modals
* Create DeleteConfirmModal component with Binance theme
* Add proper warning messages and icons
* Improve user experience with consistent styling
- Fix duplicate model/exchange display in selection dropdowns
* Use supportedModels/supportedExchanges for modal selectors
* Use configuredModels/configuredExchanges for panel display
* Remove redundant selectableModels/selectableExchanges logic
- Enhance data management
* Refresh data after deletion operations
* Proper state cleanup after modal operations
* Clear sensitive data during soft delete
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: tinkle-community <tinklefund@gmail.com >
2025-11-06 22:05:21 +08:00
Lawrence Liu
66bfccbd9b
fix(web): 修正 FAQ 翻译文件中的错误信息 ( #552 )
...
- 删除 OKX 虚假支持声明(后端未实现)
- 补充 Aster DEX 的 API 配置说明
- 修正测试网说明为暂时不支持
2025-11-06 21:59:10 +08:00
Burt
fce3441aff
Fix: 提示词, 竞赛数据接口在管理员模式下转为公开 ( #607 )
...
* 提示词, 竞赛数据接口在管理员模式下转为公开
* Fix "go vet" error
2025-11-06 20:42:43 +08:00
icy
2c5b2282c0
feat: soft deleted exchange add
2025-11-06 20:39:46 +08:00
icy
ec1f39fe3a
feat: supported models and exchange fix
2025-11-06 20:39:20 +08:00
icy
94d14cabc9
fix: show supported models/exchanges in selection modals
2025-11-06 19:30:37 +08:00
icy
ddc1f9566f
chore: load db credentials from .env in helper scripts
2025-11-06 19:12:45 +08:00
icy
1f268fac07
feat: gitignore prod config
2025-11-06 19:02:28 +08:00
icy
f92805961f
feat: web 443 port and ssl cert
2025-11-06 18:42:22 +08:00
icy
8047da3840
ui: enlarge NOFX watermark overlays
2025-11-06 18:18:04 +08:00
icy
430667e6f7
fix: remove duplicate secret input for Binance
2025-11-06 18:08:26 +08:00
icy
706c719248
chore: move shell scripts under scripts/ and update docs
2025-11-06 17:53:27 +08:00
icy
8e7e50ef5f
refactor: drop sqlite fallback and admin mode
2025-11-06 17:52:30 +08:00
icy
579c73a81b
chore: remove pm2 deployment docs and tooling
2025-11-06 17:47:40 +08:00
ZhouYongyou
cb5edffe03
Merge branch 'dev' of https://github.com/NoFxAiOS/nofx into fix/stop-loss-take-profit-method-calls
2025-11-06 14:20:35 +08:00
tinkle-community
cd82b56943
Merge pull request #12 from NoFxAiOS/feature_proxy
...
feat(proxy): add proxy module
2025-11-06 12:27:06 +08:00
Ember
506e9c5277
bugfix/ fix delete AI Model issue ( #594 )
...
* fix: 修复删除AI模型/交易所后UI未刷新的问题
问题描述:
在配置界面删除AI模型或交易所后,虽然后端数据已更新,但前端UI仍然显示已删除的配置项。
根本原因:
React的状态更新机制可能无法检测到数组内容的变化,特别是当API返回的数据与之前的引用相同时。
修复方案:
在 handleDeleteModelConfig 和 handleDeleteExchangeConfig 中使用数组展开运算符 [...items] 创建新数组,确保React能够检测到状态变化并触发重新渲染。
修改文件:
- web/src/components/AITradersPage.tsx
影响范围:
- AI模型删除功能
- 交易所删除功能
Fixes #591
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: tinkle-community <tinklefund@gmail.com >
* fix: 删除重复的确认对话框
问题描述:
删除AI模型或交易所时,确认对话框会弹出两次
根本原因:
1. ModelConfigModal 的删除按钮 onClick 中有一个 confirm
2. handleDeleteConfig 函数内部也有一个 confirm
修复方案:
移除 Modal 组件中的 confirm,保留 handleDeleteConfig 内部的确认逻辑,因为它包含了更完整的依赖检查功能
修改内容:
- 移除 ModelConfigModal 删除按钮中的 confirm
- 移除 ExchangeConfigModal 删除按钮中的 confirm
- 更新 title 属性为更合适的翻译键
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: tinkle-community <tinklefund@gmail.com >
---------
Co-authored-by: tinkle-community <tinklefund@gmail.com >
2025-11-06 12:25:25 +08:00
hzb1115
79d4dac9e5
feat(proxy): add proxy module
2025-11-05 21:41:36 -05:00
Sue
80719f382a
fix: validate config.db is file not directory ( #586 )
...
修复 config.db 验证逻辑,处理误创建为目录的情况:
- 检测 config.db 是否为目录,如果是则删除并重建为文件
- 保留已存在的数据库文件不受影响
- 修复 Docker volume 挂载可能导致的目录创建问题
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-authored-by: tinkle-community <tinklefund@gmail.com >
2025-11-06 10:38:53 +08:00
Diego
2f75b4b98d
fix: 修复删除模型/交易所时界面卡死问题并增强依赖检查 ( #578 )
...
* fix: 修复删除模型/交易所时界面卡死问题并增强依赖检查
## 问题描述
1. 删除唯一的AI模型或交易所配置时,界面会卡死数秒
2. 删除后配置仍然显示在列表中
3. 可以删除被交易员使用的配置,导致数据不一致
## 修复内容
### 后端性能优化 (manager/trader_manager.go)
- 将循环内的重复数据库查询移到循环外
- 减少N次重复查询(GetAIModels + GetExchanges)为1次查询
- 大幅减少锁持有时间,从数秒降至毫秒级
### 前端显示修复 (web/src/components/AITradersPage.tsx)
- 过滤显示列表,只显示真正配置过的模型/交易所(有apiKey的)
- 删除后重新从后端获取最新数据,确保界面同步
### 前端依赖检查 (web/src/components/AITradersPage.tsx)
- 新增完整的依赖检查,包括停止状态的交易员
- 删除前检查是否有交易员使用该配置
- 显示使用该配置的交易员名称列表
- 阻止删除被使用的配置,保证数据一致性
### 多语言支持 (web/src/i18n/translations.ts)
- 添加依赖检查相关的中英文提示文本
- cannotDeleteModelInUse / cannotDeleteExchangeInUse
- tradersUsing / pleaseDeleteTradersFirst
## 测试建议
1. 创建交易员后尝试删除其使用的模型/交易所,应显示警告并阻止删除
2. 删除未使用的模型/交易所,应立即从列表消失且界面不卡死
3. 刷新页面后,已删除的配置不应再出现
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: tinkle-community <tinklefund@gmail.com >
* refactor: 重构删除配置函数减少重复代码
## 重构内容
- 创建通用的 handleDeleteConfig 函数
- 使用配置对象模式处理模型和交易所的删除逻辑
- 消除 handleDeleteModelConfig 和 handleDeleteExchangeConfig 之间的重复代码
## 重构效果
- 减少代码行数约 40%
- 提高代码可维护性和可读性
- 便于未来添加新的配置类型
## 功能保持不变
- 依赖检查逻辑完全相同
- 删除流程完全相同
- 用户体验完全相同
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: tinkle-community <tinklefund@gmail.com >
---------
Co-authored-by: tinkle-community <tinklefund@gmail.com >
2025-11-06 10:32:30 +08:00
ZhouYongyou
7136773b6f
fix: 添加双向持仓防御性检查,避免误删除对向订单
...
在上一个修复(113a30f)中,虽然解决了订单累积问题,但引入了新的风险:
如果用户同时持有同一symbol的多空双向持仓,update_stop_loss/update_take_profit
会误删除另一方向的保护订单。
```
假设:
- BTCUSDT LONG 持仓(止损 95000)
- BTCUSDT SHORT 持仓(止损 105000)
AI 执行:update_stop_loss for SHORT
→ CancelStopLossOrders("BTCUSDT") 删除所有止损
→ SetStopLoss("BTCUSDT", "SHORT", ...) 只设置 SHORT 止损
结果:
- SHORT 止损正确更新 ✅
- LONG 止损被误删 ❌ 失去保护!
```
1. ✅ 技术支持:Binance 设置为双向持仓模式(Hedge Mode)
2. ❌ 策略禁止:Prompt 明确禁止"对同一标的同时持有多空"
3. ❌ 代码保护:开仓时检查已有同向持仓并拒绝
理论上不应该出现双向持仓,但仍需防御:
- 用户手动操作
- 并发bug
- 遗留数据
在 auto_trader.go 的 update_stop_loss/update_take_profit 函数中:
1. 执行前检测是否存在对向持仓
2. 如果检测到双向持仓:
- 记录 🚨 严重警告日志
- 说明这违反策略规则
- 提示可能的原因和建议
3. 继续执行当前逻辑(因为策略本身禁止双向持仓)
- executeUpdateStopLossWithRecord: 添加双向持仓检测(第1175-1194行)
- executeUpdateTakeProfitWithRecord: 添加双向持仓检测(第1259-1278行)
```
🚨 警告:检测到 BTCUSDT 存在双向持仓(SHORT + LONG),这违反了策略规则
🚨 取消止损单将影响两个方向的订单,请检查是否为用户手动操作导致
🚨 建议:手动平掉其中一个方向的持仓,或检查系统是否有BUG
```
- 会影响所有实现类(binance/aster/hyperliquid)
- 增加复杂度
- 策略已禁止双向持仓,属于异常场景
- 实现过于复杂
- 需要重新实现订单管理逻辑
- 策略禁止场景不应该出现
- ✅ 最小侵入性修改
- ✅ 及时警告异常情况
- ✅ 不影响正常流程
- ✅ 为调试提供线索
- 正常使用(单向持仓):无影响,正常工作 ✅
- 异常场景(双向持仓):记录警告,提示用户检查 ⚠️
Related: 113a30f (原始修复)
2025-11-06 02:57:59 +08:00
ZhouYongyou
7c5a68a9ea
fix: 修复 update_stop_loss/update_take_profit 未删除旧订单的BUG
...
## 问题描述
更新止损止盈时,旧订单没有被删除,导致订单累积。
用户看到多个止损/止盈订单同时存在(如截图所示有4个订单)。
## 根本原因
币安Futures采用双向持仓模式(Hedge Mode),每个symbol可以同时持有LONG和SHORT两个方向的仓位。
取消订单时:
- 创建订单时指定了 PositionSide(LONG/SHORT)
- 取消订单时未遍历所有订单,导致部分订单残留
## 修复内容
### 1. binance_futures.go
- CancelStopLossOrders: 取消所有方向(LONG+SHORT)的止损订单
- CancelTakeProfitOrders: 取消所有方向(LONG+SHORT)的止盈订单
- 添加错误收集机制,记录每个失败的订单
- 增强日志输出,显示订单方向(PositionSide)
- 仅当所有取消都失败时才返回错误
### 2. aster_trader.go
- 同步应用相同的修复逻辑
- 保持多交易所一致性
## 预期效果
- 更新止损时,所有旧止损订单被删除
- 更新止盈时,所有旧止盈订单被删除
- 不会出现订单累积问题
- 更详细的日志输出,方便排查问题
## 测试建议
1. 在双向持仓模式下测试 update_stop_loss
2. 验证旧订单是否全部删除
3. 检查日志中的 positionSide 输出
Related: 用户反馈截图显示4个订单同时存在
2025-11-06 02:57:02 +08:00
杜仲
a2eb03ede9
Add public routes for supported models and exchanges ( #554 )
2025-11-06 02:08:24 +08:00
icy
517e173604
Merge branch 'beta' into nofxos-beta
...
# Conflicts:
# config/database.go
# config/database_pg.go
# docker-compose.yml
# main.go
# manager/trader_manager.go
# web/src/components/AITradersPage.tsx
2025-11-06 02:06:05 +08:00
icy
3127f11c5d
Merge branch 'beta' of https://github.com/tinkle-community/nofx into beta
...
# Conflicts:
# view_pg_data.sh
# web/src/components/AITradersPage.tsx
2025-11-06 01:56:01 +08:00
icy
65053518d6
feat: implement hybrid database architecture and frontend encryption
...
- Add PostgreSQL + SQLite hybrid database support with automatic switching
- Implement frontend AES-GCM + RSA-OAEP encryption for sensitive data
- Add comprehensive DatabaseInterface with all required methods
- Fix compilation issues with interface consistency
- Update all database method signatures to use DatabaseInterface
- Add missing UpdateTraderInitialBalance method to PostgreSQL implementation
- Integrate RSA public key distribution via /api/config endpoint
- Add frontend crypto service with proper error handling
- Support graceful degradation between encrypted and plaintext transmission
- Add directory creation for RSA keys and PEM parsing fixes
- Test both SQLite and PostgreSQL modes successfully
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: tinkle-community <tinklefund@gmail.com >
2025-11-06 01:50:06 +08:00
SkywalkerJi
b99a54ef41
fix: Fixed redundant key input fields and corrected formatting on the frontend. ( #566 )
...
* Eliminate redundant key input fields in the front-end.
* go / react Formatting.
2025-11-06 01:16:04 +08:00
0xYYBB | ZYY | Bobo
3f8df95c63
fix(prompts): correct confidence scale from 0-1 to 0-100 to match backend schema ( #564 )
...
## Problem
The prompts specified confidence range as 0-1 (float), but the backend code
expects 0-100 (integer). This causes JSON parsing errors when AI outputs
values like 0.85:
```
Error: json: cannot unmarshal number 0.85 into Go struct field Decision.confidence of type int
Result: confidence defaults to 0
```
## Root Cause
**Backend Definition** (decision/engine.go:103):
```go
Confidence int `json:"confidence,omitempty"` // 信心度 (0-100)
```
**Prompts (before fix)**:
- adaptive.txt: "confidence (信心度 0-1)"
- nof1.txt: "confidence (float, 0-1)"
**buildHardSystemPrompt** (decision/engine.go:336):
```go
sb.WriteString("- `confidence`: 0-100(开仓建议≥75)\n")
```
The dynamic system prompt was correct, but the base prompts contradicted it.
## Solution
Update prompt files to use consistent 0-100 integer scale:
### adaptive.txt
- `confidence (信心度 0-1)` → `confidence (信心度 0-100)`
- `<0.85` → `<85`
- `0.85-0.90` → `85-90`
- etc.
### nof1.txt
- `confidence (float, 0-1)` → `confidence (int, 0-100)`
- `0.0-0.3` → `0-30`
- `0.3-0.6` → `30-60`
- etc.
## Impact
- ✅ Fixes JSON parsing errors when AI outputs float values
- ✅ Aligns prompts with backend schema
- ✅ Consistent with buildHardSystemPrompt() output format
- ✅ No breaking changes (backend already expects 0-100)
## Testing
```bash
# Verify backend expects 0-100
grep "Confidence int" decision/engine.go
# Output: Confidence int `json:"confidence,omitempty"` // 信心度 (0-100)
# Verify buildHardSystemPrompt uses 0-100
grep "confidence.*0-100" decision/engine.go
# Output: sb.WriteString("- `confidence`: 0-100(开仓建议≥75)\n")
# Build test
go build ./decision/... # ✅ PASS
```
## Related
- Addresses schema mismatch mentioned in Issue #557
- Note: confidence field is currently not validated by backend (validateDecision
does not check confidence value), but correct schema prevents parsing errors
---
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-authored-by: tinkle-community <tinklefund@gmail.com >
2025-11-06 00:35:53 +08:00