feat(trader): implement margin mode handling for order and leverage settings

This commit is contained in:
Dean
2026-04-14 17:42:05 +08:00
parent e1b5a5d833
commit a3d8831b36
5 changed files with 204 additions and 14 deletions

View File

@@ -41,9 +41,11 @@ func (t *OKXTrader) OpenLong(symbol string, quantity float64, leverage int) (map
szStr = t.formatSize(sz, inst)
}
marginMode := t.marginMode()
body := map[string]interface{}{
"instId": instId,
"tdMode": "cross",
"tdMode": marginMode,
"side": "buy",
"posSide": "long",
"ordType": "market",
@@ -118,9 +120,11 @@ func (t *OKXTrader) OpenShort(symbol string, quantity float64, leverage int) (ma
szStr = t.formatSize(sz, inst)
}
marginMode := t.marginMode()
body := map[string]interface{}{
"instId": instId,
"tdMode": "cross",
"tdMode": marginMode,
"side": "sell",
"posSide": "short",
"ordType": "market",
@@ -410,9 +414,11 @@ func (t *OKXTrader) SetStopLoss(symbol string, positionSide string, quantity, st
posSide = "short"
}
marginMode := t.marginMode()
body := map[string]interface{}{
"instId": instId,
"tdMode": "cross",
"tdMode": marginMode,
"side": side,
"posSide": posSide,
"ordType": "conditional",
@@ -453,9 +459,11 @@ func (t *OKXTrader) SetTakeProfit(symbol string, positionSide string, quantity,
posSide = "short"
}
marginMode := t.marginMode()
body := map[string]interface{}{
"instId": instId,
"tdMode": "cross",
"tdMode": marginMode,
"side": side,
"posSide": posSide,
"ordType": "conditional",
@@ -815,9 +823,11 @@ func (t *OKXTrader) PlaceLimitOrder(req *types.LimitOrderRequest) (*types.LimitO
posSide = "short"
}
marginMode := t.marginMode()
body := map[string]interface{}{
"instId": instId,
"tdMode": "cross",
"tdMode": marginMode,
"side": side,
"posSide": posSide,
"ordType": "limit",