mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-07 11:17:56 +08:00
9884605c75
問題: - 調整止損/止盈時,直接調用 SetStopLoss/SetTakeProfit 會創建新訂單 - 但舊的止損/止盈單仍然存在,導致多個訂單共存 - 可能造成意外觸發或訂單衝突 解決方案(參考 PR #197): 1. 在 Trader 接口添加 CancelStopOrders 方法 2. 為三個交易所實現: - binance_futures.go: 過濾 STOP_MARKET/TAKE_PROFIT_MARKET 類型 - aster_trader.go: 同樣邏輯 - hyperliquid_trader.go: 過濾 trigger 訂單(有 triggerPx) 3. 在 executeUpdateStopLossWithRecord 和 executeUpdateTakeProfitWithRecord 中: - 先調用 CancelStopOrders 取消舊單 - 然後設置新止損/止盈 - 取消失敗不中斷執行(記錄警告) 優勢: - ✅ 避免多個止損單同時存在 - ✅ 保留我們的價格驗證邏輯 - ✅ 保留執行價格記錄 - ✅ 詳細錯誤信息 - ✅ 取消失敗時繼續執行(更健壯) 測試建議: - 開倉後調整止損,檢查舊止損單是否被取消 - 連續調整兩次,確認只有最新止損單存在 致謝:參考 PR #197 的實現思路
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
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 取消该币种的止盈/止损单(用于调整止盈止损位置)
|
|
CancelStopOrders(symbol string) error
|
|
|
|
// FormatQuantity 格式化数量到正确的精度
|
|
FormatQuantity(symbol string, quantity float64) (string, error)
|
|
}
|