Commit Graph

391 Commits

Author SHA1 Message Date
ZhouYongyou
a4df3b053c fix(trader): add missing GetMinNotional and CheckMinNotional methods
These methods are required by the OpenLong/OpenShort validation but were
missing from upstream/dev.

Adds:
- GetMinNotional(): Returns minimum notional value (10 USDT default)
- CheckMinNotional(): Validates order meets minimum notional requirement
2025-11-05 01:20:02 +08:00
ZhouYongyou
1abd7029dd refactor(decision): relax minimum position size constraints for flexibility
## Changes

### Prompt Layer (Soft Guidance)
**Before**:
- BTC/ETH ≥100 USDT | 山寨币 ≥15 USDT (硬性要求)

**After**:
- 统一建议 ≥12 USDT (软性建议)
- 更简洁,不区分币种
- 给 AI 更多决策空间

### Validation Layer (Lower Thresholds)
**Before**:
- BTC/ETH: 100 USDT (硬性)
- 山寨币: 15 USDT (硬性)

**After**:
- BTC/ETH: 60 USDT (-40%, 更灵活)
- 山寨币: 12 USDT (-20%, 更合理)

## Rationale

### Why Relax?

1. **Previous was too strict**:
   - 100 USDT for BTC hardcoded at current price (~101k)
   - If BTC drops to 60k, only needs 60 USDT
   - 15 USDT for altcoins = 50% safety margin (too conservative)

2. **Three-layer defense is sufficient**:
   - Layer 1 (Prompt): Soft suggestion (≥12 USDT)
   - Layer 2 (Validation): Medium threshold (BTC 60 / Alt 12)
   - Layer 3 (API): Final check (quantity != 0 + CheckMinNotional)

3. **User feedback**: Original constraints too restrictive

### Safety Preserved

 API layer still prevents:
- quantity = 0 errors (formatted precision check)
- Below min notional (CheckMinNotional)

 Validation still blocks obviously small amounts

 Prompt guides AI toward safe amounts

## Testing

| Symbol | Amount | Old | New | Result |
|--------|--------|-----|-----|--------|
| BTCUSDT | 50 USDT |  Rejected |  Rejected |  Correct (too small) |
| BTCUSDT | 70 USDT |  Rejected |  Pass |  More flexible |
| ADAUSDT | 11 USDT |  Rejected |  Rejected |  Correct (too small) |
| ADAUSDT | 13 USDT |  Rejected |  Pass |  More flexible |

## Impact

-  More flexible for price fluctuations
-  Better user experience for small accounts
-  Still prevents API errors
-  AI has more decision space
2025-11-05 01:18:22 +08:00
ZhouYongyou
32f0cabfc3 fix(trader+decision): prevent quantity=0 error with min notional checks
User encountered API error when opening BTC position:
- Account equity: 9.20 USDT
- AI suggested: ~7.36 USDT position
- Error: `code=-4003, msg=Quantity less than or equal to zero.`

```
quantity = 7.36 / 101808.2 ≈ 0.00007228 BTC
formatted (%.3f) → "0.000"  Rounded down to 0!
```

BTCUSDT precision is 3 decimals (stepSize=0.001), causing small quantities to round to 0.

-  CloseLong() and CloseShort() have CheckMinNotional()
-  OpenLong() and OpenShort() **missing** CheckMinNotional()

- AI could suggest position_size_usd < minimum notional value
- No validation prevented tiny positions that would fail

---

**OpenLong() and OpenShort()** - Added two checks:

```go
//  Check if formatted quantity became 0 (rounding issue)
quantityFloat, _ := strconv.ParseFloat(quantityStr, 64)
if quantityFloat <= 0 {
    return error("Quantity too small, formatted to 0...")
}

//  Check minimum notional value (Binance requires ≥10 USDT)
if err := t.CheckMinNotional(symbol, quantityFloat); err != nil {
    return err
}
```

**Impact**: Prevents API errors by catching invalid quantities before submission.

---

Added minimum position size validation:

```go
const minPositionSizeGeneral = 15.0   // Altcoins
const minPositionSizeBTCETH = 100.0   // BTC/ETH (high price + precision limits)

if symbol == BTC/ETH && position_size_usd < 100 {
    return error("BTC/ETH requires ≥100 USDT to avoid rounding to 0")
}
if position_size_usd < 15 {
    return error("Position size must be ≥15 USDT (min notional requirement)")
}
```

**Impact**: Rejects invalid decisions before execution, saving API calls.

---

Updated hard constraints in AI prompt:

```
6. 最小开仓金额: **BTC/ETH ≥100 USDT | 山寨币 ≥15 USDT**
   (⚠️ 低于此金额会因精度问题导致开仓失败)
```

**Impact**: AI proactively avoids suggesting too-small positions.

---

-  User equity 9.20 USDT → suggested 7.36 USDT BTC position → **FAIL**
-  No validation, error only at API level

-  AI validation rejects position_size_usd < 100 for BTC
-  Binance trader checks quantity != 0 before submission
-  Clear error: "BTC/ETH requires ≥100 USDT..."

| Symbol | position_size_usd | Price | quantity | Formatted | Result |
|--------|-------------------|-------|----------|-----------|--------|
| BTCUSDT | 7.36 | 101808.2 | 0.00007228 | "0.000" |  Rejected (validation) |
| BTCUSDT | 150 | 101808.2 | 0.00147 | "0.001" |  Pass |
| ADAUSDT | 15 | 1.2 | 12.5 | "12.500" |  Pass |

---

**Immediate**:
-  Prevents quantity=0 API errors
-  Clear error messages guide users
-  Saves wasted API calls

**Long-term**:
-  AI learns minimum position sizes
-  Better user experience for small accounts
-  Prevents confusion from cryptic API errors

---

- Diagnostic report: /tmp/quantity_zero_diagnosis.md
- Binance min notional: 10 USDT (hardcoded in GetMinNotional())
2025-11-05 01:18:09 +08:00
SkywalkerJi
e3391fffa1 Merge pull request #425 from zhouyongyou/fix/prompts-action-names-minimal
fix(prompts): rename actions to match backend implementation

提示词对齐
2025-11-04 21:27:50 +09:00
ZhouYongyou
0fddd2731d fix(prompts): rename actions to match backend implementation
## Problem

Backend code expects these action names:
- `open_long`, `open_short`, `close_long`, `close_short`

But prompts use outdated names:
- `buy_to_enter`, `sell_to_enter`, `close`

This causes all trading decisions to fail with unknown action errors.

## Solution

Minimal changes to fix action name compatibility:

### prompts/nof1.txt
-  `buy_to_enter` → `open_long`
-  `sell_to_enter` → `open_short`
-  `close` → `close_long` / `close_short`
-  Explicitly list `wait` action
- +18 lines, -6 lines (only action definitions section)

### prompts/adaptive.txt
-  `buy_to_enter` → `open_long`
-  `sell_to_enter` → `open_short`
-  `close` → `close_long` / `close_short`
- +15 lines, -6 lines (only action definitions section)

## Impact

-  Trading decisions now execute successfully
-  Maintains all existing functionality
-  No new features added (minimal diff)

## Verification

```bash
# Backend expects these actions:
grep 'Action string' decision/engine.go
# "open_long", "open_short", "close_long", "close_short", ...

# Old names removed:
grep -r "buy_to_enter\|sell_to_enter" prompts/
# (no results)
```

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 19:41:23 +08:00
tinkle-community
5649cb7496 Merge pull request #404 from 0xEmberZz/feature/binance-guide
feat: Add Binance setup guide with tutorial modal
2025-11-04 15:35:19 +08:00
Ember
0756c6d6f2 feat: Add Binance setup guide with tutorial modal
- Add Binance configuration tutorial image (guide.png)
- Implement "View Guide" button in exchange configuration modal
- Add tutorial display modal with image viewer
- Add i18n support for guide-related text (EN/ZH)
- Button only appears when configuring Binance exchange

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 14:50:38 +08:00
SkywalkerJi
cc728b5fb4 fix the main branch history issue from November 3rd.
Merge pull request #395 from NoFxAiOS/beta
fix:fix the main branch history issue from November 3rd.
2025-11-04 13:00:05 +09:00
tinkle-community
ff4cd0e3ca Merge pull request #389 from NoFxAiOS/beta
Fix:fix the main branch history issue from November 3rd.
2025-11-04 11:22:10 +08:00
Shui
b6b956de8e Merge pull request #354 from zhouyongyou/fix/trader-config-missing-fields
fix(database): GetTraderConfig missing critical fields causes edit to fail
2025-11-03 21:57:48 -05:00
Shui
0791d6733d Merge pull request #373 from hzb1115/dev
fix(readme): update readme and pr reviewer
2025-11-03 21:07:31 -05:00
zbhan
4dcaee0477 Fix owner 2025-11-03 21:06:25 -05:00
zbhan
703aa8effa fix owner 2025-11-03 20:56:16 -05:00
zbhan
d17035dde3 fix(readme): update readme and pr reviewer 2025-11-03 20:50:56 -05:00
Luna Martinez
7ec49b0ebe Merge pull request #362 from hzb1115/dev
Fix(workflow): add title and size validation comments
2025-11-03 13:20:02 -05:00
Luna Martinez
b2df15be3f Merge branch 'NoFxAiOS:dev' into dev 2025-11-03 13:16:11 -05:00
Icyoung
045535c8cc Merge pull request #361 from Icyoung/beta
Beta bugfix
2025-11-04 02:14:54 +08:00
zbhan
09b54b8c3b Fix PR check 2025-11-03 13:12:47 -05:00
icy
793a064a27 Add NOFX watermarks to charts and fix empty state internationalization
- Add NOFX watermark to ComparisonChart (competition page)
- Add NOFX watermark to EquityChart (dashboard page)
- Fix empty state handling and internationalization in CompetitionPage

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 02:08:38 +08:00
icy
d8f325dc36 Fix ComparisonChart data display issue
The chart was not showing data because the API response format changed.
Fixed the calculation of PnL percentage by computing it from total_pnl
and balance values (initial_balance = balance - total_pnl).

Now the AI competition chart should properly display performance comparison data.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 01:54:21 +08:00
Icyoung
88d46b1dde Merge pull request #359 from Icyoung/beta
Beta Merge dev、Bug fix
2025-11-04 01:50:34 +08:00
icy
6eecd8b33a Merge branch 'dev' into beta 2025-11-04 01:45:21 +08:00
icy
4869c2bd28 Merge branch 'dev' of https://github.com/tinkle-community/nofx into dev 2025-11-04 01:45:15 +08:00
icy
5507ae7b13 Remove all test dependencies and configurations
- Removed test script from package.json
- Removed testing dependencies (@testing-library/react, vitest, jsdom)
- Deleted test directory and vitest.config.ts
- Updated package-lock.json to reflect changes
- Build still works perfectly without test dependencies

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 01:44:40 +08:00
icy
e25f04c642 Remove unused test files
Removed App.test.tsx and AITradersPage.test.tsx that were causing TypeScript build issues and are not currently in use.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 01:43:02 +08:00
Luna Martinez
4166776fdf Merge pull request #323 from zhouyongyou/fix/go-vet-warnings
fix: resolve go vet warnings for non-constant format strings
2025-11-03 12:42:46 -05:00
icy
8ca6f68867 Fix TypeScript build error
Removed unused 'Zap' import from App.tsx that was causing build failure.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 01:42:25 +08:00
Luna Martinez
9f03266fed Merge pull request #329 from zhouyongyou/chore/peer-dependency-markers
chore(web): add peer dependency markers to package-lock.json
2025-11-03 12:39:24 -05:00
icy
364c6081af Resolve merge conflicts with dev branch
Resolved conflicts in:
- api/server.go: Preserved beta_mode config and user permission checks
- manager/trader_manager.go: Kept optimized concurrent competition data with caching

Maintained all performance optimizations while merging new features from dev.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 01:36:54 +08:00
icy
71637268fd Merge branch 'dev' of https://github.com/tinkle-community/nofx into dev
# Conflicts:
#	api/server.go
2025-11-04 01:34:14 +08:00
icy
3af2dd41fb Fix: Add proper top padding to prevent HeaderBar overlap on all main app pages
Match main app layout with proven working /competition route layout:
- Use px-6 py-6 pt-24 padding (same as /competition route)
- Ensures HeaderBar doesn't overlap content on /traders and /dashboard pages
- Provides consistent 6rem (96px) top clearance for fixed positioned HeaderBar
- Removes responsive padding variants that differed from competition page

This fixes header overlap issues across all main application routes.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 01:29:39 +08:00
hzb1115
1b654cf9d2 style(backend): go fmt code 2025-11-03 17:22:11 +00:00
Luna Martinez
04f3a20af9 Merge pull request #356 from xqliu/revert-pr-229-ut-infrastructure
Revert PR #229: Remove UT infrastructure
2025-11-03 12:13:16 -05:00
icy
bfbefa0b33 Fix: Unify all pages to use HeaderBar component consistently
Replace the inline header implementation in main app with HeaderBar component to match landing page:
- Remove duplicate inline header code (168 lines)
- Use HeaderBar component for all main app pages like landing page does
- Ensure consistent header design across all routes (/competition, /traders, /dashboard)
- Maintain proper onPageChange navigation handling
- Keep all header functionality (user info, admin mode, language toggle, logout)

This fixes the header inconsistency where different pages used different header implementations.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 01:04:16 +08:00
Liu Xiang Qian
72a373e9e4 Revert "Merge pull request #229 from xqliu/test/add-ut-infrastructure"
This reverts commit 683e77b92f, reversing
changes made to 791cecd2ff.
2025-11-04 00:58:12 +08:00
Icyoung
e044e8f6bd Merge pull request #355 from Icyoung/beta
Beta Competition kline count change to 5
2025-11-04 00:23:40 +08:00
icy
93544f7637 Merge branch 'beta' of github.com:Icyoung/nofx into beta 2025-11-04 00:18:34 +08:00
icy
f68cb60aeb Merge branch 'dev' into beta 2025-11-04 00:17:50 +08:00
icy
1ae1f90d8a Limit performance comparison chart to top 5 traders
Frontend changes to ensure equity-history-batch API only requests data for top 5 performers:
- Modify CompetitionPage to pass only top 5 traders to ComparisonChart component
- Update API comments to reflect the change from top 10 to top 5
- Optimize chart performance by reducing data volume and API calls

This ensures the performance comparison chart shows only the most relevant traders while improving load times.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 00:16:14 +08:00
ZhouYongyou
9e21793737 fix: GetTraderConfig missing critical fields in SELECT/Scan
**Problem**:
- GetTraderConfig was missing 9 critical fields in SELECT statement
- Missing corresponding Scan variables
- Caused trader edit UI to show 0 for leverage and empty trading_symbols

**Root Cause**:
Database query only selected basic fields (id, name, balance, etc.)
but missed leverage, trading_symbols, prompts, and all custom configs

**Fix**:
- Added missing fields to SELECT:
  * btc_eth_leverage, altcoin_leverage
  * trading_symbols
  * use_coin_pool, use_oi_top
  * custom_prompt, override_base_prompt
  * system_prompt_template
  * is_cross_margin
  * AI model custom_api_url, custom_model_name

- Added corresponding Scan variables to match SELECT order

**Impact**:
 Trader edit modal now displays correct leverage values
 Trading symbols list properly populated
 All custom configurations preserved and displayed
 API endpoint /traders/:id/config returns complete data

**Testing**:
-  Go compilation successful
-  All fields aligned (31 SELECT = 31 Scan)
-  API layer verified (api/server.go:887-904)

Reported by: 寒江孤影
Issue: Trader config edit modal showing 0 leverage and empty symbols

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 00:00:05 +08:00
Icyoung
a15239945b Merge pull request #353 from Icyoung/beta
Beta Fix Competition、Rank api cache、Dev merge
2025-11-03 23:57:43 +08:00
icy
dfaaf66ea7 Merge branch 'dev' into beta 2025-11-03 23:46:59 +08:00
icy
d5e0e1d8d5 Merge branch 'dev' of https://github.com/tinkle-community/nofx into dev 2025-11-03 23:46:54 +08:00
icy
5bd6333b7b Optimize /api/competition endpoint performance with concurrent data fetching and caching
## Performance Improvements:
- **Concurrent Processing**: Replace serial GetAccountInfo() calls with parallel goroutines
- **Timeout Control**: Add 3-second timeout per trader to prevent blocking
- **30-second Cache**: Implement competition data cache to reduce API calls
- **Error Handling**: Graceful degradation when API calls fail or timeout

## API Changes:
- Reduce top traders from 10 to 5 for better chart performance
- Update /api/equity-history-batch to use top 5 traders by default
- Add detailed logging for cache hits and performance monitoring

## Expected Performance Gains:
- First request: ~85% faster (from 25s to 3s for 50 traders)
- Cached requests: ~99.96% faster (from 25s to 10ms)
- Better user experience with consistent response times

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 23:45:09 +08:00
SkywalkerJi
683e77b92f Merge pull request #229 from xqliu/test/add-ut-infrastructure
test: Add minimal UT infrastructure and fix Issue #227
2025-11-04 00:28:34 +09:00
Icyoung
d6e1e28c71 Merge pull request #349 from Icyoung/beta
Beta Competition fix
2025-11-03 23:28:11 +08:00
Liu Xiang Qian
cc448bf6e2 fix: Remove unused variables in AITradersPage.test.tsx to fix TypeScript compilation
Fixed TypeScript compilation errors by removing unused imports and variables:
- Removed unused 'screen' import from test-utils
- Removed unused 'fetcher' parameter from SWR mock
- Removed unused 'mockTrader' variable
- Removed unused 'TraderInfo' type import

All tests still pass (5/5) and frontend now compiles successfully.
2025-11-03 23:20:55 +08:00
icy
e553adcdbb Merge branch 'dev' into beta 2025-11-03 23:19:52 +08:00
icy
c6b9479cac Merge branch 'tinkle-nofx/dev' with conflict resolution
- Resolve UI layout conflicts in App.tsx
- Keep modern Binance-style header with authentication logic
- Maintain responsive design and user interface improvements

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 23:19:25 +08:00
icy
e762939655 Prevent my-traders API calls when user is not logged in
- Add authentication checks to SWR calls in App.tsx and AITradersPage.tsx
- Only call api.getTraders when user and token are available
- Modify loadConfigs to skip authenticated API calls when not logged in
- Load only public supported models/exchanges for unauthenticated users
- Update useEffect dependencies to include user and token

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 23:14:10 +08:00