mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-18 09:54:35 +08:00
fix: 修復5個關鍵交易bug(保證金計算、部分平倉統計、止損止盈分離、雙向持倉)
## 修復內容 ### 1. 保證金計算錯誤(Critical) - 修正提示詞中的保證金公式(adaptive.txt, nof1.txt, default.txt) - 新增代碼級保證金驗證(auto_trader.go) - 防止開倉時保證金不足錯誤(code=-2019) ### 2. 部分平倉統計錯誤(Medium) - 修改統計邏輯:多次 partial_close 聚合為一筆交易 - 新增追蹤字段:remainingQuantity, accumulatedPnL - 只在完全平倉時計入 TotalTrades++ ### 3. 前端配置覆蓋問題(Medium) - 修正 TraderConfigModal.tsx 條件判斷 - 防止空字符串覆蓋用戶選擇的提示詞 ### 4/5. 動態止損/止盈刪除配對訂單(Critical) - 新增接口:CancelStopLossOrders, CancelTakeProfitOrders - 分離訂單取消邏輯(Binance, Hyperliquid, Aster) - 調整止損時不刪除止盈,反之亦然 ### 7. 雙向持倉模式初始化(Critical) - 新增 setDualSidePosition() 函數 - 在 NewFuturesTrader() 中初始化 Hedge Mode - 防止 code=-4061 錯誤(PositionSide 參數錯誤) ## 影響範圍 - 修改文件:10個 - 新增代碼:+480行 - 刪除代碼:-71行 ## 測試狀態 - ✅ 編譯通過(go build ./...) - ✅ 語法檢查通過 - ⚠️ 需要在測試環境運行驗證實際交易效果
This commit is contained in:
@@ -114,10 +114,19 @@ stop tightened to $2,950 (break-even). Exit fully if 4h MACD crosses down."
|
||||
|
||||
# POSITION SIZING FRAMEWORK
|
||||
|
||||
Calculate position size using this formula:
|
||||
**IMPORTANT**: `position_size_usd` is the **notional value** (includes leverage), NOT margin requirement.
|
||||
|
||||
Position Size (USD) = Available Cash × Leverage × Allocation %
|
||||
Position Size (Coins) = Position Size (USD) / Current Price
|
||||
## Calculation Steps:
|
||||
|
||||
1. **Available Margin** = Available Cash × 0.95 × Allocation % (reserve 5% for fees)
|
||||
2. **Notional Value** = Available Margin × Leverage
|
||||
3. **position_size_usd** = Notional Value (this is the value for JSON)
|
||||
4. **Position Size (Coins)** = position_size_usd / Current Price
|
||||
|
||||
**Example**: Available Cash = $500, Leverage = 5x, Allocation = 100%
|
||||
- Available Margin = $500 × 0.95 × 100% = $475
|
||||
- position_size_usd = $475 × 5 = **$2,375** ← Fill this value in JSON
|
||||
- Actual margin used = $475, remaining $25 for fees
|
||||
|
||||
## Sizing Considerations
|
||||
|
||||
|
||||
Reference in New Issue
Block a user