Commit Graph

17 Commits

Author SHA1 Message Date
SkywalkerJi 7208debb11 Optimize mobile display to prevent selection boxes from exceeding the screen boundaries. 2025-10-30 12:08:39 +08:00
sue 3b4a4d34aa fix: 修复配置硬编码问题
## 修复内容
### 1. AI决策杠杆配置动态化 (decision/engine.go)
- **问题**: System Prompt 中硬编码 50x/20x 杠杆,导致 AI 生成的决策不符合用户配置(5x)
- **修复**:
  - buildSystemPrompt() 新增 btcEthLeverage, altcoinLeverage 参数
  - System Prompt 文本使用动态杠杆值(第225-226行)
  - 示例 JSON 使用配置杠杆值(第299行)
  - 调用时传入实际配置值(第100行)
- **影响**: AI 现在会根据用户配置的杠杆限制生成决策
### 2. 前端初始余额显示优化 (web/src/components/EquityChart.tsx)
- **问题**: 初始余额硬编码为 1000 USDT,与用户配置的 100 USDT 不符
- **修复**: 实现三级回退机制
  1. 优先使用历史数据第一个点的 total_equity
  2. 备用使用当前账户 account.total_equity
  3. 最后使用默认值 100(匹配常见配置)
- **影响**: 前端显示的初始余额现在与实际配置一致
## 技术细节
**函数签名变更**:
```go
// 修改前
func buildSystemPrompt(accountEquity float64) string
// 修改后
func buildSystemPrompt(accountEquity float64, btcEthLeverage, altcoinLeverage int) string
```
**React 状态优化**:
```typescript
// 修改前
const initialBalance = history[0]?.total_equity || 1000;
// 修改后
const initialBalance = history[0]?.total_equity || account?.total_equity || 100;
```
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-30 02:43:14 +08:00
sue 6ea1ead263 fix: 修复AI学习数据加载失败问题
问题描述:
- AILearning组件直接使用硬编码的localhost:8080地址
- 绕过了Vite代理配置,导致加载失败
- 在生产环境无法正常工作
修复内容:
1. api.ts: 添加统一的getPerformance()方法
2. AILearning.tsx: 移除硬编码URL,使用统一API
3. 删除多余的fetcher函数
技术改进:
- 使用Vite代理配置,避免CORS问题
- 统一API管理,提高可维护性
- 支持开发和生产环境
影响范围:
- web/src/lib/api.ts: +11行 (新增getPerformance方法)
- web/src/components/AILearning.tsx: -4行, +2行 (重构API调用)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-30 01:36:51 +08:00
tinkle-community 92e34f3732 Fix: Add input_prompt display in decision cards
Previously, the frontend DecisionRecord type was missing the input_prompt
field that exists in the backend DecisionLog, causing the input context
sent to AI to not be displayed in the UI.
Changes:
- Add input_prompt field to DecisionRecord interface in both type files
- Add collapsible Input Prompt section in DecisionCard component
- Display input_prompt before AI Chain of Thought with blue styling
- Use same expand/collapse interaction pattern as CoT trace
Now users can view both the input context and AI's reasoning process
in the decision cards.
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 23:59:11 +08:00
tinkle-community a7c276fe3c Fix: Support dynamic number of traders in ComparisonChart
Previously, ComparisonChart was hardcoded to only fetch equity history
data for the first 2 traders, causing the 3rd and subsequent traders'
data to not be displayed on the chart.
Changes:
- Replaced multiple individual useSWR calls with single consolidated call
- Use Promise.all() to fetch all traders' equity data concurrently
- Generate dynamic cache key based on all trader IDs
- Maintain backward compatibility with existing component structure
- Update useMemo dependencies to properly track data changes
This fix allows the comparison chart to properly display any number of
competing traders, not just 2.
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 21:42:34 +08:00
PorunC 0ec1c6a550 Fix: Resolve React Hook violation in ComparisonChart component
Root cause:
ComparisonChart was calling useSWR hooks dynamically inside a .map() loop,
which violates React's Rules of Hooks. When the traders array length changed
(e.g., from 0 to 2, or during initial load), the number of hook calls would
change between renders, triggering React Error #310.
Previous code:
```tsx
const traderHistories = traders.map((trader) => {
  return useSWR(`equity-history-${trader.trader_id}`, ...);  //  Dynamic hooks
});
```
The eslint-disable comment on line 24 was masking this critical issue.
Fix:
- Always call exactly 2 useSWR hooks (trader1, trader2) unconditionally
- Pass null as the key when trader doesn't exist (SWR handles this gracefully)
- Build traderHistories array from these fixed hooks
- Ensures same number of hooks called on every render
This follows React's Rules of Hooks:
 Only call hooks at the top level
 Don't call hooks inside loops, conditions, or nested functions
 Call hooks in the same order every render
Fixes: React Error #310 (Rendered more hooks than during previous render)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 20:49:22 +08:00
PorunC 2cb2366b01 Fix: Add comprehensive null safety checks to CompetitionPage component
Root cause analysis:
The previous fix (0cb1f37) only addressed App.tsx Debug Info section,
but missed CompetitionPage.tsx which also directly accesses trader data
fields without null safety checks.
When competition data is loading or incomplete, trader objects may exist
but contain undefined fields (total_pnl, total_equity, etc.), causing:
"TypeError: Cannot read properties of undefined (reading 'total_pnl')"
Fixed locations in CompetitionPage.tsx:
1. Line 76-77: Leader display in header (total_pnl, total_pnl_pct)
2. Line 142: Leaderboard total_equity display
3. Line 151-157: Leaderboard P&L section (total_pnl checks and displays)
4. Line 229-230: Head-to-Head comparison (total_pnl display)
Changes applied:
- Replace direct property access with optional chaining (?.)
- Use nullish coalescing (?? 0) for numeric comparisons
- Add fallback values ('0.00') for undefined fields
- Ensure consistent null safety across all trader data displays
This completes the null safety coverage for the entire frontend.
Fixes: TypeError in CompetitionPage at index-R21Yay1P.js:116:51447
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 20:46:08 +08:00
PorunC 6b82321e01 Fix: Add null safety checks to Debug Info section in frontend
Previously fixed StatCard components but missed the Debug Info section,
causing "Cannot read properties of undefined (reading 'total_pnl')" error
when account data is loading or incomplete.
Root cause:
- Frontend uses SWR with async data fetching (5s refresh interval)
- During initial load or API delays, account object may exist but fields undefined
- Previous fix (93e331a) only covered StatCard section (lines 369-384)
- Debug Info section (lines 360-362) still used direct property access
Changes:
- Add optional chaining (?.) to all account field accesses in Debug Info
- Add fallback values ('0.00') for undefined fields
- Ensures consistent null safety across all account data displays
This prevents runtime errors during data loading and API failures.
Fixes: TypeError: Cannot read properties of undefined (reading 'total_pnl')
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 20:39:28 +08:00
PorunC 36b75bbfc8 Fix: Improve frontend code quality and null safety
- Remove unused variables and imports
- Add null/undefined safety checks for account data display
- Use optional chaining and nullish coalescing for safer data access
- Remove unused "Input Prompt" display section (keeping CoT trace)
- Fix TypeScript warnings and improve type safety
Changes:
- App.tsx: Add null checks for account fields, remove unused stats prop and input prompt display
- ComparisonChart.tsx: Remove unused imports and variables
This improves code quality without affecting functionality.
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 20:30:17 +08:00
tinkle-community b9ea3f68ea Fix: Correct Profit Factor calculation and display units in AI Learning
Backend changes (logger/decision_logger.go):
- Fixed Profit Factor to use standard formula (total profit / total loss)
- Previously used average values which was incorrect when win/loss counts differ
- Now saves total amounts before calculating averages for accurate ratio
Frontend changes (web/src/components/AILearning.tsx):
- Fixed display units: changed USDT amounts from "%" to "USDT"
- Updated avg_win and avg_loss to show "USDT Average" instead of "%"
- Updated best/worst performer displays to show "USDT" instead of "%"
- Added "(USDT)" labels to table headers for clarity
- Removed "%" from all table data cells showing monetary amounts
This ensures accurate performance metrics and eliminates user confusion
between percentage values and absolute USDT amounts.
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 17:59:19 +08:00
tinkle-community 691def7b17 Refactor: Improve comparison chart data synchronization
Major improvements:
- Replace useState+useEffect with useMemo for better performance
- Use timestamp-based grouping instead of cycle_number
- Fix data alignment issues when backend resets cycles
- Add detailed console logging for debugging
- Optimize data merging logic with Map structures
Chart updates:
- Display sequence number instead of cycle number on X-axis
- Improve tooltip to show actual time and sequence
- Better handling of multi-trader data synchronization
- More reliable data point matching across traders
Performance:
- Reduce unnecessary re-renders with useMemo
- More efficient data processing with Maps
- Better dependency tracking in hooks
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 05:31:15 +08:00
tinkle-community 6c87a51303 UI: Enhance AI learning dashboard visual design
Improvements:
- Add gradient background with glowing effects
- Redesign header section with larger icon and enhanced typography
- Improve card layouts with modern shadows and hover effects
- Optimize Sharpe ratio and profit factor display sections
- Add better visual hierarchy and spacing
- Enhance color schemes for better readability
- Remove unused decision record fetching code
- Clean up comments for better code clarity
Visual enhancements:
- Glassmorphism effects with backdrop blur
- Animated gradient backgrounds
- Enhanced metric cards with better contrast
- Improved symbol performance table design
- Modernized trade history cards with gradients
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 04:54:53 +08:00
tinkle-community ceaedca253 Refactor: Improve AI decision system and Sharpe ratio calculation
Major improvements:
- Use period-level Sharpe ratio (range -2 to +2) instead of annualized
- Save full user prompt in decision logs for debugging
- Format complete market data (3m + 4h candles) for AI analysis
- Prevent position stacking with duplicate position checks
- Update Sharpe ratio interpretation thresholds
Market data enhancements:
- Display full technical indicators in user prompt
- Include 3-minute and 4-hour timeframe data
- Add OI (Open Interest) change and funding rate signals
Risk control:
- Block opening duplicate positions (same symbol + direction)
- Suggest close action first before opening new position
- Prevent margin usage from exceeding limits
UI improvements:
- Update multi-language translations
- Refine AI learning dashboard display
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 04:44:17 +08:00
tinkle-community 0dca506cfc Feature: Add Sharpe ratio for AI self-evolution
- Implement Sharpe ratio calculation in decision logger
- Add adaptive behavior recommendations based on Sharpe ratio
- Display Sharpe ratio in AI learning dashboard with visual indicators
- Enable AI to adjust trading strategy based on risk-adjusted returns
- Color-coded performance levels (red/yellow/green) for easy monitoring
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 02:31:15 +08:00
tinkle-community 8a26b8161b Feature: Add multi-language support and UI improvements
- Add language context and translation system (Chinese/English)
- Enhance UI components with i18n support
- Update AILearning, EquityChart, and CompetitionPage
- Add language toggle in header
- Improve user experience with localized text
2025-10-28 22:25:36 +08:00
tinkle-community a726702302 Update: Merge nofx improvements
- Frontend trading records and UI enhancements
- Optimized AI prompts and decision engine
- Performance analysis and comparison features
- Binance-style UI improvements
2025-10-28 21:45:28 +08:00
tinkle-community 5aa50d35d7 Initial commit: NOFX AI Trading System
- Multi-AI competition mode (Qwen vs DeepSeek)
- Binance Futures integration
- AI self-learning mechanism
- Professional web dashboard
- Complete risk management system
2025-10-28 15:47:34 +08:00