常見問題
首頁
幫助中心
常見問題
數字貨幣衍生品
合約交易
U本位合約
什麼是防範自行成交 (STP)?

什麼是防範自行成交 (STP)?

2023-08-29 07:03

什麼是防範自行成交 (STP)?

防範自行成交 (STP) 是交易平台採用的機制,用於防範用戶無意中與自己進行交易。當用戶自己的訂單在訂單簿上與自己的其他訂單配對時,就會發生這種情況,稱為自行成交。STP 有助於防範市場價格操縱,並確保交易活動準確反映真實的市場利益,對於維護公平透明的交易環境尤為重要。
在幣安,防範自行成交 (STP) 可防止用戶或用戶的「tradeGroupId」所發送的訂單與自己的訂單配對。

什麼是自行成交?

自行成交可能發生在以下任一種情況下:
  • 該訂單與同一帳戶交易。
  • 該訂單與具有相同「tradeGroupId」的帳戶進行交易。

觸發 STP 時會發生什麼事?

如果訂單觸發自行成交,系統將採取四種可能的模式。
  • NONE:此模式使訂單不受防範自行成交限制。帳戶或「tradeGroupId」不會被比對,訂單不會撤銷,而且交易將會發生。
  • EXPIRE_TAKER:此模式透過立即撤銷吃單方訂單的剩餘數量來阻止交易。
  • EXPIRE_MAKER:此模式透過立即撤銷潛在掛單方訂單的剩餘數量來阻止交易。
  • EXPIRE_BOTH:此模式透過立即撤銷吃單方和潛在掛單方訂單的剩餘數量來阻止交易。
STP 發生與否取決於吃單方訂單的 STP 模式。因此,訂單簿上的訂單 STP 模式已無關緊要,並且在所有未來訂單處理上將遭忽略。

如何設定訂單的 STP 模式?

STP 只能透過以下應用程式介面 (API) 端點,使用「selfTradePreventionMode」欄位進行設定:
  • POST /fapi/v1/order
  • POST /fapi/v1/batchOrders

什麼是「tradeGroupId」?

具有相同「tradeGroupId」的不同帳戶會被視為同一「交易群組」的一部分。交易群組成員提交的訂單會根據吃單方訂單的 STP 模式決定是否符合 STP 資格。
用戶可以透過 GET fapi/v2/account (REST API) 的 API,確認帳戶是否屬於同一「tradeGroupId」。
如果值為 -1,則表示帳戶尚未設定「tradeGroupId」,STP 只會在同一帳戶的訂單間發生。

哪些幣種支援 STP?

GET fapi/v1/exchangeInfo 中的所有幣種都支援 STP。

哪些訂單類型支援 STP?

當生效時間 (timeInForce) 設定為 GTC/IOC/GTD 時,下列訂單類型支援 STP:
  • 限價單
  • 市價單
  • 止盈訂單
  • 市價止損(止盈)單
  • 市價止盈單
  • 市價追蹤止損單
請注意,STP 不會對於 FOK 或 GTX 的生效時間 (timeInForce) 生效。

修改訂單是否支援 STP?

不。修改訂單不支援 STP。

如何判斷訂單是否因 STP 而撤銷?

訂單狀態將顯示為「EXPIRED_IN_MATCH」。在用戶資料串流事件「ORDER_TRADE_UPDATE」中,如果訂單因 STP 被撤銷,則欄位 X 將顯示「EXPIRED_IN_MATCH」。
{  "e":"ORDER_TRADE_UPDATE",      // Event Type  "E":1568879465651,             // Event Time  "T":1568879465650,             // Transaction Time  "o":{                                "s":"BTCUSDT",               // Symbol    "c":"TEST",                  // Client Order Id      // special client order id:      // starts with "autoclose-": liquidation order      // "adl_autoclose": ADL auto close order      // "settlement_autoclose-": settlement order for delisting or delivery    "S":"SELL",                  // Side    "o":"TRAILING_STOP_MARKET",  // Order Type    "f":"GTC",                   // Time in Force    "q":"0.001",                 // Original Quantity    "p":"0",                     // Original Price    "ap":"0",                    // Average Price    "sp":"7103.04",              // Stop Price. Please ignore with TRAILING_STOP_MARKET order    "x":"EXPIRED",               // Execution Type    "X":"EXPIRED_IN_MATCH",      // Order Status    "i":8886774,                 // Order Id    "l":"0",                     // Order Last Filled Quantity    "z":"0",                     // Order Filled Accumulated Quantity    "L":"0",                     // Last Filled Price    "N":"USDT",                  // Commission Asset, will not push if no commission    "n":"0",                     // Commission, will not push if no commission    "T":1568879465650,           // Order Trade Time    "t":0,                       // Trade Id    "b":"0",                     // Bids Notional    "a":"9.91",                  // Ask Notional    "m":false,                   // Is this trade the maker side?    "R":false,                   // Is this reduce only    "wt":"CONTRACT_PRICE",       // Stop Price Working Type    "ot":"TRAILING_STOP_MARKET", // Original Order Type    "ps":"LONG",                 // Position Side    "cp":false,                  // If Close-All, pushed with conditional order    "AP":"7476.89",              // Activation Price, only pushed with TRAILING_STOP_MARKET order    "cr":"5.0",                  // Callback Rate, only pushed with TRAILING_STOP_MARKET order    "pP": false,                 // ignore    "si": 0,                     // ignore    "ss": 0,                     // ignore    "rp":"0"                     // Realized Profit of the trade    "V": "NONE".                 // selfTradePreventionMode    "pm":"QUEUE"                 // price match type    "gtd":1768879465650          // good till date   }}

STP 範例

對於所有案例,假設這些範例的所有訂單都在同一帳戶進行。
Maker Order: symbol=BTCUSDT side=BUY  type=LIMIT quantity=1 price=20000 selfTradePreventionMode=NONE Taker Order: symbol=BTCUSDT side=SELL type=LIMIT quantity=1 price=20000 selfTradePreventionMode=NONE
結果:STP 未觸發,訂單將配對。
掛單方訂單的訂單狀態:
{    "orderId": 292864713,    "symbol": "BTCUSDT",    "status": "FILLED",    "clientOrderId": "43N239GaUaqshfG7825184",    "price": "20000",    "avgPrice": "20000",    "origQty": "1",    "executedQty": "1",    "cumQty": "1",    "cumQuote": "20000",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "NONE",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "updateTime": 1692849639460}
吃單方訂單的訂單狀態:
{    "orderId": 292864714,    "symbol": "BTCUSDT",    "status": "FILLED",    "clientOrderId": "43N239GaUaqshfG7825184",    "price": "20000",    "avgPrice": "20000",    "origQty": "1",    "executedQty": "1",    "cumQty": "1",    "cumQuote": "20000",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "SELL",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "NONE",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "updateTime": 1692849639460}
Maker Order 1: symbol=BTCUSDT side=BUY  type=LIMIT quantity=1 price=20002 selfTradePreventionMode=NONE Maker Order 2: symbol=BTCUSDT side=BUY  type=LIMIT quantity=1 price=20001 selfTradePreventionMode=NONE Taker Order 1: symbol=BTCUSDT side=SELL type=LIMIT quantity=1 price=20000 selfTradePreventionMode=EXPIRE_MAKER
結果:訂單簿上的既有訂單因 STP 將被撤銷,吃單方訂單將記錄在訂單簿上。
掛單方訂單 1:
{    "orderId": 292864710,    "symbol": "BTCUSDT",    "status": "FILLED",    "clientOrderId": "testMaker1",    "price": "20002",    "avgPrice": "20002",    "origQty": "1",    "executedQty": "1",    "cumQuote": "20002",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "NONE",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
掛單方訂單 2:
{    "orderId": 292864711,    "symbol": "BTCUSDT",    "status": "EXPIRED_IN_MATCH",    "clientOrderId": "testMaker2",    "price": "20001",    "avgPrice": "0.0000",    "origQty": "1",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "NONE",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
吃單方訂單的輸出內容:
{    "orderId": 292864712,    "symbol": "BTCUSDT",    "status": "PARTIALLY_FILLED",    "clientOrderId": "testTaker1",    "price": "20000",    "avgPrice": "20002",    "origQty": "2",    "executedQty": "1",    "cumQuote": "20002",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "SELL",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "EXPIRE_MAKER",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
Maker Order 1: symbol=BTCUSDT side=BUY  type=LIMIT quantity=1 price=20002  selfTradePreventionMode=NONE Maker Order 2: symbol=BTCUSDT side=BUY  type=LIMIT quantity=1 price=20001  selfTradePreventionMode=NONE Taker Order 1: symbol=BTCUSDT side=SELL type=LIMIT quantity=2 price=20000      selfTradePreventionMode=EXPIRE_TAKER
結果:訂單簿上的既有訂單將保留,而吃單方訂單將被撤銷。
掛單方訂單 1:
{    "orderId": 292864710,    "symbol": "BTCUSDT",    "status": "NEW",    "clientOrderId": "testMaker1",    "price": "20002",    "avgPrice": "0.0000",    "origQty": "1",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "NONE",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
掛單方訂單 2:
{    "orderId": 292864711,    "symbol": "BTCUSDT",    "status": "NEW",    "clientOrderId": "testMaker2",    "price": "20001",    "avgPrice": "0.0000",    "origQty": "1",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "NONE",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
吃單方訂單的輸出內容:
{    "orderId": 292864712,    "symbol": "BTCUSDT",    "status": "EXPIRED_IN_MATCH",    "clientOrderId": "testTaker1",    "price": "20000",    "avgPrice": "0.0000",    "origQty": "3",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "SELL",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "EXPIRE_TAKER",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
Maker Order: symbol=BTCUSDT side=BUY  type=LIMIT quantity=1 price=20002 selfTradePreventionMode=NONETaker Order: symbol=BTCUSDT side=SELL type=LIMIT quantity=3 price=20000 selfTradePreventionMode=EXPIRE_BOTH
結果:兩筆訂單都會被撤銷。
掛單方訂單:
{    "orderId": 292864710,    "symbol": "BTCUSDT",    "status": "EXPIRED_IN_MATCH",    "clientOrderId": "testMaker1",    "price": "20002",    "avgPrice": "0.0000",    "origQty": "1",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "NONE",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
吃單方訂單:
{    "orderId": 292864712,    "symbol": "BTCUSDT",    "status": "EXPIRED_IN_MATCH",    "clientOrderId": "testTaker1",    "price": "20000",    "avgPrice": "0.0000",    "origQty": "3",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "SELL",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "EXPIRE_BOTH",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
Maker Order: symbol=BTCUSDT side=BUY  type=LIMIT quantity=1 price=20002 selfTradePreventionMode=EXPIRE_MAKER Taker Order: symbol=BTCUSDT side=SELL type=LIMIT quantity=1 price=20000 selfTradePreventionMode=EXPIRE_TAKER
結果:吃單方訂單的 STP 模式將被觸發,因此吃單方訂單將被撤銷。
掛單方訂單:
{    "orderId": 292864710,    "symbol": "BTCUSDT",    "status": "NEW",    "clientOrderId": "testMaker1",    "price": "20002",    "avgPrice": "0.0000",    "origQty": "1",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "EXPIRE_MAKER",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
吃單方訂單:
{    "orderId": 292864712,    "symbol": "BTCUSDT",    "status": "EXPIRED_IN_MATCH",    "clientOrderId": "testTaker1",    "price": "20000",    "avgPrice": "0.0000",    "origQty": "1",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "SELL",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "EXPIRE_TAKER",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
Maker Order: symbol=BTCUSDT side=BUY  type=LIMIT  quantity=1 price=20002  selfTradePreventionMode=NONE Taker Order: symbol=BTCUSDT side=SELL type=MARKET quantity=3 selfTradePreventionMode=EXPIRE_MAKER
結果:既有訂單將因 STP 被撤銷,狀態顯示為「EXPIRED_IN_MATCH」。新訂單也會被撤銷,但由於訂單簿的低流動性,狀態會顯示為「EXPIRED」。
掛單方訂單:
{    "orderId": 292864710,    "symbol": "BTCUSDT",    "status": "EXPIRED_IN_MATCH",    "clientOrderId": "testMaker1",    "price": "20002",    "avgPrice": "0.0000",    "origQty": "1",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "LIMIT",    "reduceOnly": false,    "closePosition": false,    "side": "BUY",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "EXPIRE_MAKER",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}
吃單方訂單:
{    "orderId": 292864712,    "symbol": "BTCUSDT",    "status": "EXPIRED",    "clientOrderId": "testTaker1",    "price": "20000",    "avgPrice": "0.0000",    "origQty": "3",    "executedQty": "0",    "cumQuote": "0",    "timeInForce": "GTC",    "type": "MARKET",    "reduceOnly": false,    "closePosition": false,    "side": "SELL",    "positionSide": "BOTH",    "stopPrice": "0",    "workingType": "CONTRACT_PRICE",    "priceMatch": "NONE",    "selfTradePreventionMode": "EXPIRED",    "goodTillDate": 0,    "priceProtect": false,    "origType": "LIMIT",    "time": 1692849639460,    "updateTime": 1692849639460}