XT DOC logo

简体中文
english
Spot Futures
现货 合约

REST API Edit

Official:

USDT-M:https://fapi.xt.com

Coin-M:https://dapi.xt.com

Basic Information of the Interface Edit

Due to the reasons of high latency and poor stability, it is not recommend to access the XT API through a proxy.

GET request parameters are put in query Params, POST request parameters are put in request body.

The request header information is set to: Content-Type=application/x-www-form-urlencoded

In addition to the parameters required by the interface itself, signature, which is the signature parameter, needs to be passed in the query Params or request body. The interface that does not need to pass the signature parameter will be additionally explained.

Frequency Limiting Rules Edit

Get assets 3 times per second, other methods 10 times per second for each single user, 1000 times per minute for each single IP, exceeding the requested times, account will be locked for 10 minutes.

Signature Statement Edit

Since XT needs to provide some open interfaces for third-party platforms, it requires data security issues of the interface, such as whether the data has been tampered with, whether the data is outdated, whether the data can be submitted repeatedly, and the frequency of access to the interface within a certain period of time. Among them, whether the data has been tampered with is most important.

  1. Offline distribution of appkey and secretkey, for different calls, provide different appkey and secretkey.

  2. Add timestamp, the value of which should be the unix timestamp (milliseconds) of the time when the request is sent, and the valid time of the data is calculated according to this value.

  3. Add signature information for all data.

  4. Add recvwindow, the valid time is relatively simple and fixed to a certain value. For example, the data is valid within 10 minutes under the same api and appid. Here, it can be further optimized to the valid time of a single api is different.

The server determines the timestamp when it receives a request. Up to 60 seconds, and the default is 5 seconds. If it was sent 5000 milliseconds ago, the request will be considered invalid. This time window value can be customized by sending the optional parameter recvWindow. In addition, the server will also reject the request if it calculates that the client timestamp is more than one second ‘in the future’ of server time. Regarding the transaction timeliness, the Internet is not 100% reliable and cannot be completely relied upon, so your application’s local time delay to the XT server may be jitter.This is the purpose of setting recvWindow. If you are engaged in high-frequency trading and have high requirements for trading timeliness, you can flexibly set recvWindow to meet your requirements.

RecvWindow for more than 5 seconds is not recommended.

5、5. Add algorithms (signature method/algorithm). User’s signature calculation is a HSC-based protocol, where HmacSHA256 is used by default. See the specific supported protocols listed in the table below.

Name Mandatory Example Description
xt-validate-appkey true dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83
xt-validate-timestamp true 1641446237201
xt-validate-signature true 0a7d0b5e802eb5e52ac0cfcd6311b0faba6e2503a9a8d1e2364b38617877574d
xt-validate-recvwindow false 5000(millisecond)
xt-validate-algorithms false HmacSHA256 HmacMD5、HmacSHA1、HmacSHA224、HmacSHA256、HmacSHA384、HmacSHA512,默认为:HmacSHA256
xt-api-version false 1.0 Reserved, API version number
xt-validate-signversion false 1.0 Reserved, signature version number

Obtain Signature Edit

Example for http://fapi.xt.com/api/v1/public/symbol/detail?symbol=btc_usdt

The following is an example of an order placed in a call interface using echo openssl and curl tools in a Linux bash environment. Appkey, secret for demonstration purposes only:

appKey: 3976eb88-76d0-4f6e-a6b2-a57980770085

secretKey: bc6630d0231fda5cd98794f52c4998659beda290

Partial data of Header:

xt-validate-appkey: 3976eb88-76d0-4f6e-a6b2-a57980770085

xt-validate-timestamp: 1641446237201

xt-validate-algorithms: HmacSHA256

Request data:

{ type: ‘LIMIT’, timeInForce: ‘GTC’, side: ‘BUY’, symbol: ‘btc_usdt’, price: ‘39000’, quantity: ‘2’ }

1、Data

path: Concatenate all values in the order in path. The restful path in the form of /test/{var1}/{var2}/ will be spliced according to the actual parameters filled in, for example: /sign/test/bb/aa

query: Sorted by lexicographic order of key, concatenate all key=value. Example: userName=dfdfdf&password=ggg

body: Json: Operate as JSON string is not converted or sorted.

      x-www-form-urlencoded: Sorted by lexicographic order of key, concatenate all key=value. Example: userName=dfdfdf&password=ggg 

      form-data:Not supported.

If there are multiple data forms, re-concatenate in the order of path, query, and body to obtain the concatenate value of all data.

Example of Path:

      /future/api/v1/public/symbol/detail

      The above concatenated value is recorded as path

Example 1: All parameters sent via query string

        symbol=btc_usdt&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1

        The above concatenate value is recorded as query

Example 2: All parameters send X-www-form-urlencoded request body string via the request body

Request body string of json

        symbol=btc_usdt&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1

        The above concatenate value is recorded as body

Request body string of www-form-urlencoded

        {"symbol" : "btc_usdt","side" : "BUY","type":"LIMIT","timeInForce":"GTC","quantity":2,"price":39000}

        The above concatenate value is recorded as body

Example 3: Mix to use query string and request body (form and json format)

queryString: symbol=btc_usdt&side=BUY&type=LIMIT&timeInForce=GTC 上述拼接值记作query

requestBody: {“quantity”:2,”price”:39000} The above concatenate value is recorded as query

    The final concatenate value of the entire data is # concatenated with path, query, and body and form #path, #query, and #body. The finalconcatenate value is recorded asY=#path#query#body。

    Note:

        query without data, body with data:Y=#path#body

        query with data, body without data:Y=#path#query

        query with data, body with data:Y=#path#query#body

2:Request header X=”xt-validate-appkey=3976eb88-76d0-4f6e-a6b2-a57980770085&xt-validate-timestamp=1641446237201”

3:Obtain Signature

Finally, record the string that needs to be encrypted as sign=XY

Finally, encrypt the final concatenated value according to the following method to obtain a signature.

signature=org.apache.commons.codec.digest.HmacUtils.hmacSha256Hex(secretkey, sign);

Put the generated signature in the request header, with xt-validate-signature as the key and singature as the value.

How to Apply for API Key Edit

The interface may require the user’s API Key, please refer to how to create an API-KEY this page(https://xtsupport.zendesk.com/hc/zh-cn/articles/900006868163-%E5%A6%82%E4%BD%95%E7%94%B3%E8%AF%B7API%E4%BA%A4%E6%98%93-%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BAAPI%E5%AF%86%E9%92%A5-)

API Library Edit

Java connector

A lightweight Java code library that provides a method for users to directly call the API

https://github.com/futuresee/api-demo-java

Return Format Edit

All interfaces’ returns are in JSON format.

{
    "returnCode": 200,
    "result": {
        "serverTime": 1636612706739
    },
    "msgInfo": "Success."
    "error": null,
}

Error Code Edit

Status code Error information
200 Success
401 Login required
403 Login expired

Get Trading Pair Currency Edit

/future/market/v1/public/symbol/coins

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [],
  "returnCode": 0
}

Get Configuration Information for Single Trading Pair Edit

/future/market/v1/public/symbol/detail

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "baseCoin": "", //Target Assets
    "baseCoinDisplayPrecision": 0, //Displayed target currency precision
    "baseCoinPrecision": 0, //Target currency precision
    "contractSize": 0, //Contract multiplier(face value)
    "contractType": "", //Contract type, perpetual, delivery
    "depthPrecisionMerge": 0, //Handicap Precision Consolidation
    "initLeverage": 0, //Initial leverage
    "labels": [], //Label
    "liquidationFee": 0, //Forced liquidation fee
    "makerFee": 0, //Maker fee
    "maxEntrusts": 0, //Maximum active orders
    "maxOpenOrders": 0, //Maximum open orders
    "minNotional": 0, //Minimum notional value
    "minPrice": 0, //Minimum price
    "minQty": 0, //Minimum quantity
    "multiplierDown": 0, //Floor percentage of sell limit order
    "multiplierUp": 0, //Cap percentage of buy limit order
    "onboardDate": 0, //List time
    "pricePrecision": 0, //Price precision
    "quantityPrecision": 0, //Quantity precision
    "quoteCoin": "", //Quote currency
    "quoteCoinDisplayPrecision": 0, //Displayed quote currency precision
    "quoteCoinPrecision": 0, //Quote currency precision
    "state": 0, //Status
    "supportEntrustType": "", //Trigger order type supported
    "supportOrderType": "", //Order type supported
    "supportTimeInForce": "", //Valid ways supported
    "symbol": "", //Trading pair
    "takerFee": 0, //Taker fee
    "tradeSwitch": false, //Trading pair switch
    "underlyingType": "" //Target type, Coin-M,USDT-M
  },
  "returnCode": 0
}

Get Configuration Information for All Trading Pairs Edit

/future/market/v1/public/symbol/list

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "baseCoin": "", //Target Assets
      "baseCoinDisplayPrecision": 0, //Displayed target currency precision
      "baseCoinPrecision": 0, //Target currency precision
      "contractSize": 0, //Contract multiplier(face value)
      "contractType": "", //Contract type, perpetual, delivery
      "depthPrecisionMerge": 0, //Handicap Precision Consolidation
      "initLeverage": 0, //Initial leverage
      "labels": [], //Label
      "liquidationFee": 0, //Forced liquidation fee
      "makerFee": 0, //Maker fee
      "maxEntrusts": 0, //Maximum active orders
      "maxOpenOrders": 0, //Maximum open orders
      "minNotional": 0, //Minimum notional value
      "minPrice": 0, //Minimum price
      "minQty": 0, //Minimum quantity
      "multiplierDown": 0, //Floor percentage of sell limit order
      "multiplierUp": 0, //Cap percentage of buy limit order
      "onboardDate": 0, //List time
      "pricePrecision": 0, //Price precision
      "quantityPrecision": 0, //Quantity precision
      "quoteCoin": "", //Quote currency
      "quoteCoinDisplayPrecision": 0, //Displayed quote currency precision
      "quoteCoinPrecision": 0, //Quote currency precision
      "state": 0, //Status
      "supportEntrustType": "", //Trigger order type supported
      "supportOrderType": "", //Order type supported
      "supportTimeInForce": "", //Valid ways supported
      "symbol": "", //Trading pair
      "takerFee": 0, //Taker fee
      "tradeSwitch": false, //Trading pair switch
      "underlyingType": "" //Target type, Coin-M,USDT-M
    }
  ],
  "returnCode": 0
}

See Leverage Stratification of Single Trading Pair Edit

/future/market/v1/public/leverage/bracket/detail

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "leverageBrackets": [
      {
        "bracket": 0, //Level
        "maintMarginRate": 0, //Maintain margin rate
        "maxLeverage": 0, //Maximum leverage
        "maxNominalValue": 0, //Maximum notional value
        "maxStartMarginRate": 0, //Maximum initial margin rate
        "minLeverage": 0, //Minimum leverage
        "startMarginRate": 0, //Initial margin rate
        "symbol": "" //Trading pair
      }
    ],
    "symbol": ""
  },
  "returnCode": 0
}

See Leverage Stratification of All Trading Pairs Edit

/future/market/v1/public/leverage/bracket/list

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "leverageBrackets": [
        {
          "bracket": 0, //Level
          "maintMarginRate": 0, //Maintain margin rate
          "maxLeverage": 0, //Maximum leverage
          "maxNominalValue": 0, //Maximum notional value
          "maxStartMarginRate": 0, //Maximum initial margin rate
          "minLeverage": 0, //Minimum leverage
          "startMarginRate": 0, //Initial margin rate
          "symbol": "" //Trading pair
        }
      ],
      "symbol": ""
    }
  ],
  "returnCode": 0
}

Get Market Information for Specific Trading Pair Edit

/future/market/v1/public/q/ticker

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "a": "", //24h volume
    "c": "", //Latest price
    "h": "", //Highest price in 24 hours
    "l": "", //Lowest price in 24 hours
    "o": "", //The first transaction price 24 hours ago
    "r": "", //24h Price Fluctuation Limit
    "s": "", //Trading pair
    "t": 0, //Time
    "v": "" //24h turnover
  },
  "returnCode": 0
}

Get Market Information for All Trading Pairs Edit

/future/market/v1/public/q/tickers

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": "", //24h volume
      "c": "", //Latest price
      "h": "", //Highest price in 24 hours
      "l": "", //Lowest price in 24 hours
      "o": "", //The first transaction price 24 hours ago
      "r": "", //24h Price Fluctuation Limit
      "s": "", //Trading pair
      "t": 0, //Time
      "v": "" //24h turnover
    }
  ],
  "returnCode": 0
}

Get Latest Transaction Information of Trading Pairs Edit

/future/market/v1/public/q/deal

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
num integer true N/A Quantity

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": 0, //Volume
      "m": "", //Order side
      "p": 0, //Price
      "s": "", //Trading pair
      "t": 0 //Time
    }
  ],
  "returnCode": 0
}

Get Depth Data of Trading Pairs Edit

/future/market/v1/public/q/depth

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
level integer true N/A Level(min:1,max:50)

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "a": [], //Buy
    "b": [], //Sell
    "s": "", //Trading pair
    "t": 0, //Time
    "u": 0 //updateId
  },
  "returnCode": 0
}

Get Index Price for Single Trading Pair Edit

/future/market/v1/public/q/symbol-index-price

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "p": 0, //Price
    "s": "", //Trading pair
    "t": 0 //Time
  },
  "returnCode": 0
}

Get Index Price for All Trading Pairs Edit

/future/market/v1/public/q/index-price

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "p": 0, //Price
      "s": "", //Trading pair
      "t": 0 //Time
    }
  ],
  "returnCode": 0
}

Get Mark Price for Single Trading Pair Edit

/future/market/v1/public/q/symbol-mark-price

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "p": 0, //Price
    "s": "", //Trading pair
    "t": 0 //Time
  },
  "returnCode": 0
}

Get Mark Price for All Trading Pairs Edit

/future/market/v1/public/q/mark-price

Parameters
Parameter Type mandatory Default Description Ranges
symbol string false N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "p": 0, //Price
      "s": "", //Trading pair
      "t": 0 //Time
    }
  ],
  "returnCode": 0
}

Get Trading Pair Information of Kline Edit

/future/market/v1/public/q/kline

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
interval string true N/A Time-interval 1m;5m;15m;30m;1h;4h;1d;1w
startTime integer false N/A Start time
endTime integer false N/A End time
limit integer false N/A Limit

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": 0, //Volume
      "c": 0, //Close price
      "h": 0, //Highest price
      "l": 0, //Lowest price
      "o": 0, //Open price
      "s": "", //Trading pair
      "t": 0, //Time
      "v": 0 //Turnover
    }
  ],
  "returnCode": 0
}

Get Aggregated Market Information for Specific Trading Pair Edit

/future/market/v1/public/q/agg-ticker

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "a": "", //24h volume
    "ap": "", //ask price
    "bp": "", //bid price
    "c": "", //Latest price
    "h": "", //Highest price in 24 hours
    "i": "", //index price
    "l": "", //Lowest price in 24 hours
    "m": "", //mark price
    "o": "", //The first transaction price 24 hours ago
    "r": "", //24h price fluctuation limit
    "s": "", //Trading pair
    "t": 0, //Time
    "v": "" //24h Turnover
  },
  "returnCode": 0
}

Get Aggregated Market Information for All Trading Pairs Edit

/future/market/v1/public/q/agg-tickers

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": "", //24h volume
      "ap": "", //ask price
      "bp": "", //bid price
      "c": "", //Latest price
      "h": "", //Highest price in 24 hours
      "i": "", //index price
      "l": "", //Lowest price in 24 hours
      "m": "", //mark price
      "o": "", //The first transaction price 24 hours ago
      "r": "", //24h price fluctuation limit
      "s": "", //Trading pair
      "t": 0, //Time
      "v": "" //24h Turnover
    }
  ],
  "returnCode": 0
}

Get Funding Rate Information Edit

/future/market/v1/public/q/funding-rate

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //Is there a next page
    "hasPrev": false, //Is there a previous page
    "items": [ //Datasheets
      {
        "collectionInternal": 0, //Billing Cycle (second)
        "createdTime": 0, //Time
        "fundingRate": 0, //Latest funding rate
        "id": 0, //id
        "symbol": "" //Trading pair
      }
    ]
  },
  "returnCode": 0
}

Get Funding Rate Records Edit

/future/market/v1/public/q/funding-rate-record

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
direction string false NEXT Direction(PREV:Previous page;NEXT:Next page) PREV;NEXT
id integer false N/A id
limit integer false 10 Limit

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //Is there a next page
    "hasPrev": false, //Is there a previous page
    "items": [ //Datasheets
      {
        "collectionInternal": 0, //Billing Cycle (second)
        "createdTime": 0, //Time
        "fundingRate": 0, //Latest funding rate
        "id": 0, //id
        "symbol": "" //Trading pair
      }
    ]
  },
  "returnCode": 0
}

Get Trading Pair Risk Fund Balance Edit

/future/market/v1/public/contract/risk-balance

Parameters
Parameter Type mandatory Default Description Ranges
symbol string false N/A Trading pair
direction string false NEXT Direction(PREV:Previous page;NEXT:Next page) PREV;NEXT
id integer false N/A id
limit integer false 10 Limit

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //Is there a next page
    "hasPrev": false, //Is there a previous page
    "items": [ //Datasheets
      {
        "amount": 0, //Balance
        "coin": "", //Currency
        "createdTime": 0, //Time
        "id": 0 //id
      }
    ]
  },
  "returnCode": 0
}

Get the open position of a trading pair Edit

/future/market/v1/public/contract/open-interest

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair

Note:This method does not require a signature.

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "symbol": "", //Trading pair
    "openInterest": "", //open position
    "openInterestUsd": 0, //open value
    "time": "", //time
  },
  "returnCode": 0
}

Create Orders Edit

/future/trade/v1/order/create

Parameters
Parameter Type mandatory Default Description Ranges
clientOrderId string false N/A Client order ID
symbol string false N/A Trading pair
orderSide string true N/A Order side:BUY;SELL BUY;SELL
orderType string true N/A Order type:LIMIT;MARKET LIMIT;MARKET
origQty number true N/A Quantity (Cont)
price number false N/A Price
reduceOnly boolean false false Reduce only
timeInForce string false GTC Valid way:GTC;IOC;FOK;GTX GTC;IOC;FOK;GTX
triggerProfitPrice number false N/A Stop profit price
triggerStopPrice number false N/A Stop loss price
positionSide string true N/A Position side:LONG;SHORT LONG;SHORT
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

See Order History Edit

/future/trade/v1/order/list-history

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pairs (queries all trading pairs if not passed)
direction string false NEXT Direction(PREV:Previous page;NEXT:Next page) PREV;NEXT
id integer false N/A id
limit integer false 10 Limit
startTime integer false N/A Start time
endTime integer false N/A End time
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //Is there a next page
    "hasPrev": false, //Is there a previous page
    "items": [ //Datasheets
      {
        "clientOrderId": "", //Client order ID
        "avgPrice": 0, //Average price
        "closePosition": false, //Whether to close all when order condition is triggered
        "closeProfit": 0, //Offset profit and loss
        "createdTime": 0, //Creat time
        "executedQty": 0, //Volume (Cont)
        "forceClose": false, //Is it a liquidation order
        "marginFrozen": 0, //Occupied margin
        "orderId": 0, //Order ID
        "orderSide": "", //Order side
        "orderType": "", //Order type
        "origQty": 0, //Quantity (Cont)
        "positionSide": "", //Position side
        "price": 0, //Order price
        "sourceId": 0, //Triggering conditions ID
        "state": "", //Order state:NEW:New order (unfilled);PARTIALLY_FILLED:Partial deal;PARTIALLY_CANCELED:Partial revocation;FILLED:Filled;CANCELED:Cancled;REJECTED:Order failed;EXPIRED:Expired
        "symbol": "", //Trading pair
        "timeInForce": "", //Valid type
        "triggerProfitPrice": 0, //TP trigger price
        "triggerStopPrice": 0 //SL trigger price
      }
    ]
  },
  "returnCode": 0
}

See Transaction Details Edit

/future/trade/v1/order/trade-list

Parameters
Parameter Type mandatory Default Description Ranges
orderId integer false N/A Order ID
symbol string false N/A Trading pair
page integer false 1 Page
size integer false 10 Quantity of a single page
startTime integer false N/A 起始时间
endTime integer false N/A 结束时间
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "fee": 0, //Fee
        "feeCoin": "", //Currency of fee
        "orderId": 0, //Order ID
        "execId": 0, //Trade ID
        "price": 0, //Price
        "quantity": 0, //Volume
        "symbol": "", //Trading pair
        "timestamp": 0 //Time
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

Bulk Orders Edit

/future/trade/v1/order/create-batch

Parameters
Parameter Type mandatory Default Description Ranges
list string true N/A List collection of order data
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

See Orders by ID Edit

/future/trade/v1/order/detail

Parameters
Parameter Type mandatory Default Description Ranges
orderId integer true N/A Order ID
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "avgPrice": 0, //Average price
    "closePosition": false, //Whether to close all when order condition is triggered
    "closeProfit": 0, //Offset profit and loss
    "createdTime": 0, //Create time
    "executedQty": 0, //Volume (Cont)
    "forceClose": false, //Is it a liquidation order
    "marginFrozen": 0, //Occupied margin
    "orderId": 0, //Order ID
    "orderSide": "", //Order side
    "orderType": "", //Order type
    "origQty": 0, //Quantity (Cont)
    "positionSide": "", //Position side
    "price": 0, //Order price
    "sourceId": 0, //Triggering conditions ID
    "state": "", //Order state:NEW:New order (unfilled);PARTIALLY_FILLED:Partial deal;PARTIALLY_CANCELED:Partial revocation;FILLED:Filled;CANCELED:Cancled;REJECTED:Order failed;EXPIRED:Expired
    "symbol": "", //Trading pair
    "timeInForce": "", //Valid type
    "triggerProfitPrice": 0, //TP trigger price
    "triggerStopPrice": 0 //SL trigger price
  },
  "returnCode": 0
}

See Orders Edit

/future/trade/v1/order/list

Parameters
Parameter Type mandatory Default Description Ranges
clientOrderId String false N/A Client order ID
page integer false 1 Page
size integer false 10 Quantity of a single page
startTime integer false N/A Start time
endTime integer false N/A End time
state string true NEW Order state: NEW:New order (unfilled);PARTIALLY_FILLED:Partial deal;PARTIALLY_CANCELED:Partial revocation;FILLED:Filled;CANCELED:Cancled;REJECTED:Order failed;EXPIRED:Expired;UNFINISHED:Unfinished;HISTORY:(History)
symbol string false N/A Trading pair
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "clientOrderId": "", //Client order ID
        "avgPrice": 0, //Average price
        "closePosition": false, //Whether to close all when order condition is triggered
        "closeProfit": 0, //Offset profit and loss
        "createdTime": 0, //Creat time
        "executedQty": 0, //Volume (Cont)
        "forceClose": false, //Is it a liquidation order
        "marginFrozen": 0, //Occupied margin
        "orderId": 0, //Order id
        "orderSide": "", //Order side
        "orderType": "", //Order type
        "origQty": 0, //Quantity (Cont)
        "positionSide": "", //Position side
        "price": 0, //Order price
        "sourceId": 0, //Triggering conditions ID
        "state": "", //Order state:NEW:New order (unfilled);PARTIALLY_FILLED:Partial deal;PARTIALLY_CANCELED:Partial revocation;FILLED:Filled;CANCELED:Cancled;REJECTED:Order failed;EXPIRED:Expired
        "symbol": "", //Trading pair
        "timeInForce": "", //Valid type
        "triggerProfitPrice": 0, //TP trigger price
        "triggerStopPrice": 0 //SL trigger price
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

Cancel Orders Edit

/future/trade/v1/order/cancel

Parameters
Parameter Type mandatory Default Description Ranges
orderId Integer true N/A Order ID
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": "", //Order ID
  "returnCode": 0
}

Cancel All Orders Edit

/future/trade/v1/order/cancel-all

Parameters
Parameter Type mandatory Default Description Ranges
symbol String true N/A Trading pair (cancel all trading pair orders if don't pass parameters)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

Create Trigger Orders Edit

/future/trade/v1/entrust/create-profit

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
orderSide string true N/A Order side:BUY;SELL BUY;SELL
entrustType string true N/A Order type:TAKE_PROFIT(Take Profit Limit Order);STOP(Stop Limit Order);TAKE_PROFIT_MARKET(Take Profit Market Order);STOP_MARKET(Stop Loss Market Order);TRAILING_STOP_MARKET(trailing stop order) TAKE_PROFIT;STOP;TAKE_PROFIT_MARKET;STOP_MARKET;TRAILING_STOP_MARKET
origQty number true N/A Quantity (Cont)
price number false N/A Price
stopPrice number false N/A Trigger price
timeInForce string true N/A Valid way:GTC;IOC;FOK;GTX GTC;IOC;FOK;GTX
triggerPriceType string true N/A Trigger price type:INDEX_PRICE(Index price);MARK_PRICE(Mark price);LATEST_PRICE(latest price) INDEX_PRICE;MARK_PRICE;LATEST_PRICE
expireTime integer false N/A Expiration time
positionSide string true N/A Position side:LONG;SHORT LONG;SHORT
{
    "error": {
    "code": "",
    "msg": ""
    },
    "msgInfo": "",
    "result": {},
    "returnCode": 0
}
title: Response
language: json

Cancel Trigger Orders Edit

/future/trade/v1/entrust/cancel-plan

Parameters
Parameter Type mandatory Default Description Ranges
entrustId integer true N/A Trigger order ID
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

Cancel All Trigger Orders Edit

/future/trade/v1/entrust/cancel-all-plan

Parameters
Parameter Type mandatory Default Description Ranges
symbol string false N/A Trading pair (cancel all trading pair orders if don't pass parameters)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

See Trigger Orders Edit

/future/trade/v1/entrust/plan-list

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pairs (queries all trading pairs if not passed)
page integer false 1 Page
size integer false 10 Quantity of a single page
startTime integer false N/A Start time
endTime integer false N/A End time
state string true N/A Order status NOT_TRIGGERED:New order (not triggered);TRIGGERING:Triggering;TRIGGERED:Triggered;USER_REVOCATION:User revocation;PLATFORM_REVOCATION:Platform revocation (rejection);EXPIRED:expired;UNFINISHED:Unfinished;HISTORY:(History) NOT_TRIGGERED;TRIGGERING;TRIGGERED;USER_REVOCATION;PLATFORM_REVOCATION;EXPIRED;UNFINISHED;HISTORY
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "closePosition": false, //Whether triggered to close all
        "createdTime": 0, //Create time
        "entrustId": 0, //Order ID
        "entrustType": "", //Order type
        "marketOrderLevel": 0, //Best market price
        "orderSide": "", //Order side
        "ordinary": true,
        "origQty": 0, //Quantity (Cont)
        "positionSide": "", //osition side
        "price": 0, //Order price
        "state": "", //Order state:NOT_TRIGGERED:New order (not triggered);TRIGGERING:Triggering;TRIGGERED:Triggered;USER_REVOCATION:User revocation;PLATFORM_REVOCATION:Platform revocation (rejection);EXPIRED:expired;UNFINISHED:Unfinished;HISTORY:(History)
        "stopPrice": 0, //Trigger price
        "symbol": "", //Trading pair
        "timeInForce": "", //Valid way
        "triggerPriceType": "" //Trigger price type
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

See Trigger Orders base on EntrustId Edit

/future/trade/v1/entrust/plan-detail

Parameters
Parameter Type mandatory Default Description Ranges
entrustId integer true N/A Order ID
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "closePosition": false, //Whether triggered to close all
    "createdTime": 0, //Create time
    "entrustId": 0, //Order ID
    "entrustType": "", //Order type
    "marketOrderLevel": 0, //Best market price
    "orderSide": "", //Order side
    "ordinary": true,
    "origQty": 0, //Quantity (Cont)
    "positionSide": "", //Position side
    "price": 0, //Order price
    "state": "", //Order state:NOT_TRIGGERED:New order (not triggered);TRIGGERING:Triggering;TRIGGERED:Triggered;USER_REVOCATION:User revocation;PLATFORM_REVOCATION:Platform revocation (rejection);EXPIRED:expired;UNFINISHED:Unfinished;HISTORY:(History)
    "stopPrice": 0, //Trigger price
    "symbol": "", //Trading pair
    "timeInForce": "", //有效方式
    "triggerPriceType": "" //触发价格类型
  },
  "returnCode": 0
}

See Trigger Orders History Edit

/future/trade/v1/entrust/plan-list-history

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pairs (queries all trading pairs if not passed)
direction string false NEXT Direction(PREV:Previous page;NEXT:Next page) PREV;NEXT
id integer false N/A id
limit integer false 10 Limit
startTime integer false N/A Start time
endTime integer false N/A End time
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //Is there a next page
    "hasPrev": false, //Is there a previous page
    "items": [ //Datasheets
      {
        "closePosition": false, //Whether triggered to close all
        "createdTime": 0, //Create time
        "entrustId": 0, //Order ID
        "entrustType": "", //Order type
        "marketOrderLevel": 0, //Best market price
        "orderSide": "", //Order side
        "ordinary": true,
        "origQty": 0, //Quantity (Cont)
        "positionSide": "", //Position side
        "price": 0, //Order price
        "state": "", //Order state:NOT_TRIGGERED:New order (not triggered);TRIGGERING:Triggering;TRIGGERED:Triggered;USER_REVOCATION:User revocation;PLATFORM_REVOCATION:Platform revocation (rejection);EXPIRED:expired
        "stopPrice": 0, //Trigger price
        "symbol": "", //Trading pair
        "timeInForce": "", //Valid way
        "triggerPriceType": "" //Trigger price type
      }
    ]
  },
  "returnCode": 0
}

Create Stop Limit Edit

/future/trade/v1/entrust/create-profit

Parameters
Parameter Type mandatory Default Description Ranges
symbol string false N/A Trading pair
origQty integer true Quantity (Cont)
triggerProfitPrice integer true TP trigger price
triggerStopPrice integer true SL trigger price
expireTime integer true Expiration time
positionSide string true Position side:LONG;SHORT LONG;SHORT
{
    "error": {
    "code": "",
    "msg": ""
    },
    "msgInfo": "",
    "result": {},
    "returnCode": 0
}
title: Response
language: json

Cancel Stop Limit Edit

/future/trade/v1/entrust/cancel-profit-stop

Parameters
Parameter Type mandatory Default Description Ranges
profitId integer true N/A Stop limit ID
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

Cancel All Stop Limit Edit

/future/trade/v1/entrust/cancel-all-profit-stop

Parameters
Parameter Type mandatory Default Description Ranges
symbol string false N/A Trading pair (cancel all trading pair orders if don't pass parameters)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

See Stop Limit Edit

/future/trade/v1/entrust/profit-list

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pairs (queries all trading pairs if not passed)
page integer false 1 Page
size integer false 10 Quantity of a single page
startTime integer false N/A Start time
endTime integer false N/A End time
state string true N/A Order state:NOT_TRIGGERED:New order (not triggered);TRIGGERING:Triggering;TRIGGERED:Triggered;USER_REVOCATION:User revocation;PLATFORM_REVOCATION:Platform revocation (rejection);EXPIRED:expired;UNFINISHED:Unfinished;HISTORY:(History) NOT_TRIGGERED;TRIGGERING;TRIGGERED;USER_REVOCATION;PLATFORM_REVOCATION;EXPIRED;UNFINISHED;HISTORY
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "createdTime": 0, //Time
        "entryPrice": 0, //Open position average price
        "executedQty": 0, //Actual transaction
        "isolatedMargin": 0, //Isolated Margin
        "origQty": 0, //Quantity (Cont)
        "positionSide": "", //Position side
        "positionSize": 0, //Position quantity (Cont)
        "profitId": 0, //Order ID
        "state": "", //Order state:NOT_TRIGGERED:New order (not triggered);TRIGGERING:Triggering;TRIGGERED:Triggered;USER_REVOCATION:User revocation;PLATFORM_REVOCATION:Platform revocation (rejection);EXPIRED:expired;
        "symbol": "", //Trading pair
        "triggerProfitPrice": 0, //Stop profit price
        "triggerStopPrice": 0 //Stop loss price
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

See Stop Limit base on Profitld Edit

/future/trade/v1/entrust/profit-detail

Parameters
Parameter Type mandatory Default Description Ranges
profitId integer true N/A Stop limit ID
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "createdTime": 0, //Time
    "entryPrice": 0, //Open position average price
    "executedQty": 0, //Actual transaction
    "isolatedMargin": 0, //Isolated Margin
    "origQty": 0, //Quantity (Cont)
    "positionSide": "", //Position side
    "positionSize": 0, //Position quantity (Cont)
    "profitId": 0, //Order ID
    "state": "", //Order state:NOT_TRIGGERED:New order (not triggered);TRIGGERING:Triggering;TRIGGERED:Triggered;USER_REVOCATION:User revocation;PLATFORM_REVOCATION:Platform revocation (rejection);EXPIRED:expired;
    "symbol": "", //Trading pair
    "triggerProfitPrice": 0, //Stop profit price
    "triggerStopPrice": 0 //Stop loss price
  },
  "returnCode": 0
}

Alter Stop Limit Edit

/future/trade/v1/entrust/update-profit-stop

Parameters
Parameter Type mandatory Default Description Ranges
profitId integer true N/A Stop limit ID
triggerProfitPrice number false N/A TP trigger price
triggerStopPrice number false N/A SL trigger price
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

Get Account Related Information Edit

/future/user/v1/account/info

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "accountId": 0, //Account ID
    "allowOpenPosition": false, //Is it possible to open position
    "allowTrade": false, //Is it possible to trade
    "allowTransfer": false, //Is it possible to transfer
    "openTime": "", //Opening time
    "state": 0, //User status
    "userId": 0 //User ID
  },
  "returnCode": 0
}

Get ListenKey Edit

/future/user/v1/user/listen-key

Note:Valid time is 8 hours

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

Open Contract Edit

/future/user/v1/account/open

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

Get User's Single Currency Fund Information Edit

/future/user/v1/balance/detail

Parameters
Parameter Type mandatory Default Description Ranges
coin string true N/A Currency
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "availableBalance": 0, //Available balance
    "coin": "", //Currency
    "isolatedMargin": 0, //Frozen isolated margin
    "openOrderMarginFrozen": 0, //Frozen order
    "walletBalance": 0 //Balance
  },
  "returnCode": 0
}

Get User's Funds Information Edit

/future/user/v1/balance/list

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "availableBalance": 0, //Available balance
      "coin": "", //Currency
      "isolatedMargin": 0, //Frozen isolated margin
      "openOrderMarginFrozen": 0, //Frozen order
      "walletBalance": 0 //Balance
    }
  ],
  "returnCode": 0
}

Get User's Account Flow Information Edit

/future/user/v1/balance/bills

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pairs (queries all trading pairs if not passed)
direction string false NEXT Direction(PREV:Previous page;NEXT:Next page) PREV;NEXT
id integer false N/A id
limit integer false 10 Limit
startTime integer false N/A Start time
endTime integer false N/A End time
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //Is there a next page
    "hasPrev": false, //Is there a previous page
    "items": [ //Datasheets
      {
        "afterAmount": 0, //Balance after change
        "amount": 0, //Quantity
        "coin": "", //Currency
        "createdTime": 0, //Time
        "id": 0, //id
        "side": "", //ADD:transfer in;SUB:transfer out
        "symbol": "", //Trading pair
        "type": "" //EXCHANGE:transfer;CLOSE_POSITION:Offset profit and loss;TAKE_OVER:position takeover;QIANG_PING_MANAGER:Liquidation management fee (fee);FUND:Fund Fee;FEE:Fee(Open position, liquidation, Forced liquidation);ADL:Adl;TAKE_OVER:position takeover;MERGE:Position Merge
      }
    ]
  },
  "returnCode": 0
}

Get Fund Fee Information Edit

/future/user/v1/balance/funding-rate-list

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pairs (queries all trading pairs if not passed)
direction string false NEXT Direction(PREV:Previous page;NEXT:Next page) PREV;NEXT
id integer false N/A id
limit integer false 10 Limit
startTime integer false N/A Start time
endTime integer false N/A End time
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //Is there a next page
    "hasPrev": false, //Is there a previous page
    "items": [ //Datasheets
      {
        "cast": 0, //Fund fee
        "coin": "", //Currency
        "createdTime": 0, //Time
        "id": 0, //id
        "positionSide": "", //Direction
        "symbol": "" //Trading pair
      }
    ]
  },
  "returnCode": 0
}

Get Position Information Edit

/future/user/v1/position/list

Parameters
Parameter Type mandatory Default Description Ranges
symbol string false N/A Trading pair (see the position information of all trading pairs if don't pass parameters)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "autoMargin": false, //Whether to automatically call margin
      "availableCloseSize": 0, //Available quantity (Cont)
      "closeOrderSize": 0, //Pending order quantity (Cont)
      "entryPrice": 0, //Open position average price
      "isolatedMargin": 0, //Isolated Margin
      "leverage": 0, //Leverage
      "openOrderMarginFrozen": 0, //Occupied open position margin
      "positionSide": "", //Position side
      "positionSize": 0, //Position quantity (Cont)
      "positionType": "", //Position type
      "realizedProfit": 0, //Realized profit and loss
      "symbol": "" //Trading pair
    }
  ],
  "returnCode": 0
}

Adjust Leverage Edit

/future/user/v1/position/adjust-leverage

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
positionSide string true N/A Position side LONG;SHORT
leverage integer true N/A Leverage
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

Alter Margin Edit

/future/user/v1/position/margin

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
margin number false N/A Quantity
positionSide string false N/A Position side:LONG;SHORT
type string false N/A Adjust direction (add isolated margin, reduce isolated margin) ADD;SUB
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

Alter the automatical margin call Edit

/future/user/v1/position/auto-margin

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
positionSide string true N/A Position side LONG;SHORT
autoMargin boolean true N/A Whether to automatically call margin true;false
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

Close All Edit

/future/user/v1/position/close-all

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

Get ADL Information Edit

/future/user/v1/position/adl

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "longQuantile": 0, //long position adl
      "shortQuantile": 0, //Short position adl
      "symbol": "" //Trading pair
    }
  ],
  "returnCode": 0
}

Collect Trading Pair Edit

/future/user/v1/user/collection/add

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

Cancel Trading Pair Collection Edit

/future/user/v1/user/collection/cancel

Parameters
Parameter Type mandatory Default Description Ranges
symbol string true N/A Trading pair
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

List of Collected Trading Pairs Edit

/future/user/v1/user/collection/list

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [],
  "returnCode": 0
}

WEBSOCKET API Edit

Official:

wss://fstream.xt.com

WS market information subscription address: wss://fstream.xt.com/ws/market

WS user subscription address: wss://fstream.xt.com/ws/user

Prompt Message Edit

For each link, the client-side will periodically send a ping message, and the server-side will reply with a pong message. If the server-side does not receive the ping message from the front end for about one minute, the server will automatically disconnect with the client.

Format Description Edit

Official:

**Event prompt, fixed format: { “channel”:””, “data”:{} } **

Market Information Subscription Edit

Subscribe to the 24-hour market information ticker:

{
 "req":"sub_ticker",
 "symbol":"btc_usdt,eth_usdt"
}

ps: Symbol field is not required to pass parameters, if don’t pass parameters, subscribe to all trading pairs

Unsubscribe to the aggregated 24-hour market information:

{
 "req":"unsub_ticker"
}

Kline subscription:

{
 "req":"sub_kline",
 "symbol":"btc_usdt","type":"1m"
}

Type of Kline subscription:1m 5m 15m 30m 1h 4h 1d 1w

Kline unsubscription:

{
 "req":"unsub_kline"
}

Subscribe to the aggregated 24-hour market information aggTicker:

{
 "req":"sub_agg_ticker",
 "symbol":"btc_usdt,eth_usdt"
}

ps: Symbol field is not required to pass parameters, if don’t pass parameters, subscribe to all trading pairs

Unsubscribe to the aggregated 24-hour market information:

{
 "req":"unsub_agg_ticker"
}

Index price subscription:

{
 "req":"sub_index_price",
 "symbol":"btc_usdt,eth_usdt"
}

ps: Symbol field is not required to pass parameters, if don’t pass parameters, subscribe to all trading pairs

Index price unsubscription:

{
 "req":"unsub_index_price"
}

Mark price subscription:

{
 "req":"sub_mark_price",
 "symbol":"btc_usdt,eth_usdt"
}

ps: Symbol field is not required to pass parameters, if don’t pass parameters, subscribe to all trading pairs

Mark price unsubscription:

{
 "req":"unsub_mark_price"
}

Trading pairs subscription:

 {
  "req":"sub_symbol",
  "symbol":"btc_usdt"
 }

After subscribing to trading pairs, news of the index.price、mark.price、ticker、agg.ticker、deal、deep、deep.full、fund.rate of the trading pair will be pushed.

Trading pairs unsubscription:

{
 "req":"unsub_symbol"
}

Subscribe to Multi-Pair Depth:

{
 "req":"sub_depth",
 "symbol":"btc_usdt,eth_usdt"
}

ps:Multiple trading pair depth subscriptions, trading pairs are separated by commas, and a maximum of ten trading pair depths can be subscribed, and the deep and deep.full messages of the subscribed trading pairs will be pushed.

sub_mark_price、sub_index_price、sub_agg_ticker、sub_ticker Bulk subscription pushes every 3 seconds

Market Information Push Edit

Index price:

{
 "channel":"push.index.price",
 "data":{
   "s":"btc_usdt", //trading pair
   "p":"50000",    //price
   "t":123124124   //timestamp
  }
}

Mark price:

 {
  "channel":"push.mark.price",
  "data":{
     "s":"btc_usdt", //trading pair
     "p":"50000",    //price
     "t":123124124   //timestamp
  }
 }

Deal:

{
 "channel":"push.deal",
 "data":{
    "s":"btc_index", //trading pair
    "p":"50000",    //price
    "a":"0.1"   //Quantity
    "m": "BID"   //Deal side  BID:Buy ASK:Sell
    "t":123124124   //timestamp
 }
}

Change depth:

{
 "channel":"push.deep",
 "data":{
     "id":1 ,  //update Id
     "s":"btc_index", //trading pair
     "ba":1 // 方向 1 bid 2 ask
     "p":"50000",    //price
     "q":"0.1" , //Quantity
     "t":123124124   //timestamp
 }
}

Fund fee:

 {
  "channel":"push.fund.rate",
  "data":{
     "s":"btc_usdt", //Trading pair
     "r":"0.01",    // Fund fee
     "t":123124124   //timestamp
  }
}

24-hour market information:

{
 "channel":"push.ticker",
 "data":{
     "s":"btc_index", //trading pair
     "o":"49000",     // opening price
     "c":"50000",    //Closing price
     "h":"0.1",      //highest price
     "l":"0.1",       //lowest price
     "a":"0.1",      //volume
     "v":"0.1",       //Turnover
     "ch":"0.21",   //Quote change

     "i":"0.21" ,   //index price

     "m":"0.21",   //mark price

     "bp":"0.21",   //bid price

     "ap":"0.21" ,  //ask price
 }
}

Subscribe to the aggregated 24-hour market information agg.ticker:

{
 "channel":"push.agg.ticker",
 "data":{
     "s":"btc_index", //trading pair
     "o":"49000",     // opening price
     "c":"50000",    //Closing price
     "h":"0.1",      //highest price
     "l":"0.1",       //lowest price
     "a":"0.1",      //volume
     "v":"0.1",       //Turnover
     "ch":"0.21",   //Quote change
 }
}

Kline

{
 "channel":"push.kline",
 "data":{
     "s":"btc_index", //trading pair
     "o":"49000",     // opening price
     "c":"50000",    //Closing price
     "h":"0.1",      //highest price
     "l":"0.1",       //lowest price
     "a":"0.1",      //volume
     "v":"0.1",       //Turnover
     "ch":"0.21",   //Quote change
     "t":123124124   //timestamp
 }
}

Full first 50 block depth

{
 "channel":"push.deep.full",
  "data":{
      "s":"btc_index", //trading pair
      "a":[["50000","0.1"],["50001","0.2"]],    //ask sell order queue,[price, quantity]
      "b":[["49999","0.1"],["48888","0.2"]]   //bid buy queue
 }
}

Users subscription Edit

WS user subscription address:wss://fstream.xt.com/ws/user

Step 1: The user need to call the interface: /v1/user/listen-key to get the listenKey.

第二步:Step 2: When subscribing to user-related websocket events, users need to send: {“req”:”sub_user”, “listenKey”:”listenKey obtained in the previous step”}

If you receive “invalid_listen_key”, it means that the listenKey is expired or invalid, and you need to re-request to obtain the listenKey.

ps: listenKey is obtained through the interface.

User-related data will be pushed after subscription.

Pushes Edit

Push: Balance change

{"channel":"user.balance",
  "data":{
       "coin":"usdt",
       "underlyingType":1, //  1:Coin-M,2:USDT-M
       "walletBalance":"123", // Balance
       "openOrderMarginFrozen":"123", // Frozen order
       "isolatedMargin":"213"  // Isolated Margin
 }}

Change position

  {"channel":"user.position",
   "data":{
       "symbol":"btc_usdt",
       "positionType": "ISOLATED",  
       "positionSide": "LONG",
       "positionSize":"123",  // Position quantity

       "closeOrderSize": "100",  //  Pending order quantity (Cont)

       "availableCloseSize": "23",  //  Available quantity (Cont)

       "realizedProfit": "123"   //  Realized profit and loss

       "entryPrice":"213",   //  Open position average price
       "isolatedMargin":"213",  //  Isolated Margin

       "openOrderMarginFrozen": "123", //  Occupied open position margin
       "leverage":20  // Leverage
}}

Transactions:

{"channel":"user.trade",
  "data":{
      "orderId":"12312312",  // Order ID
      "price":"34244",  // Price
      "quantity":"123", // Quantity
      "marginUnfrozen":"123", // Quantity of unfrozen margin
      "timestamp":1731231231 // Timestamp
}}

用户订单:

{"channel":"user.order",
  "data":{

      "symbol":"btc_usdt",  // Trading pair

      "positionType": "123",    //   Quantity
      "avgPrice": "123", // Average price
      "executedQty":"34244", // Volume (Cont)
      "marginFrozen":"123", // Occupied margin
      "sourceType":"default", //  DEFAULT:normal order,ENTRUST:plan commission,PROFIR:Take Profit and Stop Loss

      "sourceId" : "1231231",// Triggering conditions ID
      "state": "", // state:NEW:New order (unfilled);PARTIALLY_FILLED:Partial deal;PARTIALLY_CANCELED:Partial revocation;FILLED:Filled;CANCELED:Cancled;REJECTED:Order failed;EXPIRED:Expired
      "timestamp": 1731231231 // Timestamp
}}

Message:

{"channel":"user.notify",
  "data":{   

     "symbol":"btc_usdt",
     "positionType": "ISOLATED",  
     "positionSide": "LONG",
     "positionSize":"123",  // Position quantity
     "notifyType": "WARN",  // Notification Type:WARN:Warning, about to be levelled,PARTIAL:Partially Liquidation,LIQUIDATION:Liquidation,ADL:ADL
}}

REST API Edit

正式:

U本位合约:https://fapi.xt.com

币本位合约:https://dapi.xt.com

接口的基本信息 Edit

鉴于延迟高和稳定性差等原因,不建议通过代理的方式访问API。

GET请求参数放入query Params中,POST请求参数放入request body中

请求头信息请设置为:Content-Type=application/x-www-form-urlencoded

除了接口本身所需的参数外,还需要在query Params 或 request body中传递 signature, 即签名参数,不需要传递签名参数的接口会额外说明。

限频规则 Edit

获取资产每秒3次,其他方法单个用户每秒10次,单个IP每分钟1000次,超出锁定账户10分钟。

签名说明 Edit

由于XT需要为第三方平台提供一些开放性的接口,所以需要接口的数据安全问题,比如数据是否被篡改,数据是否已过时,数据是否可以重复提交,接口在某个时间内访问频率等问题。其中数据是否被篡改是最重要的。

1、线下分配appkey和secretkey,针对不同的调用,提供不同的appkey和secretkey

2、加入timestamp(时间戳),其值应当是请求发送时刻的unix时间戳(毫秒),数据的有郊时间根据此值来计算。

3、加入signature(数据签名),所有数据的签名信息。

4、加入recvwindow(自定义请求有效时间),有效时间目前相对简单统一固定为某个值,比如:同api同appid下10分钟内数据都有郊,此处可以再进步优化到具体单个api有效时间都不相同。

服务器收到请求时会判断请求中的时间戳,最长60秒,默认为5秒,如果是5000毫秒之前发出的,则请求会被认为无效。这个时间窗口值可以通过发送可选参数recvWindow来自定义。 另外,如果服务器计算得出客户端时间戳在服务器时间的‘未来’一秒以上,也会拒绝请求。 关于交易时效性 互联网状况并不100%可靠,不可完全依赖,因此你的程序本地到xt服务器的时延会有抖动. 这是我们设置recvWindow的目的所在,如果你从事高频交易,对交易时效性有较高的要求,可以灵活设置recvWindow以达到你的要求。

不推荐使用5秒以上的recvWindow

5、加入algorithms (签名方法/算法),用户计算签名是基于哈希的协议,此处默认使用HmacSHA256。具体支持那些协议,请参见下面表格中所列出

字段名 是否必须 示例 说明
xt-validate-appkey true dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83
xt-validate-timestamp true 1641446237201
xt-validate-signature true 0a7d0b5e802eb5e52ac0cfcd6311b0faba6e2503a9a8d1e2364b38617877574d
xt-validate-recvwindow false 5000(毫秒)
xt-validate-algorithms false HmacSHA256 HmacMD5、HmacSHA1、HmacSHA224、HmacSHA256、HmacSHA384、HmacSHA512,默认为:HmacSHA256
xt-api-version false 1.0 保留,API版本号
xt-validate-signversion false 1.0 保留,签名版本号

签名生成 Edit

http://fapi.xt.com/future/api/v1/public/symbol/detail?symbol=btc_usdt的示例

以下是在linux bash环境下使用 echo openssl 和curl工具实现的一个调用接口下单的示例 appkey、secret仅供示范:

appKey: 3976eb88-76d0-4f6e-a6b2-a57980770085

secretKey: bc6630d0231fda5cd98794f52c4998659beda290

Header部分数据:

xt-validate-appkey: 3976eb88-76d0-4f6e-a6b2-a57980770085

xt-validate-timestamp: 2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9

xt-validate-algorithms: HmacSHA256

Authorization: bearer eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxNjYyMTA1ODcyNyIsInNjb3BlIjoiYXV0aCIsImlzcyI6Inh0LmNvbSIsImxhc3RBdXRoVGltZSI6MTY0NDgwNjEyNjE0OSwidXNlck5hbWUiOiIxNjYyMTA1ODcyNyIsImV4cCI6MTY0NDg5MjUyNiwidXNlcklkIjoxMzEwNzN9.vi2Cvc1BlYOKTdR6OrK1d89K9Je6DVLkJXSd2QEN7c6N11AmeIymhoLccqz6vflkC-c7eoFswutonGom375pxVX3gjnYomMi5-IbxpTL0Bys2tQ2xI7rhrbMIADBXL0G2CpCYLyZdapn3RxNScgQyJhI5ulupdXTx7tspeYDHfA

请求数据:

{ type: ‘LIMIT’, timeInForce: ‘GTC’, side: ‘BUY’, symbol: ‘btc_usdt’, price: ‘39000’, quantity: ‘2’ }

1、数据部分

path: 按照path中顺序将所有value进行拼接。形如/test/{var1}/{var2}/的restful路径将按填入的实际参数后路径拼接,示例:/sign/test/bb/aa

query: 按照key的字典序排序,将所有key=value进行拼接。示例:userName=dfdfdf&password=ggg

body: Json: 直接按JSON字符串不做转换或排序操作。

          x-www-form-urlencoded: 按照key的字典序排序,将所有key=value进行拼接,示例:userName=dfdfdf&password=ggg 

          form-data:此格式暂不支持。

如果存在多种数据形式,则按照path、query、body的顺序进行再拼接,得到所有数据的拼接值。

路径Path示例:

      /future/api/v1/public/symbol/detail

      上述拼接值记作为path

示例 1: 所有参数通过 query string 发送

        symbol=btc_usdt&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1

        上述值拼接记作query

示例 2: 所有参数通过 request body 发送

x-www-form-urlencoded的request body string :

        symbol=btc_usdt&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1

        上述值拼接记作body

json的request body string :

        {"symbol" : "btc_usdt","side" : "BUY","type":"LIMIT","timeInForce":"GTC","quantity":2,"price":39000}

        上述值拼接记作body

示例 3: 混合使用 query string 与 request body(分为表单与json两种格式)

queryString: symbol=btc_usdt&side=BUY&type=LIMIT&timeInForce=GTC 上述拼接值记作query

requestBody: {“quantity”:2,”price”:39000} 上述拼接值记作body

    整个数据最且拼接值由#符号分别与path、query、body进行拼接成#path、#query、#body,最终拼接值记作为Y=#path#query#body。

    注意:

        query无数据,body有数据:Y=#path#body

        query有数据,body无数据:Y=#path#query

        query有数据,body有数据:Y=#path#query#body

2、请求头部分 X=”xt-validate-appkey=3976eb88-76d0-4f6e-a6b2-a57980770085&xt-validate-timestamp=1641446237201”

3、生成签名

最终把需要进行加密的字符串,记作为sign=XY

最后将最终拼接值按照如下方法进行加密得到签名。

signature=org.apache.commons.codec.digest.HmacUtils.hmacSha256Hex(secretkey, sign);

将生成的签名singature放到请求头中,以xt-validate-signature为Key,以singature为值。

API Key申请步骤 Edit

接口可能需要用户的 API Key,如何创建API-KEY请参考这里

API 代码库 Edit

Java connector

一个轻量级的Java代码库,提供让用户直接调用API的方法。

https://github.com/futuresee/api-demo-java

返回格式 Edit

所有的接口返回都是JSON格式。

{
    "returnCode": 200,
    "result": {
        "serverTime": 1636612706739
    },
    "msgInfo": "Success."
    "error": null,
}

错误代码 Edit

状态码 错误信息
200 成功
401 需要登录
403 登录过期

获取交易对币种 Edit

/future/market/v1/public/symbol/coins

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [],
  "returnCode": 0
}

获取单个交易对的配置信息 Edit

/future/market/v1/public/symbol/detail

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "baseCoin": "", //标的资产
    "baseCoinDisplayPrecision": 0, //标的币种显示精度
    "baseCoinPrecision": 0, //标的币种精度
    "contractSize": 0, //合约乘数(面值)
    "contractType": "", //合约类型,永续,交割
    "depthPrecisionMerge": 0, //盘口精度合并
    "initLeverage": 0, //初始杠杆倍数
    "labels": [], //标签
    "liquidationFee": 0, //强平手续费
    "makerFee": 0, //maker手续费
    "maxEntrusts": 0, //最多open条件单
    "maxOpenOrders": 0, //最多open订单
    "minNotional": 0, //最小名义价值
    "minPrice": 0, //最小价格
    "minQty": 0, //最小数量
    "multiplierDown": 0, //限价卖单下限百分比
    "multiplierUp": 0, //限价买单价格上限百分比
    "onboardDate": 0, //上线时间
    "pricePrecision": 0, //价格精度
    "quantityPrecision": 0, //数量精度
    "quoteCoin": "", //报价币种
    "quoteCoinDisplayPrecision": 0, //报价币种显示精度
    "quoteCoinPrecision": 0, //报价币种精度
    "state": 0, //状态
    "supportEntrustType": "", //支持计划委托类型
    "supportOrderType": "", //支持订单类型
    "supportTimeInForce": "", //支持有效方式
    "symbol": "", //交易对
    "takerFee": 0, //taker手续费
    "tradeSwitch": false, //交易对开关
    "underlyingType": "" //标的类型,币本位,u本位
  },
  "returnCode": 0
}

获取所有交易对的配置信息 Edit

/future/market/v1/public/symbol/list

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "baseCoin": "", //标的资产
      "baseCoinDisplayPrecision": 0, //标的币种显示精度
      "baseCoinPrecision": 0, //标的币种精度
      "contractSize": 0, //合约乘数(面值)
      "contractType": "", //合约类型,永续,交割
      "depthPrecisionMerge": 0, //盘口精度合并
      "initLeverage": 0, //初始杠杆倍数
      "labels": [], //标签
      "liquidationFee": 0, //强平手续费
      "makerFee": 0, //maker手续费
      "maxEntrusts": 0, //最多open条件单
      "maxOpenOrders": 0, //最多open订单
      "minNotional": 0, //最小名义价值
      "minPrice": 0, //最小价格
      "minQty": 0, //最小数量
      "multiplierDown": 0, //限价卖单下限百分比
      "multiplierUp": 0, //限价买单价格上限百分比
      "onboardDate": 0, //上线时间
      "pricePrecision": 0, //价格精度
      "quantityPrecision": 0, //数量精度
      "quoteCoin": "", //报价资产
      "quoteCoinDisplayPrecision": 0, //报价币种显示精度
      "quoteCoinPrecision": 0, //报价币种精度
      "state": 0, //状态
      "supportEntrustType": "", //支持计划委托类型
      "supportOrderType": "", //支持订单类型
      "supportTimeInForce": "", //支持有效方式
      "symbol": "", //交易对
      "takerFee": 0, //taker手续费
      "tradeSwitch": false, //交易对开关
      "underlyingType": "" //标的类型,币本位,u本位
    }
  ],
  "returnCode": 0
}

查询单个交易对杠杆分层 Edit

/future/market/v1/public/leverage/bracket/detail

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "leverageBrackets": [
      {
        "bracket": 0, //档位
        "maintMarginRate": 0, //维持保证金率
        "maxLeverage": 0, //最大杠杆倍数
        "maxNominalValue": 0, //该层最大名义价值
        "maxStartMarginRate": 0, //最大起始保证金率
        "minLeverage": 0, //最小杠杆倍数
        "startMarginRate": 0, //起始保证金率
        "symbol": "" //交易对
      }
    ],
    "symbol": ""
  },
  "returnCode": 0
}

查询所有交易对杠杆分层 Edit

/future/market/v1/public/leverage/bracket/list

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "leverageBrackets": [
        {
          "bracket": 0, //档位
          "maintMarginRate": 0, //维持保证金率
          "maxLeverage": 0, //最大杠杆倍数
          "maxNominalValue": 0, //该层最大名义价值
          "maxStartMarginRate": 0, //最大起始保证金率
          "minLeverage": 0, //最小杠杆倍数
          "startMarginRate": 0, //起始保证金率
          "symbol": "" //交易对
        }
      ],
      "symbol": ""
    }
  ],
  "returnCode": 0
}

获取指定交易对的行情信息 Edit

/future/market/v1/public/q/ticker

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "a": "", //24小时成交量
    "c": "", //最新价
    "h": "", //24小时最高价
    "l": "", //24小时最低价
    "o": "", //24小时前第一笔成交价
    "r": "", //24小时涨跌幅
    "s": "", //交易对
    "t": 0, //时间
    "v": "" //24小时成交额
  },
  "returnCode": 0
}

获取全交易对的行情信息 Edit

/future/market/v1/public/q/tickers

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": "", //24小时成交量
      "c": "", //最新价
      "h": "", //24小时最高价
      "l": "", //24小时最低价
      "o": "", //24小时前第一笔成交价
      "r": "", //24小时涨跌幅
      "s": "", //交易对
      "t": 0, //时间
      "v": "" //24小时成交额
    }
  ],
  "returnCode": 0
}

获取交易对的最新成交信息 Edit

/future/market/v1/public/q/deal

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
num integer true N/A 数量

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": 0, //成交量
      "m": "", //买卖方向
      "p": 0, //成交价
      "s": "", //交易对
      "t": 0 //成交时间
    }
  ],
  "returnCode": 0
}

获取交易对的深度信息 Edit

/future/market/v1/public/q/depth

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
level integer true N/A 档位(min:1,max:50)

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "a": [], //卖单
    "b": [], //买单
    "s": "", //交易对
    "t": 0, //时间
    "u": 0 //updateId
  },
  "returnCode": 0
}

获取单个交易对的指数价格 Edit

/future/market/v1/public/q/symbol-index-price

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "p": 0, //价格
    "s": "", //交易对
    "t": 0 //时间
  },
  "returnCode": 0
}

获取所有交易对的指数价格 Edit

/future/market/v1/public/q/index-price

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "p": 0, //价格
      "s": "", //交易对
      "t": 0 //时间
    }
  ],
  "returnCode": 0
}

获取单个交易对的标记价格 Edit

/future/market/v1/public/q/symbol-mark-price

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "p": 0, //价格
    "s": "", //交易对
    "t": 0 //时间
  },
  "returnCode": 0
}

获取所有交易对的标记价格 Edit

/future/market/v1/public/q/mark-price

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "p": 0, //价格
      "s": "", //交易对
      "t": 0 //时间
    }
  ],
  "returnCode": 0
}

获取交易对的k线信息 Edit

/future/market/v1/public/q/kline

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
interval string true N/A 时间间隔 1m;5m;15m;30m;1h;4h;1d;1w
startTime integer false N/A 起始时间
endTime integer false N/A 结束时间
limit integer false N/A 限制条数

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": 0, //成交量
      "c": 0, //结束价
      "h": 0, //最高价
      "l": 0, //最低价
      "o": 0, //开始价
      "s": "", //交易对
      "t": 0, //时间
      "v": 0 //成交额
    }
  ],
  "returnCode": 0
}

获取指定交易对的聚合行情信息 Edit

/future/market/v1/public/q/agg-ticker

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "a": "", //24小时成交量
    "ap": "", //卖一价格
    "bp": "", //买一价格
    "c": "", //最新价
    "h": "", //24小时最高价
    "i": "", //指数价格
    "l": "", //24小时最低价
    "m": "", //标记价格
    "o": "", //24小时前第一笔成交价
    "r": "", //24小时涨跌幅
    "s": "", //交易对
    "t": 0, //时间
    "v": "" //24小时成交额
  },
  "returnCode": 0
}

获取全交易对的聚合行情信息 Edit

/future/market/v1/public/q/agg-tickers

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "a": "", //24小时成交量
      "ap": "", //卖一价格
      "bp": "", //买一价格
      "c": "", //最新价
      "h": "", //24小时最高价
      "i": "", //指数价格
      "l": "", //24小时最低价
      "m": "", //标记价格
      "o": "", //24小时前第一笔成交价
      "r": "", //24小时涨跌幅
      "s": "", //交易对
      "t": 0, //时间
      "v": "" //24小时成交额
    }
  ],
  "returnCode": 0
}

获取资金费率 Edit

/future/market/v1/public/q/funding-rate

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //是否有下一页
    "hasPrev": false, //是否有上一页
    "items": [ //数据列表
      {
        "collectionInternal": 0, //收取时间间隔(秒)
        "createdTime": 0, //时间
        "fundingRate": 0, //最新资金费率
        "id": 0, //id
        "symbol": "" //交易对
      }
    ]
  },
  "returnCode": 0
}

获取资金费率记录 Edit

/future/market/v1/public/q/funding-rate-record

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
direction string false NEXT 方向(PREV:上一页;NEXT:下一页) PREV;NEXT
id integer false N/A id
limit integer false 10 条数

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //是否有下一页
    "hasPrev": false, //是否有上一页
    "items": [ //数据列表
      {
        "collectionInternal": 0, //收取时间间隔(秒)
        "createdTime": 0, //时间
        "fundingRate": 0, //最新资金费率
        "id": 0, //id
        "symbol": "" //交易对
      }
    ]
  },
  "returnCode": 0
}

获取交易对风险基金余额 Edit

/future/market/v1/public/contract/risk-balance

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对
direction string false NEXT 方向(PREV:上一页;NEXT:下一页) PREV;NEXT
id integer false N/A id
limit integer false 10 条数

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //是否有下一页
    "hasPrev": false, //是否有上一页
    "items": [ //数据列表
      {
        "amount": 0, //余额
        "coin": "", //币种
        "createdTime": 0, //时间
        "id": 0 //id
      }
    ]
  },
  "returnCode": 0
}

获取交易对开仓量 Edit

/future/market/v1/public/contract/open-interest

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对

注:此方法不需要签名

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "symbol": "", //交易对
    "openInterest": "", //开仓量
    "openInterestUsd": 0, //开仓价值
    "time": "", //时间
  },
  "returnCode": 0
}

下单 Edit

/future/trade/v1/order/create

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
clientOrderId string false N/A 自定义订单id
symbol string false N/A 交易对
orderSide string true N/A 买卖方向:BUY;SELL BUY;SELL
orderType string true N/A 订单类型:LIMIT;MARKET LIMIT;MARKET
origQty number true N/A 数量(张)
price number false N/A 价格
reduceOnly boolean false false 只减仓
timeInForce string false GTC 有效方式:GTC;IOC;FOK;GTX GTC;IOC;FOK;GTX
triggerProfitPrice number false N/A 止盈价
triggerStopPrice number false N/A 止损价
positionSide string true N/A 仓位方向:LONG;SHORT LONG;SHORT
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

查询历史订单 Edit

/future/trade/v1/order/list-history

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对
direction string false NEXT 方向(PREV:上一页;NEXT:下一页) PREV;NEXT
id integer false N/A id
limit integer false 10 条数
startTime integer false N/A 起始时间
endTime integer false N/A 结束时间
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //是否有下一页
    "hasPrev": false, //是否有上一页
    "items": [ //数据列表
      {
        "clientOrderId": "", //自定义订单id
        "avgPrice": 0, //成交均价
        "closePosition": false, //是否条件全平仓
        "closeProfit": 0, //平仓盈亏
        "createdTime": 0, //创建时间
        "executedQty": 0, //已成交数量(张)
        "forceClose": false, //是否是强平订单
        "marginFrozen": 0, //占用保证金
        "orderId": 0, //订单id
        "orderSide": "", //买卖方向
        "orderType": "", //订单类型
        "origQty": 0, //数量(张)
        "positionSide": "", //持仓方向
        "price": 0, //委托价格
        "sourceId": 0, //条件触发id
        "state": "", //订单状态 NEW:新建订单(未成交);PARTIALLY_FILLED:部分成交;PARTIALLY_CANCELED:部分撤销;FILLED:全部成交;CANCELED:已撤销;REJECTED:下单失败;EXPIRED:已过期
        "symbol": "", //交易对
        "timeInForce": "", //有效类型
        "triggerProfitPrice": 0, //止盈触发价
        "triggerStopPrice": 0 //止损触发价
      }
    ]
  },
  "returnCode": 0
}

查询成交明细 Edit

/future/trade/v1/order/trade-list

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
orderId integer false N/A 订单id
symbol string false N/A 交易对
page integer false 1 页码
size integer false 10 单页数
startTime integer false N/A 起始时间
endTime integer false N/A 结束时间
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "fee": 0, //手续费
        "feeCoin": "", //手续费币种
        "orderId": 0, //订单id
        "execId": 0, //成交id
        "price": 0, //成交价格
        "quantity": 0, //成交数量
        "symbol": "", //交易对
        "timestamp": 0 //时间
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

批量下单 Edit

/future/trade/v1/order/create-batch

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
list string true N/A 下单数据的list集合
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

根据id查询订单 Edit

/future/trade/v1/order/detail

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
orderId integer true N/A 订单id
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "avgPrice": 0, //成交均价
    "closePosition": false, //是否条件全平仓
    "closeProfit": 0, //平仓盈亏
    "createdTime": 0, //创建时间
    "executedQty": 0, //已成交数量(张)
    "forceClose": false, //是否是强平订单
    "marginFrozen": 0, //占用保证金
    "orderId": 0, //订单id
    "orderSide": "", //买卖方向
    "orderType": "", //订单类型
    "origQty": 0, //数量(张)
    "positionSide": "", //持仓方向
    "price": 0, //委托价格
    "sourceId": 0, //条件触发id
    "state": "", //订单状态 NEW:新建订单(未成交);PARTIALLY_FILLED:部分成交;PARTIALLY_CANCELED:部分撤销;FILLED:全部成交;CANCELED:已撤销;REJECTED:下单失败;EXPIRED:已过期
    "symbol": "", //交易对
    "timeInForce": "", //有效类型
    "triggerProfitPrice": 0, //止盈触发价
    "triggerStopPrice": 0 //止损触发价
  },
  "returnCode": 0
}

查询订单 Edit

/future/trade/v1/order/list

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
clientOrderId String false N/A 自定义订单id
page integer false 1 页码
size integer false 10 单页数
startTime integer false N/A 开始时间
endTime integer false N/A 结束时间
state string true NEW 订单状态 NEW:新建订单(未成交);PARTIALLY_FILLED:部分成交;FILLED:全部成交;CANCELED:用户撤销;REJECTED:下单失败;EXPIRED:已过期;UNFINISHED:未完成;HISTORY:(历史)
symbol string false N/A 交易对
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "clientOrderId": "", //自定义订单id
        "avgPrice": 0, //成交均价
        "closePosition": false, //是否条件全平仓
        "closeProfit": 0, //平仓盈亏
        "createdTime": 0, //创建时间
        "executedQty": 0, //已成交数量(张)
        "forceClose": false, //是否是全平订单
        "marginFrozen": 0, //占用保证金
        "orderId": 0, //订单id
        "orderSide": "", //买卖方向
        "orderType": "", //订单类型
        "origQty": 0, //数量(张)
        "positionSide": "", //持仓方向
        "price": 0, //委托价格
        "sourceId": 0, //条件触发id
        "state": "", //订单状态 NEW:新建订单(未成交);PARTIALLY_FILLED:部分成交;PARTIALLY_CANCELED:部分撤销;FILLED:全部成交;CANCELED:已撤销;REJECTED:下单失败;EXPIRED:已过期
        "symbol": "", //交易对
        "timeInForce": "", //有效类型
        "triggerProfitPrice": 0, //止盈触发价
        "triggerStopPrice": 0 //止损触发价
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

撤销订单 Edit

/future/trade/v1/order/cancel

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
orderId Integer true N/A 订单id
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": "", //订单id
  "returnCode": 0
}

撤销所有订单 Edit

/future/trade/v1/order/cancel-all

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol String true N/A 交易对(不传时撤销所有交易对订单)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

创建计划委托 Edit

/future/trade/v1/entrust/create-plan

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对
orderSide string true N/A 买卖方向:BUY;SELL BUY;SELL
entrustType string true N/A 委托类型:TAKE_PROFIT(止盈限价单);STOP(止损限价单);TAKE_PROFIT_MARKET(止盈市价单);STOP_MARKET(止损市价单);TRAILING_STOP_MARKET(跟踪止损单) TAKE_PROFIT;STOP;TAKE_PROFIT_MARKET;STOP_MARKET;TRAILING_STOP_MARKET
origQty number true N/A 数量(张)
price number false N/A 价格
stopPrice number false N/A 触发价
timeInForce string true N/A 有效方式:GTC;IOC;FOK;GTX GTC;IOC;FOK;GTX
triggerPriceType string true N/A 触发价格类型:INDEX_PRICE(指数价格);MARK_PRICE(标记价格);LATEST_PRICE(最新价格) INDEX_PRICE;MARK_PRICE;LATEST_PRICE
expireTime integer false N/A 过期时间
positionSide string true N/A 仓位方向:LONG;SHORT LONG;SHORT
{
    "error": {
    "code": "",
    "msg": ""
    },
    "msgInfo": "",
    "result": {},
    "returnCode": 0
}
title: Response
language: json

撤销计划委托 Edit

/future/trade/v1/entrust/cancel-plan

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
entrustId integer true N/A 计划委托id
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

撤销所有计划委托 Edit

/future/trade/v1/entrust/cancel-all-plan

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对(不传时撤销所有交易对)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

查询计划委托 Edit

/future/trade/v1/entrust/plan-list

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对(不传时撤销所有交易对)
page integer false 1 页码
size integer false 10 单页数
startTime integer false N/A 开始时间
endTime integer false N/A 结束时间
state string true N/A 委托状态 NOT_TRIGGERED:新建委托(未触发);TRIGGERING:触发中;TRIGGERED:已触发;USER_REVOCATION:用户撤销;PLATFORM_REVOCATION:平台撤销(拒绝);EXPIRED:已过期;UNFINISHED:未完成;HISTORY:(历史) NOT_TRIGGERED;TRIGGERING;TRIGGERED;USER_REVOCATION;PLATFORM_REVOCATION;EXPIRED;UNFINISHED;HISTORY
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "closePosition": false, //是否触发全平
        "createdTime": 0, //创建时间
        "entrustId": 0, //委托id
        "entrustType": "", //委托类型
        "marketOrderLevel": 0, //市价最优档
        "orderSide": "", //买卖方向
        "ordinary": true,
        "origQty": 0, //数量(张)
        "positionSide": "", //持仓方向
        "price": 0, //订单价格
        "state": "", //订单状态 NOT_TRIGGERED:新建委托(未触发);TRIGGERING:触发中;TRIGGERED:已触发;USER_REVOCATION:用户撤销;PLATFORM_REVOCATION:平台撤销(拒绝);EXPIRED:已过期
        "stopPrice": 0, //触发价格
        "symbol": "", //交易对
        "timeInForce": "", //有效方式
        "triggerPriceType": "" //触发价格类型
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

根据entrustId查询计划委托 Edit

/future/trade/v1/entrust/plan-detail

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
entrustId integer true N/A 委托id
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "closePosition": false, //是否触发全平
    "createdTime": 0, //创建时间
    "entrustId": 0, //委托id
    "entrustType": "", //委托类型
    "marketOrderLevel": 0, //市价最优档
    "orderSide": "", //买卖方向
    "ordinary": true,
    "origQty": 0, //数量(张)
    "positionSide": "", //持仓方向
    "price": 0, //订单价格
    "state": "", //订单状态 NOT_TRIGGERED:新建委托(未触发);TRIGGERING:触发中;TRIGGERED:已触发;USER_REVOCATION:用户撤销;PLATFORM_REVOCATION:平台撤销(拒绝);EXPIRED:已过期
    "stopPrice": 0, //触发价格
    "symbol": "", //交易对
    "timeInForce": "", //有效方式
    "triggerPriceType": "" //触发价格类型
  },
  "returnCode": 0
}

查询历史计划委托 Edit

/future/trade/v1/entrust/plan-list-history

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对(不传时撤销所有交易对)
direction string false NEXT 方向(PREV:上一页;NEXT:下一页) PREV;NEXT
id integer false N/A id
limit integer false 10 条数
startTime integer false N/A 起始时间
endTime integer false N/A 结束时间
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //是否有下一页
    "hasPrev": false, //是否有上一页
    "items": [ //数据列表
      {
        "closePosition": false, //是否触发全平
        "createdTime": 0, //创建时间
        "entrustId": 0, //委托id
        "entrustType": "", //委托类型
        "marketOrderLevel": 0, //市价最优档
        "orderSide": "", //买卖方向
        "ordinary": true,
        "origQty": 0, //数量(张)
        "positionSide": "", //持仓方向
        "price": 0, //订单价格
        "state": "", //订单状态 NOT_TRIGGERED:新建委托(未触发);TRIGGERING:触发中;TRIGGERED:已触发;USER_REVOCATION:用户撤销;PLATFORM_REVOCATION:平台撤销(拒绝);EXPIRED:已过期
        "stopPrice": 0, //触发价格
        "symbol": "", //交易对
        "timeInForce": "", //有效方式
        "triggerPriceType": "" //触发价格类型
      }
    ]
  },
  "returnCode": 0
}

创建止盈止损 Edit

/future/trade/v1/entrust/create-profit

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
origQty integer true 数量(张)
triggerProfitPrice integer true 止盈触发价
triggerStopPrice integer true 止损触发价
expireTime integer true 过期时间
positionSide string true 仓位方向:LONG;SHORT LONG;SHORT
{
    "error": {
    "code": "",
    "msg": ""
    },
    "msgInfo": "",
    "result": {},
    "returnCode": 0
}
title: Response
language: json

撤销止盈止损 Edit

/future/trade/v1/entrust/cancel-profit-stop

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
profitId integer true N/A 止盈止损id
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

撤销所有止盈止损 Edit

/future/trade/v1/entrust/cancel-all-profit-stop

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对(不传时撤销所有交易对)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

查询止盈止损 Edit

/future/trade/v1/entrust/profit-list

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对(不传时撤销所有交易对)
page integer false 1 页码
size integer false 10 单页数
startTime integer false N/A 开始时间
endTime integer false N/A 结束时间
state string true N/A 委托状态 NOT_TRIGGERED:新建委托(未触发);TRIGGERING:触发中;TRIGGERED:已触发;USER_REVOCATION:用户撤销;PLATFORM_REVOCATION:平台撤销(拒绝);EXPIRED:已过期;UNFINISHED:未完成;HISTORY:(历史) NOT_TRIGGERED;TRIGGERING;TRIGGERED;USER_REVOCATION;PLATFORM_REVOCATION;EXPIRED;UNFINISHED;HISTORY
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "items": [
      {
        "createdTime": 0, //时间
        "entryPrice": 0, //开仓均价
        "executedQty": 0, //实际成交
        "isolatedMargin": 0, //逐仓保证金
        "origQty": 0, //数量(张)
        "positionSide": "", //仓位方向
        "positionSize": 0, //持仓数量(张)
        "profitId": 0, //委托id
        "state": "", //订单状态 NOT_TRIGGERED:新建委托(未触发);TRIGGERING:触发中;TRIGGERED:已触发;USER_REVOCATION:用户撤销;PLATFORM_REVOCATION:平台撤销(拒绝);EXPIRED:已过期
        "symbol": "", //交易对
        "triggerProfitPrice": 0, //止盈价格
        "triggerStopPrice": 0 //止损价格
      }
    ],
    "page": 0,
    "ps": 0,
    "total": 0
  },
  "returnCode": 0
}

根据profitId查询止盈止损 Edit

/future/trade/v1/entrust/profit-detail

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
profitId integer true N/A 止盈止损id
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "createdTime": 0, //时间
    "entryPrice": 0, //开仓均价
    "executedQty": 0, //实际成交
    "isolatedMargin": 0, //逐仓保证金
    "origQty": 0, //数量(张)
    "positionSide": "", //仓位方向
    "positionSize": 0, //持仓数量(张)
    "profitId": 0, //委托id
    "state": "", //订单状态 NOT_TRIGGERED:新建委托(未触发);TRIGGERING:触发中;TRIGGERED:已触发;USER_REVOCATION:用户撤销;PLATFORM_REVOCATION:平台撤销(拒绝);EXPIRED:已过期
    "symbol": "", //交易对
    "triggerProfitPrice": 0, //止盈价格
    "triggerStopPrice": 0 //止损价格
  },
  "returnCode": 0
}

修改止盈止损 Edit

/future/trade/v1/entrust/update-profit-stop

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
profitId integer true N/A 止盈止损id
triggerProfitPrice number false N/A 止盈触发价
triggerStopPrice number false N/A 止损触发价
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

获取账户相关信息 Edit

/future/user/v1/account/info

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "accountId": 0, //帐户id
    "allowOpenPosition": false, //是否可开仓
    "allowTrade": false, //是否可以交易
    "allowTransfer": false, //是否可以划转
    "openTime": "", //开通时间
    "state": 0, //用户状态
    "userId": 0 //用户id
  },
  "returnCode": 0
}

获取listenKey Edit

/future/user/v1/user/listen-key

注:有效时间为8小时

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

开通合约 Edit

/future/user/v1/account/open

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

获取用户单币种资金 Edit

/future/user/v1/balance/detail

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
coin string true N/A 币种
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "availableBalance": 0, //可用余额
    "coin": "", //币种
    "isolatedMargin": 0, //逐仓保证金冻结
    "openOrderMarginFrozen": 0, //订单冻结
    "walletBalance": 0 //钱包余额
  },
  "returnCode": 0
}

获取用户资金 Edit

/future/user/v1/balance/list

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "availableBalance": 0, //可用余额
      "coin": "", //币种
      "isolatedMargin": 0, //逐仓保证金冻结
      "openOrderMarginFrozen": 0, //订单冻结
      "walletBalance": 0 //钱包余额
    }
  ],
  "returnCode": 0
}

获取用户账务流水 Edit

/future/user/v1/balance/bills

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
direction string false NEXT 方向(PREV:上一页;NEXT:下一页) PREV;NEXT
id integer false N/A id
limit integer false 10 条数
startTime integer false N/A 起始时间
endTime integer false N/A 结束时间
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //是否有下一页
    "hasPrev": false, //是否有上一页
    "items": [ //数据列表
      {
        "afterAmount": 0, //变动后余额
        "amount": 0, //数量
        "coin": "", //币种
        "createdTime": 0, //时间
        "id": 0, //id
        "side": "", //ADD:划入;SUB:转出
        "symbol": "", //交易对
        "type": "" //EXCHANGE:划转;CLOSE_POSITION:平仓盈亏;TAKE_OVER:仓位接管;QIANG_PING_MANAGER:强平管理费(手续费);FUND:资金费用;FEE:手续费 (开仓、平仓、强平);ADL:自动减仓;TAKE_OVER:仓位接管MERGE:仓位合并
      }
    ]
  },
  "returnCode": 0
}

获取资金费用 Edit

/future/user/v1/balance/funding-rate-list

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对
direction string false NEXT 方向(PREV:上一页;NEXT:下一页) PREV;NEXT
id integer false N/A id
limit integer false 10 条数
startTime integer false N/A 起始时间
endTime integer false N/A 结束时间
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {
    "hasNext": false, //是否有下一页
    "hasPrev": false, //是否有上一页
    "items": [ //数据列表
      {
        "cast": 0, //资金费用
        "coin": "", //币种
        "createdTime": 0, //时间
        "id": 0, //id
        "positionSide": "", //方向
        "symbol": "" //交易对
      }
    ]
  },
  "returnCode": 0
}

获取持仓信息 Edit

/future/user/v1/position/list

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string false N/A 交易对(不传时查询所有交易对的持仓信息)
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "autoMargin": false, //是否自动追加保证金
      "availableCloseSize": 0, //可平仓数量(张)
      "closeOrderSize": 0, //平仓挂单数量(张)
      "entryPrice": 0, //开仓均价
      "isolatedMargin": 0, //逐仓保证金
      "leverage": 0, //杠杆倍数
      "openOrderMarginFrozen": 0, //开仓订单保证金占用
      "positionSide": "", //持仓方向
      "positionSize": 0, //持仓数量(张)
      "positionType": "", //仓位类型
      "realizedProfit": 0, //已实现盈亏
      "symbol": "" //交易对
    }
  ],
  "returnCode": 0
}

调整杠杆倍数 Edit

/future/user/v1/position/adjust-leverage

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
positionSide string true N/A 仓位方向 LONG;SHORT
leverage integer true N/A 杠杆倍数
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

修改保证金 Edit

/future/user/v1/position/margin

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
margin number false N/A 数量
positionSide string false N/A 持仓方向:LONG;SHORT
type string false N/A 调整方向(ADD:增加逐仓保证金;SUB:减少逐仓保证金) ADD;SUB
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

修改自动追加保证金 Edit

/future/user/v1/position/auto-margin

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
positionSide string true N/A 仓位方向 LONG;SHORT
autoMargin boolean true N/A 是否开启自动追加保证金 true;false
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": {},
  "returnCode": 0
}

一键平仓 Edit

/future/user/v1/position/close-all

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

获取ADL信息 Edit

/future/user/v1/position/adl

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [
    {
      "longQuantile": 0, //多头adl
      "shortQuantile": 0, //空头adl
      "symbol": "" //交易对
    }
  ],
  "returnCode": 0
}

收藏交易对 Edit

/future/user/v1/user/collection/add

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

取消收藏交易对 Edit

/future/user/v1/user/collection/cancel

Parameters
参数 数据类型 是否必须 默认值 描述 取值范围
symbol string true N/A 交易对
{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": true,
  "returnCode": 0
}

收藏交易对列表 Edit

/future/user/v1/user/collection/list

{
  "error": {
    "code": "",
    "msg": ""
  },
  "msgInfo": "",
  "result": [],
  "returnCode": 0
}

WEBSOCKET API Edit

正式:

wss://fstream.xt.com

行情ws订阅地址: wss://fstream.xt.com/ws/market

用户ws订阅地址: wss://fstream.xt.com/ws/user

连接心跳 Edit

每个链接,客户端需要定期发送ping消息,服务端会回复pong的消息,服务端再1分钟左右没有收到前端的ping消息,会主动断开链接

格式说明 Edit

正式:

**事件推送,固定格式: { “channel”:””, “data”:{} } **

行情订阅 Edit

订阅24小时行情 ticker:

{
 "req":"sub_ticker",
 "symbol":"btc_usdt,eth_usdt"
}

ps: symbol 非必传,不传则订阅所有交易对

取消订阅24小时行情:

{
 "req":"unsub_ticker"
}

K线订阅:

{
 "req":"sub_kline",
 "symbol":"btc_usdt","type":"1m"
}

ps:K线订阅type类型: 1m 5m 15m 30m 1h 4h 1d 1w

K线取消订阅:

{
 "req":"unsub_kline"
}

订阅24小时聚合行情 aggTicker:

{
 "req":"sub_agg_ticker",
 "symbol":"btc_usdt,eth_usdt"
}

ps: symbol 非必传,不传则订阅所有交易对

取消24小时聚合行情订阅:

{
 "req":"unsub_agg_ticker"
}

指数价格订阅:

{
 "req":"sub_index_price",
 "symbol":"btc_usdt,eth_usdt"
}

ps: symbol 非必传,不传则订阅所有交易对

取消指数价格订阅:

{
 "req":"unsub_index_price"
}

标记价格订阅:

{
 "req":"sub_mark_price",
 "symbol":"btc_usdt,eth_usdt"
}

ps: symbol 非必传,不传则订阅所有交易对

取消标记价格订阅:

{
 "req":"unsub_mark_price"
}

订阅交易对:

 {
  "req":"sub_symbol",
  "symbol":"btc_usdt"
 }

ps:订阅交易对之后,会推送这个交易对的index.price、mark.price、ticker、agg.ticker、deal、deep、deep.full、fund.rate的消息

取消交易对订阅:

{
 "req":"unsub_symbol"
}

订阅多交易对深度:

{
 "req":"sub_depth",
 "symbol":"btc_usdt,eth_usdt"
}

ps:多交易对深度订阅,交易对以逗号隔开,最多订阅十个交易对深度,会推送所订阅的交易对的deep、deep.full的消息

sub_mark_price、sub_index_price、sub_agg_ticker、sub_ticker批量订阅每3秒推送一次

行情推送 Edit

指数价格inde.price:

{
 "channel":"push.index.price",
 "data":{
   "s":"btc_usdt", //交易对
   "p":"50000",    //价格
   "t":123124124   //时间戳
  }
}

标记价格:

 {
  "channel":"push.mark.price",
  "data":{
     "s":"btc_usdt", //交易对
     "p":"50000",    //价格
     "t":123124124   //时间戳
  }
 }

成交:

{
 "channel":"push.deal",
 "data":{
    "s":"btc_index", //交易对
    "p":"50000",    //价格
    "a":"0.1"   //数量
    "m": "BID"   //成交方向  BID 买 ASK卖
    "t":123124124   //时间戳
 }
}

深度变更:

{
 "channel":"push.deep",
 "data":{
     "id":1 ,  //update Id
     "s":"btc_index", //交易对
     "ba":1 // 方向 1 bid 2 ask
     "p":"50000",    //价格
     "q":"0.1" , //数量
     "t":123124124   //时间戳
 }
}

资金费率:

 {
  "channel":"push.fund.rate",
  "data":{
     "s":"btc_usdt", //交易对
     "r":"0.01",    // 资金费率
     "t":123124124   //时间戳
  }
}

24小时行情ticker:

{
 "channel":"push.ticker",
 "data":{
     "s":"btc_index", //交易对
     "o":"49000",     // open 开盘价
     "c":"50000",    //cloes 收盘价
     "h":"0.1",      //high 最高价
     "l":"0.1",       //low 最低价
     "a":"0.1",      //amount 成交量
     "v":"0.1",       //volume 成交额
     "ch":"0.21",   //change 涨跌幅

     "i":"0.21" ,   //index 指数价格

     "m":"0.21",   //mark 标记价格

     "bp":"0.21",   //bid price 买一价格

     "ap":"0.21" ,  //ask price 卖一价格
 }
}

24小时聚合行情agg.ticker:

{
 "channel":"push.agg.ticker",
 "data":{
     "s":"btc_index", //交易对
     "o":"49000", // open 开盘价
     "c":"50000",    //cloes 收盘价
     "h":"0.1", //high 最高价
     "l":"0.1", //low 最低价
     "a":"0.1", //amount 成交量
     "v":"0.1", //volume 成交额
     "ch":"0.21"   //change 涨跌幅
 }
}

K线

{
 "channel":"push.kline",
 "data":{
     "s":"btc_index", //交易对
     "o":"49000", // open 开盘价
     "c":"50000",    //cloes 收盘价
     "h":"0.1", //high 最高价
     "l":"0.1", //low 最低价
     "a":"0.1", //amount 成交量
     "v":"0.1", //volume 成交额
     "ch":"0.21",   //change 涨跌幅
     "t":123124124   //时间戳
 }
}

全量前50挡深度

{
 "channel":"push.deep.full",
  "data":{
      "s":"btc_index", //交易对
      "a":[["50000","0.1"],["50001","0.2"]],    //ask 卖单队列, [价格,数量]
      "b":[["49999","0.1"],["48888","0.2"]]   //bid 买单队列
 }
}

用户订阅 Edit

用户ws订阅地址: https://xxx.xxx.xxx/ws/user

第一步:用户要先调用接口:/v1/user/listen-key 获取listenKey

第二步:订阅用户相关的websocket事件时需要发送:{“req”:”sub_user”, “listenKey”:”上一步获取的listenKey”}

如果收到”invalid_listen_key”表示listenKey过期或者无效,需要重新请求获取listenKey

ps:listenKey通过接口获取

订阅之后会推送用户相关数据

用户推送 Edit

用户推送事件: 余额变更

{"channel":"user.balance",
  "data":{
       "coin":"usdt",  

        "underlyingType":1, //  1:币本位,2:U本位
        "walletBalance":"123", // 钱包余额
        "openOrderMarginFrozen":"123", // 订单冻结
        "isolatedMargin":"213"  // 逐仓保证金
 }}

仓位变更

  {"channel":"user.position",
   "data":{
       "symbol":"btc_usdt",
       "positionType": "ISOLATED",  
       "positionSide": "LONG",
       "positionSize":"123",  // 持仓数量

       "closeOrderSize": "100",  //  平仓挂单数量

       "availableCloseSize": "23",  //  可平仓张数

       "realizedProfit": "123"   //  已实现盈亏

       "entryPrice":"213",   //  开仓均价
       "isolatedMargin":"213",  //  逐仓保证金

       "openOrderMarginFrozen": "123", //  开仓订单占用保证金
       "leverage":20  // 杠杆倍数
}}

用户成交:

{"channel":"user.trade",
  "data":{
      "orderId":"12312312",  // 订单id
      "price":"34244",  // 价格
      "quantity":"123", // 数量
      "marginUnfrozen":"123", // 保证金解冻数量
      "timestamp":1731231231 // 时间戳
}}

用户订单:

{"channel":"user.order",
  "data":{

      "symbol":"btc_usdt",  // 交易对

      "positionType": "123",    //   数量
      "avgPrice": "123", // 成交均价
      "executedQty":"34244", // 已成交数量
      "marginFrozen":"123", // 占用保证金
      "sourceType":"default", //  DEFAULT:普通订单, ENTRUST:计划委托,PROFIR:止盈止损

      "sourceId" : "1231231",// 条件订单出发ID
      "state": "", // 订单状态 NEW:新建订单;未成交; PARTIALLY_FILLED:部分成交;PARTIALLY_CANCELED:部分撤销;FILLED:全部成交;CANCELED:已撤销;REJECTED:下单失败;EXPIRED:已过期
      "timestamp": 1731231231 // 时间戳
}}

用户消息:

{"channel":"user.notify",
  "data":{   

     "symbol":"btc_usdt",
     "positionType": "ISOLATED",  
     "positionSide": "LONG",
     "positionSize":"123",  // 持仓数量

     "notifyType": "WARN",  // 通知类型:  WARN:告警,即将被强平,PARTIAL:部分强平,LIQUIDATION:全部强平,ADL:自动减仓

}}