Commit Graph

11 Commits

Author SHA1 Message Date
icy 7d58f56e49 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 5ad135310f Supports custom system prompts and custom models. 2025-11-01 19:45:54 +08:00
tinkle-community beb9561742 Feature: Add position details to Trade History
Add missing fields to TradeOutcome:
- Quantity: Position size
- Leverage: Leverage multiplier
- PositionValue: Total position value (quantity × openPrice)
- MarginUsed: Margin required (positionValue / leverage)
This provides complete trade information for analysis and display.
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-30 18:09:16 +08:00
tinkle-community fd8b1477e7 Fix: Resolve Trade History data loss and P&L calculation errors
Major fixes:
1. Trade History data loss issue
   - Root cause: Open records outside analysis window caused close matching failures
   - Solution: Pre-populate position state by reading 3x window of historical records
   - Ensures long-term positions (>5 hours) generate correct trade records
2. P&L calculation errors
   - Remove incorrect leverage multiplication from absolute P&L
   - Correct calculation: Futures P&L = quantity × price difference
   - Leverage only affects P&L percentage (relative to margin)
3. Other fixes
   - Break-even trades (pnl=0) no longer misclassified as losses
   - Perfect strategy shows Profit Factor as 999.0 instead of 0.0
   - Expand analysis window from 20 to 100 cycles (5 hours)
Files changed:
- logger/decision_logger.go: Core matching and calculation logic
- api/server.go: API analysis window
- trader/auto_trader.go: AI decision analysis window
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-30 17:58:25 +08:00
tinkle-community 683ae58563 Fix: Correct Sharpe Ratio calculation by using proper equity values
Critical bug fix in Sharpe Ratio calculation logic:
Problem:
- Previously calculated equity as TotalBalance + TotalUnrealizedProfit
- This was incorrect because TotalBalance already stores TotalEquity
- TotalUnrealizedProfit actually stores TotalPnL (not unrealized profit)
- This caused: equity = 2 * TotalEquity - InitialBalance (wrong!)
Root cause:
- Field naming mismatch between AccountSnapshot and actual stored values
- TotalBalance field actually contains TotalEquity (wallet + unrealized)
- TotalUnrealizedProfit field actually contains TotalPnL (equity - initial)
Solution:
- Use TotalBalance directly as it already represents complete account equity
- Added clear comments explaining the field name vs content mismatch
- Sharpe Ratio now correctly calculates risk-adjusted returns
Impact:
- Sharpe Ratio values are now mathematically accurate
- AI performance assessment is now reliable
- No changes needed to data storage or API layer
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 18:08:36 +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 938926254f Fix: Correct PnL calculation in trade history analysis
Fixed critical issues in historical trade record and performance analysis:
1. PnL Calculation: Changed from percentage-only to actual USDT amount
   - Now correctly calculates: positionValue × priceChange% × leverage
   - Previously: 100U@5% and 1000U@5% both showed 5.0
   - Now: Properly reflects different position sizes and leverage
2. Position Tracking: Added quantity and leverage to open position records
   - Store complete trade data for accurate PnL calculation
   - Previously only stored: side, openPrice, openTime
   - Now includes: quantity, leverage for proper accounting
3. Position Key: Fixed to distinguish long/short positions
   - Changed from symbol to symbol_side (e.g., BTCUSDT_long)
   - Prevents conflicts when holding both long and short positions
4. Sharpe Ratio: Replaced custom Newton's method with math.Sqrt
   - Simplified standard deviation calculation
   - More reliable and maintainable
Impact: Win rate, profit factor, and Sharpe ratio now based on accurate USDT amounts
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-10-29 15:30:32 +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 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