NAV
简体中文

API Overview

0. Base endpoints

Base endpoints: https://openapi.bitwellex.com, https://openapi.bitwellex.co

Users can compare the latency between openapi.bitwellex.com and openapi.bitwellex.co, and choose the one with lower latency.

Among these endpoints, openapi.bitwellex.co has certain link latency optimization for users using aws cloud service.

1. Access Restriction

Details of access restrictions are in this section.

When the access exceeds the rate limit, the status 429 is returned: Requests are too frequent.

1.1 Rest API

If the incoming APIKey is valid, limit the speed with the user ID; if not, limit the speed with the public IP.

Speed limit rules: There are separate instructions on each interface. If not, the general interface speed limit is 5 times per second.

1.2 WebSocket

WebSocket limits each endpoint to 50 requests per second.

2. Validation

This section focuses on the following four areas of detail for validation:

● Generate APIKey ● Initiating Requests ● Signatures ● Timestamp

2.1 Generating APIKey

Before users can sign any request, they must create an APIKey through the BitWell website:

APIKey and SecretKey will be generated and provided by BitWell.

2.2 Request initiation

All REST API request headers must contain the following KEY:

FT-language language (optional), supports the following three, default “en-US”

All requests should contain application/json type content and be valid JSON.

2.3 Signatures

The request header of BW-ACCESS-SIGN is encrypted using HMAC SHA256 method on timestamp + Request Method + Request Path + Request body (where + denotes a string connection), and then exported using Base64 encoding.

Key Value Comments Example
timestamp Unix timestamp format, accurate to the millisecond Values are the same as the BW-ACCESS-TIMESTAMP request header. 1420674445201
Request Method Request Method All Capitalized Letters POST
Request Path Request Interface Path GET requests with query parameters /order/pending?num=30
Request Body String of the request subject 1) If the request has no body (usually a GET request), then Request Body is omitted
2) The value is consistent with the request
{“symbol”:“BTC_USDT”,“order_id”:“1010000867765”}
SecretKey Private Key Generated by the BitWell User Center Application DtUTxNBkTUKr4N9hwaYmDSRgxyIDD0Za

2.3.1 javascript sample

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/hmac-sha256.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/enc-base64.min.js"></script>

<script>
  var timestamp = new Date().getTime();
  var message = timestamp + 'GET' + '/users/self/verify';
  var secretKey = "-BW Secret Key-";
  var hash = CryptoJS.HmacSHA256(message, secretKey);
  var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
  document.write(hashInBase64);
</script>

2.3.2 PHP sample

$secretKey = "Apply BW Api Secret Key and replace with your's";
$timestamp = intval(microtime(true)*1000);
$requestMethod = 'GET';
$requestPath = '/api/v1/orders/pending';
$requestBody = '';
$message = $timestamp.$requestMethod.$requestPath.$requestBody;

$s = hash_hmac('sha256', $message, $secretKey, true);
echo base64_encode($s);

2.3.3 Python 2.7 sample

import hashlib
import hmac
import base64
import time

timstamp = int(round(time.time() * 1000))
m = str(timstamp) + 'GET' + '/order/pending?start=1' + '' 
message = bytes(m).encode('utf-8')
secret = bytes("--secretKey--").encode('utf-8')

signature = base64.b64encode(hmac.new(secret, message, digestmod=hashlib.sha256).digest())
print(signature)

2.3.4 Go sample

package main

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"fmt"
	"time"
)

func ComputeHmac256(message string, secret string) string {
	key := []byte(secret)
	h := hmac.New(sha256.New, key)
	h.Write([]byte(message))
	return base64.StdEncoding.EncodeToString(h.Sum(nil))
}

func main() {
	timestamp := time.Now().UnixNano() / 1000000
	message := fmt.Sprintf("%d%s%s%s", timestamp, "GET", "/order/pending?from=3", "")
	secretKey := "-BW Secret Key-"
	fmt.Println(ComputeHmac256(message, secretKey))
}

hmac Reference: https://tools.ietf.org/id/draft-mcgrew-aead-aes-cbc-hmac-sha2-03.html

hmac sha256 Example Reference: https://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/

2.4 Timestamps

The BW-ACCESS-TIMESTAMP request header must be in Unix timestamp format (e.g. 1420674445201), accurate to the millisecond.

2.5 Websocket Signing

Note: When signing Websocket, the Request Method is set to POST, and the Request Path and Request Body are set to empty strings

Market Symbols

1. Spot-Market Symbols

Request Method: GET
Request Address: /pub/openapi/v1/symbol/spot/all
Login Required: No

Params: None

Result:

Key Key Type Remark
base_asset string base asset code
quote_asset string quote asset code
symbol string symbol code
price_precision int price precision
volume_precision int volume precision
quote_asset_precision int quote asset precision
base_asset_precision int base asset precision
{
    "data": [
        {
            "base_asset": "USDT",
            "quote_asset": "BTC",
            "symbol": "BTC_USDT",
            "price_precision": 2,
            "volume_precision": 4
        },
        {
            "base_asset": "USDT",
            "symbol": "ETH_USDT",
            "price_precision": 2,
            "quote_asset": "ETH",
            "volume_precision": 4
        }
    ],
    "errmsg": "",
    "errno": 0
}

2. Index-Market Symbols

Request Method: GET
Request Address: /pub/openapi/v1/symbol/index/all
Login Required: No

Params: None

Result:

Key Key Type Remark
base_asset string base asset code
quote_asset string quote asset code
symbol string symbol code
price_precision int price precision
volume_precision int volume precision
{
    "data": [
        {
            "base_asset": "USDT",
            "symbol": "BTC_INDEX",
            "price_precision": 2,
            "quote_asset": "FT_INDEX",
            "volume_precision": 0
        },
        {
            "base_asset": "USDT",
            "symbol": "MKR_INDEX",
            "price_precision": 2,
            "quote_asset": "FT_INDEX",
            "volume_precision": 0
        }
    ],
    "errmsg": "",
    "errno": 0
}

3. Options-Market Symbols

Request Method: GET
Request Address: /pub/openapi/v1/symbol/options/all
Login Required: No

Params:None

Result:

Key Key Type remark
base_asset string base asset code
symbol string symbol code
price_precision int price precision
volume_precision int volume precision
direction int direction:long:1,short:2
index_symbol string relate index symbol code
multiple string contract multiplier
strike_price string strike price
strike_time int64 strike time,accurate to seconds
underlying_asset string underlying asset code
quote_asset_precision int quote asset precision
{
    "data": [
        {
            "base_asset": "USDT",
            "symbol": "FIL-20200927-16-C",
            "direction": 1,
            "index_symbol": "FIL_INDEX",
            "multiple": "10",
            "price_precision": 2,
            "strike_price": "16",
            "strike_time": 1601197200,
            "underlying_asset": "FIL",
            "volume_precision": 0
        },
        {
            "base_asset": "USDT",
            "symbol": "MKR-20201002-900-C",
            "direction": 1,
            "index_symbol": "MKR_INDEX",
            "multiple": "0.1",
            "price_precision": 2,
            "strike_price": "900",
            "strike_time": 1601629200,
            "underlying_asset": "MKR",
            "volume_precision": 0
        },
        {
            "base_asset": "USDT",
            "symbol": "BTC-20201002-7500-P",
            "direction": 2,
            "index_symbol": "BTC_INDEX",
            "multiple": "0.1",
            "price_precision": 2,
            "quote_asset": "FT_OPTIONS",
            "strike_price": "7500",
            "strike_time": 1601629200,
            "underlying_asset": "BTC",
            "volume_precision": 0
        }
    ],
    "errmsg": "",
    "errno": 0
}

4. Futures-Market Symbols

Request Method: GET
Request Address: /pub/openapi/v1/symbol/swap/all
Login Required: No

Params: None

Result:

Key Key Type remark
base_asset string base asset code
symbol string symbol code
price_precision int price precision
volume_precision int volume precision
index_symbol string relate index symbol code
multiple string contract multiplier
underlying_asset string underlying asset code
quote_asset_precision int quote asset precision
{
    "data": [
        {
            "base_asset": "USDT",
            "index_symbol": "BTC_INDEX",
            "multiple": "0.1",
            "price_precision": 2,
            "symbol": "BTCUSDT_SWAP",
            "underlying_asset": "BTC",
            "volume_precision": 0
        }
    ],
    "errmsg": "",
    "errno": 0
}

Spot API

The output structure is as follows

Key Key Type Note
data object Back to data
errmsg string Error messages
errno int Error code ( 0 : for success)
{
    "data":{},
    "errmsg":"",
    "errno":0
}

The content-type of the output response header defaults to application/json and the corresponding errno is 0 if the response is successful.

In addition, in the page field of the page returned by the pagination, total is the total number of data items (not total pages).

1. Place an order

Request method: POST
Request address: /openapi/v1/spot/order/place
Request Authorization: Yes

Request Parameters:

{
	"symbol":"BTC_USDT",
	"order_type":"buy_limit",
	"price":8838,
	"volume":0.01,
	"client_oid":"test1111111111111"
}
Key Key Type Is it mandatory Description Default Value Note
symbol string true Trading pair NA Example: BTC_USDT, ETH_USDT
order_type string true Order type NA buy_limit:limit-buy,
sell_limit:limit-sell,
buy_market:market-buy,
sell_market:market-sell,
limit_stop_loss:limit stop loss,
limit_stop_profit:limit take profit,
market_stop_loss:market stop loss,
market_stop_profit:market stop profit,
buy_post_only: buy post only,
sell_post_only: sell post only
price float false Order price NA Not valid for market orders
volume float true Order volume NA
tri_price float false Trigger price for stop-loss and take-profit orders NA
remain_type string false Remaining Treatment Type cancel: Immediate cancellation of unfulfilled partial orders
limit_match_best: Place order at the best traded price, or cancelled if not filled
limit_last: Place order at the last traded price, or cancelled if not filled
limit_side_best: Place order at the best available market price. If there is no market, then cancel the order.
limit: Place order with the limit price
client_oid string false User-created order id NA Maximum length is 32 characters
retain_seconds int false Pending order retention time 0 Unit: seconds, 0 means not overdue

order_type Specific Categories

1.1 buy_limit: limit-buy

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: buy_limit
price float true Order price See above
volume float true Order volume See above

1.2 sell_limit: limit-sell

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: sell_limit
price float true Order price See above
volume float true Order volume See above

1.3 buy_market: market-buy

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: buy_market
volume float true Order volume See above

1.4 sell_market: market-sell

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: sell_market
volume float true Order volume See above

1.5 limit_stop_loss: limit stop loss

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: limit_stop_loss
price float true Order price See above
volume float true Order volume See above
tri_price float true Trigger price: the line of stop loss See above

1.6 limit_stop_profit: limit take profit

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: limit_stop_profit
price float true Order price See above
volume float true Order volume See above
tri_price float true Trigger price: the line of take profit See above

1.7 market_stop_loss: market stop loss

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: market_stop_loss
volume float true Order volume See above
tri_price float true Trigger price: the line of take profit See above

1.8 market_stop_profit: market take profit

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: market_stop_profit
volume float true Order volume See above
tri_price float true Trigger price: the line of take profit See above

1.9 buy_post_only: buy post only

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: buy_post_only
price float true Order price See above
volume float true Order volume See above

1.10 sell_post_only: sell post only

Key Key Type Is it mandatory Description Note
symbol string true Trading pair See above
order_type string true Order type Value: sell_post_only
price float true Order price See above
volume float true Order volume See above

Response Data:

Key Key Type Note
tri_order_id int Trigger Order Number (Trigger order only)
order_id int Order id
client_oid string User-created order id (if any)
{
    "data": {
        "tri_order_id": 1010000867764, 
        "order_id": 1010000867765,
        "client_oid": "c111111a11111",
    },
    "errmsg":"",
    "errno":0
}

2. Batch orders

Request method: POST
Request address: /openapi/v1/spot/order/batch_place
Request Authorization: Yes

Request Parameters:

{
    "batch_orders":[
        {
            "symbol":"XRP_USDT",
            "order_type":"buy_limit",
            "price":0.21,
            "volume":1,
            "client_oid":"test1111111111111"
        }, {
            "symbol":"XRP_USDT",
            "order_type":"sell_limit",
            "price":0.22,
            "volume":1,
            "client_oid":"test1111111111112"
        }, {
            "symbol":"XRP_USDT",
            "order_type":"buy_market",
            "volume":1,
            "client_oid":"test1111111111113"
        }, {
            "symbol":"XRP_USDT",
            "order_type":"sell_market",
            "volume":1,
            "client_oid":"test1111111111114"
        }, {
            "symbol":"XRP_USDT",
            "order_type":"limit_stop_loss",
            "price":0.21,
            "volume":1,
            "tri_price":0.19,
            "client_oid":"test1111111111115"
        }
    ]
}
Key Key Type Is it mandatory Description Default Value Note
batch_orders array true Order data NA
Key Key Type Is it mandatory Description Default Value Note
symbol string true Trading pair NA Example: BTC_USDT, ETH_USDT
order_type string true Order type NA buy_limit:limit-buy,
sell_limit:limit-sell,
buy_market:market-buy,
sell_market:market-sell,
limit_stop_loss:limit stop loss,
limit_stop_profit:limit take profit,
market_stop_loss:market stop loss,
market_stop_profit:market stop profit,
buy_post_only: buy post only,
sell_post_only: sell post only
price float false Order price NA Not valid for market orders
volume float true Order volume NA
tri_price float false Trigger price for stop-loss and take-profit orders NA
remain_type string false Remaining Treatment Type cancel: Immediate cancellation of unfulfilled partial orders
limit_match_best: Place order at the best traded price, or cancelled if not filled
limit_last: Place order at the last traded price, or cancelled if not filled
limit_side_best: Place order at the best available market price. If there is no market, then cancel the order.
limit: Place order with the limit price
client_oid string false User-created order id NA Maximum length is 32 characters
retain_seconds int false Pending order retention time 0 Unit: seconds, 0 means not expired

Order_type: Same as “order api”.

Response Data:

Key Key Type Note
items array Order data
Key Key Type Note
order_id int Order id
tri_order_id int Trigger Order Number (Trigger order only)
client_oid string User-created order id (if any)
errmsg string Error messages
errno int Error code (0: for success)
{
    "data": {
        "items": [
            {
                "client_oid":"c111111a11111",
                "tri_order_id":0,
                "order_id":1010000868734,
                "errmsg":"",
                "errno":0
            },
            {
                "client_oid":"c111111a11112",
                "order_id":0,
                "tri_order_id":0,
                "errmsg":"Invalid remain type",
                "errno":11010101
            }
        ]
    },
    "errmsg":"",
    "errno":0
}

3. Cancel orders

Request method: POST
Request address: /openapi/v1/spot/order/cancel
Request Authorization: Yes

Request Parameters:

{
    "order_id":1010000869102
}
Key Key Type Is it mandatory Description Default Value Note
order_id int true Order id NA

Response Data:

{
    "data": {
        "order_id": 1010000866876,
        "client_oid": "c111111a11111",
    },
    "errmsg":"",
    "errno":0
}

4. Batch order cancellation

Request method: POST
Request address: /openapi/v1/spot/order/batch_cancel
Request Authorization: Yes

Request Parameters:


{
	"order_ids": [
		1010000869123,
		1010000869124
	]
}
Key Key Type Is it mandatory Description Default Value Note
order_ids int[] true Order id NA

Response Data:

Key Key Type Note
success array successfully cancelled orders
failed array failed cancelled orders
Key Key Type Note
order_id int Order id
client_oid string User-created order id(if any)
Key Key Type Note
order_id int Order id
client_oid string User-created order id(if any)
errmsg string Error messages(Valid only for declined orders)
errno int Error code(Valid only for declined orders)
{
    "data": {
        "failed": [
            {
                "client_oid":"",
                "errmsg":"Failed to cancel, the order has been processed",
                "errno":11010202,
                "order_id":1010000868741
            }
        ],
        "success": [
            {
                "client_oid":"test1111111111111",
                "errmsg":"",
                "errno":0,
                "order_id":1010000868744
            },
            {
                "client_oid":"test1111111111112",
                "errmsg":"",
                "errno":0,
                "order_id":1010000868745
            }
        ]
    },
    "errmsg":"",
    "errno":0
}

5. Trading pair batch order cancellation

Request method: POST
Request address:/openapi/v1/spot/order/symbol_batch_cancel
Request Authorization:Yes

Request Parameters:


{
	"symbol": "BTC_USDT",
    "direction": 0
    "price":1.234
}
Key Key Type Is it mandatory Description Default Value Note
symbol string true Trading pair NA Example: BTC_USDT, ETH_USDT
direction int false Trading pair 0 1: Cancel sell orders; 2: Cancel buy orders; 0: Cancel buy&sell orders
price float false Cancel order price 0 Cancel all orders between the latest price and the buy one/sell one price; and the ones with a value of 0 does not take effect

Response Data:

{
    "data":{},
    "errmsg":"",
    "errno":0
}

6. Order details

Request method: GET
Request address: /openapi/v1/spot/order/query
Request Authorization: Yes

Request Parameters:

Key Key Type Is it mandatory Description Default Value Note
order_id int true Order id NA

Response Data:

Key Key Type Note
order_time int Order place time
order_id int Order id
client_oid string User-created order id
symbol string Trading pair
direction string Order side, buy: buy order, sell: sell order
price string Order price
volume string Order volume
match_volume string Order filled amount
match_amount string Order filled total
queue_price string Pending order price
queue_volume string Pending order amount
order_type string Order type,
buy_limit:limit-buy,
sell_limit:limit-sell,
buy_market:market-buy,
sell_market:market-sell,
limit_stop_loss:limit stop loss,
limit_stop_profit:limit take profit,
market_stop_loss:market stop loss,
market_stop_profit:market stop profit,
buy_post_only: buy post only,
sell_post_only: sell post only
remain_type string Remaining Treatment Type, cancel: Immediate cancellation of unfulfilled partial orders
limit_match_best: Place order at the best traded price, or cancelled if not filled
limit_last: Place order at the last traded price, or cancelled if not filled
limit_side_best: Place order at the best available market price. If there is no market, then cancel the order.
limit: Place order with the limit price
state int Order status, 0. pending, 1. open order, 2. canceling order, 3. canceled order, 4. partial filled, 5. completed, 6. error, 7. waiting for trigger, 8. triggered, 9. Trigger Price Failure
tri_direction string Trigger direction, up: up trigger, down: down trigger
tri_price string Trigger price
{
    "data": {
        "order_time": 1601283710,
        "order_id": 10100002577892,
        "client_oid": "test00001",
        "symbol": "BTC_USDT",
        "direction": "buy",
        "price": "7000",
        "volume": "0.001",
        "match_volume": "0.001",
        "match_amount": "7",
        "queue_price": "7000",
        "queue_volume": "0",
        "order_type": "buy_limit",
        "state": 5,
        "tri_price": "0",
        "tri_direction": "",
        "remain_type": "limit"
    },
    "errmsg":"",
    "errno":0
}

7. Query open Order

Request method: GET
Request address: /openapi/v1/spot/order/pending
Request Authorization: Yes

Request Parameters:

Key Key Type Is it mandatory Description Default Value Note
symbol string false Trading pair NA Example: BTC_USDT, ETH_USDT
start_date string false Query start date NA Date format yyyy-mm-dd, Query by order generation time
end_date string false Query end date NA Date format yyyy-mm-dd, Query by order generation time
num int false Number of result sets 10 Number of result sets returned per page, max. 100, default is 10 if not filled

Response Data:

Key Key Type Note
items array Order list
page object Pages info
Key Key Type Note
prev string Previous page, the value is "” when page 1..
next string Next page, the value is "” if the length of the items array is less than num.

Pagination usage:

Page 1: 
    `openapi/v1/spot/order/pending`

Previous: If the current page is greater than `1`, `prev` does not return null, as follows
    `openapi/v1/spot/order/pending?prev_id=xxxx&page_index=2`

Next: When the `items` array is equal to `num`, `next` does not return null.
    `openapi/v1/spot/order/pending?next_id=xxxx&page_index=3`
Key Key Type Note
order_time int Order place time
order_id int Order id
client_oid string User-created order id
symbol string Trading pair
direction string Order side, buy: buy order, sell: sell order
price string Order price
volume string Order volume
match_volume string Order filled amount
match_amount string Order filled total
queue_price string Pending order price
queue_volume string Pending order amount
order_type string Order type,
buy_limit:limit-buy,
sell_limit:limit-sell,
buy_market:market-buy,
sell_market:market-sell,
limit_stop_loss:limit stop loss,
limit_stop_profit:limit take profit,
market_stop_loss:market stop loss,
market_stop_profit:market stop profit,
buy_post_only: buy post only,
sell_post_only: sell post only
remain_type string Remaining Treatment Type, cancel: Immediate cancellation of unfulfilled partial orders
limit_match_best: Place order at the best traded price, or cancelled if not filled
limit_last: Place order at the last traded price, or cancelled if not filled
limit_side_best: Place order at the best available market price. If there is no market, then cancel the order.
limit: Place order with the limit price
state int Order status, 0. pending, 1. open order, 2. canceling order, 3. canceled order, 4. partial filled, 5. completed, 6. error, 7. waiting for trigger, 8. triggered, 9. Trigger Price Failure
tri_direction string Trigger direction, up: up trigger, down: down trigger
tri_price string Trigger price
{
    "data": {
        "items": [
            {
                "order_time": 1601283710,
                "order_id": 10100002577892,
                "client_oid": "test00001",
                "symbol": "BTC_USDT",
                "direction": "buy",
                "price": "7000",
                "volume": "0.001",
                "match_volume": "0.001",
                "match_amount": "7",
                "queue_price": "7000",
                "queue_volume": "0",
                "order_type": "buy_limit",
                "state": 5,
                "tri_price": "0",
                "tri_direction": "",
                "remain_type": "limit"
            },
        ],
        "page": {
            "prev": "",
            "next": "/openapi/v1/spot/order/all?next_id=10100002606285&page_index=2"
        }
    },
    "errmsg": "",
    "errno": 0
}

8. Query order history

Request method: GET
Request address: /openapi/v1/spot/order/filled
Request Authorization: Yes

Request Parameters: Same as current open order query

Response Data: Same as current open order query

9. All order query

Request method: GET
Request address: /openapi/v1/spot/order/all
Request Authorization: Yes

Request Parameters: Same as current open order query

Response Data: Same as current open order query

10. Query filled order

Request method: GET
Request address: /openapi/v1/spot/order/matches
Request Authorization: Yes

Request Parameters:

Key Key Type Is it mandatory Description Default Value Note
order_id int false Order id NA
symbol string false Trading pair NA Example: BTC_USDT, ETH_USDT
start_date string false Query start date NA Date format yyyy-mm-dd, Query by order generation time
end_date string false Query end date NA Date format yyyy-mm-dd, Query by order generation time
num int false Number of result sets 10 Number of result sets returned per page, max. 100, default is 10 if not filled

Response Data:

Key Key Type Note
items array Filled Orders list
page object Pages info
Key Key Type Note
prev string Previous page, the value is "” when page 1..
next string Next page, the value is "” if the length of the items array is less than num.

Pagination usage:Same as current open order query

Key Key Type Note
match_time int Order filled timestamp
direction string Order side, buy: buy order, sell: sell order
price string Order filled price
volume string Order filled amount
fee_asset string Fee asset
fee_volume string fee
symbol string Trading pair
bonus_asset string Maker subsidy assets
bonus_volume string Amount of maker subsidy assets
{
    "data": {
        "items": [
            {
                "direction": "sell",
                "fee_asset": "USDT",
                "fee_volume": "0.09607",
                "match_time": 1591431070,
                "price": "9607.04",
                "symbol": "BTC_USDT",
                "volume": "0.01",
                "bonus_asset": "USDT",
                "bonus_volume": "0.15"
            }
        ],
        "page": {
            "prev": "",
            "next": "/openapi/v1/spot/order/matches?next_id=1312783&page_index=2"
        }
    },
    "errmsg": "",
    "errno": 0
}

Asset API

The output structure is as follows

Key Key Type Remark
data object return data
errmsg string error message
errno int error code( 0 : as success)
{
    "data":{},
    "errmsg":"",
    "errno":0
}

The default content type of the output response header should be “application/json”. The “errno” would be 0 If it is successfully responsed.

1. Asset Query

Request Method: GET
Request Address: /openapi/v1/asset/all
Request Authorization: Yes

Params:

None

Response:

Key Key Type Remark
items array assets list
Key Key Type Remark
code string asset code
name string asset name
{
    "data": {
        "items": [
            {
                "code": "BTC",
                "name": "Bitcoin"
            },
            {
                "code": "USDT",
                "name": "Tether USD"
            }
        ]
    },
    "errmsg": "",
    "errno": 0
}

2. Spot Single Asset Balance Query

Request Method: GET
Request Address: /openapi/v1/asset/spot/balance
Request Authorization: Yes

Params:

Key Key Type Mandatory Description Remark
asset string true asset code eg: BTC

Response:

Key Key Type Remark
asset string asset code
asset_name string asset name
available string available funds
frozen string frozen funds
locked string locked funds
total string total funds(avail+frozen+locked)
{
    "data": {
        "asset": "BTC",
        "asset_name": "Bitcoin",
        "available": "1013.12720675",
        "frozen": "0",
        "locked": "0",
        "total": "1013.12720675"
    },
    "errmsg": "",
    "errno": 0
}

3. Spot All Assets Balance Query

Request Method: GET
Request Address: /openapi/v1/asset/spot/all_balance
Request Authorization: Yes

Params: None

Response:

Key Key Type Remark
items array assets balance list
Key Key Type Remark
asset string asset code
asset_name string asset name
available string available funds
frozen string frozen funds
locked string locked funds
total string total funds(avail+frozen+locked)
{
    "data": {
        "items": [
            {
                "asset": "BTC",
                "asset_name": "Bitcoin",
                "available": "1013.12720675",
                "frozen": "0",
                "locked": "0",
                "total": "1013.12720675"
            },
            {
                "asset": "USDT",
                "asset_name": "Tether USD",
                "available": "9860739.020219",
                "frozen": "279.21",
                "locked": "0",
                "total": "9861018.230219"
            },
            {
                "asset": "ETH",
                "asset_name": "Ethereum",
                "available": "10000000.995",
                "frozen": "0",
                "locked": "0",
                "total": "10000000.995"
            }
        ]
    },
    "errmsg": "",
    "errno": 0
}

4. Option Single Asset Balance Query

Request Method: GET
Request Address: /openapi/v1/asset/options/balance
Request Authorization: Yes

Params:

Key Key Type Mandatory Description Remark
asset string true asset code eg: BTC

Response:

Key Key Type Remark
asset string asset code
asset_name string asset name
available string available funds
frozen string frozen funds
total string total funds(avail + frozen + covered frozen + margin frozen)
covered_frozen string covered frozen fund
margin_frozen string margin frozen fund
{
    "data": {
        "asset": "BTC",
        "asset_name": "Bitcoin",
        "available": "8999.9",
        "covered_frozen": "0",
        "frozen": "0.1",
        "margin_frozen": "0",
        "total": "9000"
    },
    "errmsg": "",
    "errno": 0
}

5. Option All Assets Balance Query

Request Method: GET
Request Address: /openapi/v1/asset/options/all_balance
Request Authorization: Yes

Params: None

Response:

Key Key Type Remark
items array assets balance list
Key Key Type Remark
asset string asset code
asset_name string asset name
available string available funds
frozen string frozen funds
total string total funds(avail + frozen + covered frozen + margin frozen)
covered_frozen string covered frozen fund
margin_frozen string margin frozen fund
{
    "data": {
        "items": [
            {
                "asset": "BTC",
                "asset_name": "Bitcoin",
                "available": "8999.9",
                "covered_frozen": "0",
                "frozen": "0.1",
                "margin_frozen": "0",
                "total": "9000"
            },
            {
                "asset": "USDT",
                "asset_name": "Tether USD",
                "available": "90000491.665951",
                "covered_frozen": "0",
                "frozen": "218.33",
                "margin_frozen": "96.3",
                "total": "90000806.295951"
            },
            {
                "asset": "ETH",
                "asset_name": "Ethereum",
                "available": "0",
                "covered_frozen": "0",
                "frozen": "0",
                "margin_frozen": "0",
                "total": "0"
            }
        ]
    },
    "errmsg": "",
    "errno": 0
}

6. Futures Single Asset Balance Query

Request Method: GET
Request Address: /openapi/v1/asset/swap/balance
Request Authorization: Yes

Params:

Key Key Type Mandatory Description Remark
asset string true asset code eg: BTC

Response:

Key Key Type Remark
asset string asset code
asset_name string asset name
available string available funds
frozen string frozen funds
total string total funds(avail + frozen + margin frozen)
margin_frozen string margin frozen funds
{
    "data": {
        "asset": "USDT",
        "asset_name": "Tether USD",
        "available": "99773.583336",
        "frozen": "0",
        "margin_frozen": "8286.637863",
        "total": "108060.221199"
    },
    "errmsg": "",
    "errno": 0
}

7. Futures All Assets Balance Query

Request Method: GET
Request Address: /openapi/v1/asset/swap/all_balance
Request Authorization: Yes

Params: None

Response:

Key Key Type Remark
items array assets balance list
Key Key Type Remark
asset string asset code
asset_name string asset name
available string available funds
frozen string frozen funds
total string total funds(avail + frozen + margin frozen)
margin_frozen string margin frozen funds
{
    "data": {
        "items": [
            {
                "asset": "BTC",
                "asset_name": "Bitcoin",
                "available": "0",
                "frozen": "0",
                "margin_frozen": "0",
                "total": "0"
            },
            {
                "asset": "USDT",
                "asset_name": "Tether USD",
                "available": "99773.583336",
                "frozen": "0",
                "margin_frozen": "8286.637863",
                "total": "108060.221199"
            }
        ]
    },
    "errmsg": "",
    "errno": 0
}

8. Asset Transfer(Spot Account)

Request Method: POST
Request Address: /openapi/v1/asset/transfer
Login Required: Yes
Params:

Key Key Type Mandatory Description Remark
asset string Yes asset code eg:BTC/USDT
amount float Yes transfer amount eg: 1.55
to_uid int Yes payee

Result:

{
    "data": {},
    "errmsg": "",
    "errno": 0
}

Quotation API

The output structure is as follows

Key Key Type Remark
data object response data
errmsg string error message
errno int error code( 0 : as success)
{
    "data":{},
    "errmsg":"",
    "errno":0
}

The default content type of the output response header should be “application/json”. The “errno” would be 0 If it is successfully responsed.

1. K-line data(Candlestick Charts)

Request Method: GET

Request Address: /pub/openapi/v1/hq/kline

Login Required: No

Special tip: In the return data of this interface, time Is the beginning of an interval , such as:8:00~8:15, time is 8:00’s timestamp

Params:

Key Key Type Mandatory Description Remark
symbol string Yes symbol code eg: BTC_USDT
type int No K-line type look at:type params list
num int No num default 60, max 2880
ts int No timestamp get data before the timestamp

typeparams list:

type enumeration type filed description
1 day
2 hour
3 minute
4 5min
5 15min
6 30min
7 4h
8 8h
9 1week
10 1month

Result:

{
  "data": [
    {
      "symbol": "BTC_USDT",
      "time": 1593344700,
      "open": 40.34,
      "close": 39.79,
      "high": 40.34,
      "low": 39.76,
      "volume": 86,
      "amount": 3439.52,
      "type": 5
    }
  ],
  "errmsg": "",
  "errno": 0
}

Response:

filed description
time time (by seconds)
open open price
close close price
high highest price
low lowest price
volume match volume
amount match amount
type same with the param type

2. Fetch the recent market quotation

Request Method: GET

Request Address: /pub/openapi/v1/hq/quote

Login Required: No

Special tip:

Params:

Key Key Type Mandatory Description Remark
symbol string Yes symbol code eg: BTC_USDT,XRP_USDT

Result:

{
  "data": [
    {
      "amount": 21.5631,
      "amount_24": 84057335.36599398,
      "high": 11349,
      "high_24": 11349,
      "low": 10980.56,
      "low_24": 10980.56,
      "open": 11098.02,
      "prev_24": 11142.66,
      "sn": 214650314992441180,
      "state": 2,
      "symbol": "BTC_USDT",
      "time": 1596467413652610,
      "trade": 11349,
      "type": "spot",
      "volume": 0.0019,
      "volume_24": 7518.5058
    },
    {
      "amount": 86.515,
      "amount_24": 28004799.082520593,
      "high": 0.31586,
      "high_24": 0.31586,
      "low": 0.28397,
      "low_24": 0.28397,
      "open": 0.28594,
      "prev_24": 0.289,
      "sn": 214650314992060860,
      "state": 2,
      "symbol": "XRP_USDT",
      "time": 1596467414119937,
      "trade": 0.3146,
      "type": "spot",
      "volume": 275,
      "volume_24": 93996959.91
    }
  ],
  "errmsg": "",
  "errno": 0
}
field description
symbol symbol code
trade current price
high_24 24h highest
low_24 24h lowest
volume_24 24h volume
amount_24 24h amount
prev_24 price before 24h,to calculate the 24-hour fluctuation range
time last match time,unit ms
type data type “index”-index,“spot”-spot,“options”-options, “swap”-futures

3. Fetch recent orderBook

Request Method: GET

Request Address: /pub/openapi/v1/hq/orderbook

Login Required: No

Special tip: The keys (price) of the ask array is from small to large, and the keys (price) of the bid array is from large to small

Params:

Key Key Type Mandatory Description Remark
symbol string Yes symbol code eg: BTC_USDT
{
	"data": {
		"ask": [
			[45283.13, 565],
			[45283.19, 477],
			[45283.23, 696],
			[45283.43, 302],
			[45283.74, 2220],
			[45284.19, 2661],
			[45284.64, 1071],
			[45285.09, 140],
			[45285.58, 619],
			[45285.82, 2096],
			[45286.14, 7],
			[45286.92, 1629],
			[45288.27, 1725],
			[45288.72, 1886],
			[45291.17, 31364]
		],
		"bid": [
			[45281.16, 247],
			[45280.85, 44],
			[45280.6, 456],
			[45280.26, 248],
			[45280.2, 265],
			[45279.95, 1226],
			[45279.67, 1094],
			[45279.22, 2178],
			[45278.77, 1875],
			[45278.46, 683],
			[45278.15, 1478],
			[45277.11, 20923],
			[45272.95, 1621],
			[45272.5, 2153],
			[45269.35, 25945]
		],
		"sn": 0,
		"time": 1628832932000000,
		"trade": 0,
		"volume": 0
	},
	"errmsg": "",
	"errno": 0
}
field description
bid price -> volume
ask price -> volume
time snapshot time in memory, unit:μs

4. Fetch recent transaction

Request Method: GET

Request Address: /pub/openapi/v1/hq/transaction

Login Required: No

Special tip:

Params:

Key Key Type Mandatory Description Remark
symbol string Yes symbol code eg: BTC_USDT
{
  "data": [
    {
      "amount": 1721920.6,
      "direction": 1,
      "open_mode": "open",
      "price": 45313.7,
      "sn": 0,
      "subtype": "transaction",
      "symbol": "BTCUSDT_SWAP",
      "time_us": 1628833106042871,
      "volume": 38,
      "extra": 0
    }
  ],
  "errmsg": "",
  "errno": 0
}

The data is an array, which may include multiple transactions at the same time

key value
price match price
volume match volume
amount match amount
time_us match time,unit:μs
symbol symbol code

Quotation WS

1.WS Introduction

Interface Address

wss://openws.bitwellex.com/v2

wss://openws.bitwellex.co/v2

You can compare the delay time between openws.bitwellex.com and openws bitwellex.co,and choose the lower delay one for use. And we have did some link delay optimization for the domain openws.bitwellex.co for users who are on the AWS cloud services platform.

QA

QA1:

Q: The Kline time of WS is different from the value of the date in the historical data returned by the Kline interface by the unit. A: The unit of WS is: μs, and the unit of API is: seconds

QA2:

Q:For example, will the USDT_BTC-quote command be merged if I send it many times? will it push multiple messages after I send the same command?

A: It will merge and not push messages multiple times.The server performs has the unique check,if the current user subscribes to the key, the secondary subscription is invalid.

QA3:

Q: If the minutes, hours, days and time-sharing are switched many times, should I frequently send unsub requests to WS first? Firstly Send unsub,then the sub command?

A: Yes, you need to unsub the history of the client to prevent WS leakage (for example, if the user clicks 4 times, the message will be pushed 4 times if it is not unsub)

Establish connection

Address is above.

ping text

As the server and client maintain WS with heartbeat time, if there is no heartbeat or data communication within 60s, it may cause the server or client to actively disconnect. Therefore, the server provides a ping text message. Please send Ping text regularly within 60s

Format: The client Send: ping The server response: success

If the server fails to reply, it may be that the server has actively disconnected. Please reconnect.

2.Check Authentication

Authentication occurs after the connection is established. The client actively sends a text message. The message format is as follows:

{
    "action":"auth",
    "type":"openapi",
	  "access_key": "W2zxxxxND1Wxxxxtdt9gxxxxJFtxxxxQ",
	  "signature": "4F65x5A2bLaaaWVQj3Aqp+B4w+ivaA7n5Oi2SuYtCJ9o=",
	  "timestamp": "1420674445201"
}

After successful authentication, the server will return the authentication result:

{"action":"auth","type":"openapi","errmsg":"","errno":0,"ts":1602583578}

说明:

  1. If errno is not 0, the authentication fails. Refer to errmsg for details of the failure
  2. Overview of authentication logic reference API
  3. The unit of WS is: μs, and the unit of ts is: s

3.Subscription data method

The message subscription requires the client to send MSG (JSON format). The symbol is an array of transaction pairs, so batch and single subscriptions are supported

{
    "action":"sub",
    "symbol":["BTC_USDT","ETH_USDT","BTC_ETH"],
    "type":"quote"
}

Description:

action: sub-add subscribe,unsub-cancel subscribe

symbol: symbol codes array,support batch or single subscribe

4.Data Index

case Quotation Data, symbol equals thie specific code(eg:BTC_USDT), type has the follow values:

case User Order: symbol equals “USER_ORDER”,type has the follow values:

case User Option, symbol equals “USER_OPTION”,type has the follow values:

5.Quotation data

{
	"amount_24": 1359041553290.97,
	"high_24": 45678,
	"highest_bid": 45338.04,
	"leverage": 0,
	"low_24": 43805.35,
	"lowest_ask": 45339.94,
	"prev_24": 45164.09,
	"prev_1h": 45240.93,
	"sn": 0,
	"state": 0,
	"subtype": "quote",
	"symbol": "BTCUSDT_SWAP",
	"time": 1628833420434784,
	"trade": 45338.92,
	"type": "swap",
	"volume_24": 30429594
}

Description:

Field Description
symbol symbol code
trade trade price
high_24 24h highest
low_24 24h lowest
highest_bid highest bid
lowest_ask lowest ask
volume_24 24h match volume
amount_24 24h match amount
prev_24 price before 24h,to calculate the 24-hour fluctuation range
time last match time,unit ms
type data type “index”-index,“spot”-spot,“options”-options, “swap”-futures

6.K-line Data

 {
    "symbol":"BTC_USDT",
    "open":1.0,
    "high":1.0,
    "low":1.0,
    "volume":4.0,
    "amount":4.0,
    "close":1.0, 
    "subtype":"kline-15min",
    "time": 1592619538684837
 }    
Field Description
open open price
high highest price
low lowest price
close close price
time current time by unix format,unit:μs
volume match volume
amount match amount

kline-{type} params list:

type enumeration type filed description
1 day
2 hour
3 minute
4 5min
5 15min
6 30min
7 4h
8 8h
9 1week
10 1month

7.Transaction Data

[
    {
    "symbol":"BTC-0703-9000-C",
    "price":39.01,
    "volume":4,
    "amount":156.04,
    "direction":1,
    "subtype":"",
    "open_mode":"open",
    "time_us":1593347347135782,
    "sn":198669755295637272
    },
    {
    "symbol":"BTC-0703-9000-C",
    "price":38.93,
    "volume":5,
    "amount":194.65,
    "direction":1,
    "subtype":"transaction",
    "time_us":1593347347135784,
    "sn":198669755295637272
    }
]

The data is an array, which may include multiple transactions at the same time

Field Description
price match price
volume match volume
amount match amount
time_us match time,unit:μs
symbol symbol code

8.OrderBook Data

{
    "bid":{
        "38.76":1,
        "38.64":1,
        "38.63":8,
        "38.62":3,
        "38.58":6,
    },
    "ask":{
        "38.87":6,
        "38.88":1,
        "38.89":6,
        "38.9":8,
        "38.97":2,
    },
    "trade":38.87,
    "volume":3,
   "symbol": "BTC_USDT",
   "subtype":"orderbook",
    "time":1593347487172380,
    "sn":198669755295637354
}

Field Description
bid orderbook bid data
—key price
—value volume
ask orderbook ask data
—key price
—value volume
trade recent match price
volume recent match volume

9.Option Data

{
    "theory_price":35.95,
    "delta":0.5389,
    "gamma":0.0047,
    "theta":-3.5326,
    "vega":41.3693,
    "leverage":12.5184,
    "iv":0,
    "open_positions":0,
    "symbol": "BTC-0703-9000-C",
    "subtype":"option"
}

Description:

Field Description
theory_price theory price
delta delta
gamma gamma
theta theta
vega vega
leverage leverage ratio
iv implied volatility
open_positions open positions
symbol symbol code
subtype subscribe type

10.Perpetual Contract Information Data

{
	"theory_price": 45338.84,
	"mark_price": 45338.84,
	"funding_rate": 0.00009,
	"next_funding_rate": 0.00009,
	"symbol": "BTCUSDT_SWAP",
	"subtype": "swap",
	"open_positions": 609038,
	"ema": 45335.77
}

field info:

Field Description
mark_price mark price
funding_rate current funding rate
next_funding_rate estimate funding rate
symbol symbol code
subtype subscribe type
open_positions open positions

User related WS

1.summary

Authorization / data format is same with the appointment of Quotation WS

2.User Order

Subscription format

{
    "action":"sub",
    "symbol":["USER_ORDER"],
    "type":"state_change" # Change of order
}

Response

Same as order list format

3.User Options

Subscription format

{
    "action":"sub",
    "symbol":["USER_OPTION"],
    "type":"pos_change" # Change of position
}

Response

{
	"symbol": "BTC-20201016-7500-C"
	"open_mode": "buy",
	"open_volume": 0,
	"frozen_volume": 0,
}
Key Key Type Description
symbol string symbol code
open_mode string open mode, buy: open buy, margin_sell:margin sell,covered_sell:covered sell
open_volume int open volume
frozen_volume int frozen volume

4.User Futures

Subscription format

{
    "action":"sub",
    "symbol":["USER_SWAP"],
    "type":"pos_change" # Change of position
}

Response

Same as position list

WELL-Platform token related data

1.Update of platform currency quantity classification

Request Method: GET
Request Address:/pub/openapi/v1/collateral/well_updates
Login Required:No

Params: None

Result:

Key Key Type Remark
lock_amount number lock amount of WELL
circulate_amount number circulate amount of WELL
lock_percentage number lock_amount/circulate_amount, keep 4 decimal,
destroyed_amount number destroyed amount of WELL
announce_issued_amount number announce issued amount of WELL
destroyed_percentage number destroyed_amount/announce_issued_amount,keep 4 decimal
{
    "data": {
        "lock_amount": 36200,
        "circulate_amount": 100000,
        "lock_percentage": 0.36,
        "destroyed_amount": 10000,
        "announce_issued_amount": 1000000,
        "destroyed_percentage": 0.01 
    },
    "errmsg": "",
    "errno": 0
}