Files
nofx/trader/interface.go
ZhouYongyou df2d6533de 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 ./...)
-  語法檢查通過
- ⚠️ 需要在測試環境運行驗證實際交易效果
2025-11-04 18:36:39 +08:00

55 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package trader
// Trader 交易器统一接口
// 支持多个交易平台币安、Hyperliquid等
type Trader interface {
// GetBalance 获取账户余额
GetBalance() (map[string]interface{}, error)
// GetPositions 获取所有持仓
GetPositions() ([]map[string]interface{}, error)
// OpenLong 开多仓
OpenLong(symbol string, quantity float64, leverage int) (map[string]interface{}, error)
// OpenShort 开空仓
OpenShort(symbol string, quantity float64, leverage int) (map[string]interface{}, error)
// CloseLong 平多仓quantity=0表示全部平仓
CloseLong(symbol string, quantity float64) (map[string]interface{}, error)
// CloseShort 平空仓quantity=0表示全部平仓
CloseShort(symbol string, quantity float64) (map[string]interface{}, error)
// SetLeverage 设置杠杆
SetLeverage(symbol string, leverage int) error
// SetMarginMode 设置仓位模式 (true=全仓, false=逐仓)
SetMarginMode(symbol string, isCrossMargin bool) error
// GetMarketPrice 获取市场价格
GetMarketPrice(symbol string) (float64, error)
// SetStopLoss 设置止损单
SetStopLoss(symbol string, positionSide string, quantity, stopPrice float64) error
// SetTakeProfit 设置止盈单
SetTakeProfit(symbol string, positionSide string, quantity, takeProfitPrice float64) error
// CancelAllOrders 取消该币种的所有挂单
CancelAllOrders(symbol string) error
// CancelStopOrders 取消该币种的止盈/止损单(已废弃:会同时删除止损和止盈)
// 请使用 CancelStopLossOrders 或 CancelTakeProfitOrders
CancelStopOrders(symbol string) error
// CancelStopLossOrders 仅取消止损单(修复 BUG调整止损时不删除止盈
CancelStopLossOrders(symbol string) error
// CancelTakeProfitOrders 仅取消止盈单(修复 BUG调整止盈时不删除止损
CancelTakeProfitOrders(symbol string) error
// FormatQuantity 格式化数量到正确的精度
FormatQuantity(symbol string, quantity float64) (string, error)
}