幣安槓桿為所有全倉和逐倉用戶提供四個不同的下單交易介面:
- POST /sapi/v1/margin/order
- POST /sapi/v1/margin/order/oco
- POST /sapi/v1/margin/order/oto
- POST /sapi/v1/margin/order/otoco
其中參數sideEffectType為訂單介面設定以下四種交易模式:
- NO_SIDE_EFFECT(普通模式): 直接使用槓桿賬戶內的現有數字資產下買/賣單。這種模式下,用戶需要在槓桿平台上手動借款/還款,或通過 POST /sapi/v1/margin/borrow-repay 借款/還款。
- MARGIN_BUY(自動借款模式):根據用戶的最大槓桿倍數,自動借入數字資產下買/賣單。簡而言之,相當於「借款 + 下單」。注意:下單成功即完成借款,借款與訂單成交沒有關係。
- AUTO_REPAY(自動還款模式):買/賣單成交後,系統自動使用收到的數字資產來償還該資產的負債。簡而言之,相當於「下單 + 訂單成交 + 還款」。還款依然遵循借什麼還什麼,先還利息再還本金的原則。
- 自動還款模式不適用於介面“/sapi/v1/margin/order/otoco” 和 “/sapi/v1/margin/order/oto”。
- AUTO_BORROW_REPAY(同時自動借款和還款):用户在下單時,結合MARGIN_BUY 和 AUTO_REPAY兩種模式,完成「借款 + 下單 + 訂單成交 + 還款」。
- 自動借款和還款模式不適用於介面“/sapi/v1/margin/order/otoco” 和 “/sapi/v1/margin/order/oto”。
參數sideEffectType設定不同交易模式舉例:
場景1
用戶A持有 1 BTC 資產和 10,000 USDC負債,調用 POST /sapi/v1/margin/order 介面,設定sideEffectType為NO_SIDE_EFFECT。以價格 40,000 USDC下單賣出 1 BTC後,用戶持有40,000 USDC資產和10,000 USDC負債。接口呼叫參數和返回參數如下:
呼叫參數:
Parameter | Value |
symbol | BTCUSDC |
isIsolated | FALSE |
side | SELL |
type | Limit |
quantity | 1 |
quoteOrderQty | |
price | 40,000 |
stopPrice | |
newClientOrderId | |
icebergQty | |
newOrderRespType | |
sideEffectType | NO_SIDE_EFFECT |
timeInForce | GTC |
selfTradePreventionMode | NONE |
autoRepayAtCancel | |
recvWindow | |
timestamp | 1507725176595 |
返回參數:
{
"symbol": "BTCUSDC",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "40000.00000000",
"origQty": "1.00000000",
"executedQty": "1.00000000",
"cummulativeQuoteQty": "1.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "Limit",
"side": "SELL",
"isIsolated": false, // 是否是逐倉symbol交易
"selfTradePreventionMode": "NONE",
"fills": [
{
"price": "40000.00000000",
"qty": "1.00000000",
"commission": "40.00000000",
"commissionAsset": "USDC"
}
]
}
場景2
用戶B持有 1 BTC資產和10,000 USDC負債,調用 POST /sapi/v1/margin/order 介面,設定sideEffectType為MARGIN_BUY。以價格40,000 USDT下單買入0.5 BTC後,系統自動借入20,000 USDC負債。最後用戶持有1.5 BTC資產和30,000 USDC負債。
呼叫參數:
Parameter | Value |
symbol | BTCUSDC |
isIsolated | FALSE |
side | BUY |
type | Limit |
quantity | 0.5 |
quoteOrderQty | |
price | 40,000 |
stopPrice | |
newClientOrderId | |
icebergQty | |
newOrderRespType | |
sideEffectType | MARGIN_BUY |
timeInForce | GTC |
selfTradePreventionMode | NONE |
autoRepayAtCancel | TRUE |
recvWindow | |
timestamp | 1507725176595 |
返回參數:
{
"symbol": "BTCUSDC",
"orderId": 29,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "40000.00000000",
"origQty": "0.50000000",
"executedQty": "0.50000000",
"cummulativeQuoteQty": "0.50000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "Limit",
"side": "BUY",
"marginBuyBorrowAmount": 20000, // 下單後沒有發生借款則不返回該字段
"marginBuyBorrowAsset": "USDC", // 下單後沒有發生借款則不返回該字段
"isIsolated": false, // 是否是逐倉symbol交易
"selfTradePreventionMode": "NONE",
"fills": [
{
"price": "40000.00000000",
"qty": "0.50000000",
"commission": "20.00000000",
"commissionAsset": "USDC"
}
]
}
場景3
用戶C持有1 BTC資產和10,000 USDC負債,調用 POST /sapi/v1/margin/order 介面,設定sideEffectType為AUTO_REPAY。以價格 40,000 USDT下單賣出 1 BTC後,系統自動歸還10,000 USDC負債(忽略所產生的利息)。最後用戶持有30,000 USDC資產,沒有負債。
呼叫參數:
Parameter | Value |
symbol | BTCUSDC |
isIsolated | FALSE |
side | SELL |
type | Limit |
quantity | 1 |
quoteOrderQty | |
price | 40,000 |
stopPrice | |
newClientOrderId | |
icebergQty | |
newOrderRespType | |
sideEffectType | AUTO_REPAY |
timeInForce | GTC |
selfTradePreventionMode | NONE |
autoRepayAtCancel | |
recvWindow | |
timestamp | 1507725176595 |
返回參數:
{
"symbol": "BTCUSDC",
"orderId": 30,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "40000.00000000",
"origQty": "1.00000000",
"executedQty": "1.00000000",
"cummulativeQuoteQty": "1.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "Limit",
"side": "SELL",
"isIsolated": false, // 是否是逐倉symbol交易
"selfTradePreventionMode": "NONE",
"fills": [
{
"price": "40000.00000000",
"qty": "1.00000000",
"commission": "40.00000000",
"commissionAsset": "USDC"
}
]
}
"symbol": "BTCUSDC",
"orderId": 30,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "40000.00000000",
"origQty": "1.00000000",
"executedQty": "1.00000000",
"cummulativeQuoteQty": "1.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "Limit",
"side": "SELL",
"isIsolated": false, // 是否是逐倉symbol交易
"selfTradePreventionMode": "NONE",
"fills": [
{
"price": "40000.00000000",
"qty": "1.00000000",
"commission": "40.00000000",
"commissionAsset": "USDC"
}
]
}
場景4
用戶D持有1 BTC資產和10,000 USDC負債,調用 POST /sapi/v1/margin/order 介面,設定sideEffectType為AUTO_BORROW_REPAY。以價格 2,500 USDC下單賣出 4 ETH,系統自動借入4 ETH負債,同時歸還10,000 USDC負債(忽略所產生的利息)。最後用戶持有1 BTC 資產和4 ETH負債。
呼叫參數:
Parameter | Value |
symbol | ETHUSDC |
isIsolated | FALSE |
side | SELL |
type | Limit |
quantity | 4 |
quoteOrderQty | |
price | 2,500 |
stopPrice | |
newClientOrderId | |
icebergQty | |
newOrderRespType | |
sideEffectType | AUTO_BORROW_REPAY |
timeInForce | GTC |
selfTradePreventionMode | NONE |
autoRepayAtCancel | TRUE |
recvWindow | |
timestamp | 1507725176595 |
返回參數:
{
"symbol": "ETHUSDC",
"orderId": 31,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "2500.00000000",
"origQty": "4.00000000",
"executedQty": "4.00000000",
"cummulativeQuoteQty": "4.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "Limit",
"side": "SELL",
"marginBuyBorrowAmount": 4, // 下單後沒有發生借款則不返回該字段
"marginBuyBorrowAsset": "ETH", // 下單後沒有發生借款則不返回該字段
"isIsolated": false, // 是否是逐倉symbol交易
"selfTradePreventionMode": "NONE",
"fills": [
{
"price": "2500.00000000",
"qty": "4.00000000",
"commission": "10.00000000",
"commissionAsset": "USDC"
}
]
}
"symbol": "ETHUSDC",
"orderId": 31,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "2500.00000000",
"origQty": "4.00000000",
"executedQty": "4.00000000",
"cummulativeQuoteQty": "4.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "Limit",
"side": "SELL",
"marginBuyBorrowAmount": 4, // 下單後沒有發生借款則不返回該字段
"marginBuyBorrowAsset": "ETH", // 下單後沒有發生借款則不返回該字段
"isIsolated": false, // 是否是逐倉symbol交易
"selfTradePreventionMode": "NONE",
"fills": [
{
"price": "2500.00000000",
"qty": "4.00000000",
"commission": "10.00000000",
"commissionAsset": "USDC"
}
]
}
用戶可前往 槓桿帳戶和交易介面 查看所有介面說明。