NAV
English 繁體中文 中文

Interface Description

Feedback Email

Email: api@bg.exchange

request address

HTTP request address

HOST: https://api.bg.exchange/hk

WEBSOCKET request address

Response Status

HTTP/1.1 400

{
  "code":1087,
  "message": "No data found"
}

HTTP/1.1 401

{
  "code":40001,
  "message": "ACCESS_KEY cannot be empty"
}

HTTP/1.1 500

{
  "code":500,
  "message":"Internal Server Error"
}
Status Code Meaning Example
200 Success Request
400 Bad Request -- The client should not repeat this request without modification. message string
401 Unauthorized -- Your API key is wrong, See Authentication Description message string
500 Internal Server Error -- We had a problem with our server. Try again later. message string

Glossary

noun suggestion
currency currency, such as BTC, USDT,HKD, USD
product trading product, such as BTC_HKD

Account Information

GET get all account balance information

Get all the trading account information of the user

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

GET HOST/v1/accounts

Authentication information

For authentication information of private information, please refer to Authentication Instructions

RESPONSE EXAMPLE

[
  {
    "available": "10.0001",
    "balance": "11.0001",
    "currency": "BTC",
    "hold": "1.0"
  }
]
Parameter name Parameter description Type
available Available Quota string
hold Freeze Quota string
balance balance, including the available amount is the sum of the frozen amount string
currency Asset name string

GET get single account balance information

Get the trading account information specified by the user

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

GET HOST/v1/accounts/{currency}

Authentication information

For authentication information of private information, please refer to Authentication Instructions

Parameter name Parameter description Required Data type
currency Asset name, for example: BTC true string

RESPONSE EXAMPLE

{
  "available": "10.0001",
  "balance": "11.0001",
  "currency": "BTC",
  "hold": "1.0"
}
Parameter name Parameter description Type
available Available Quota string
hold Freeze Quota string
balance balance, including the sum of available quota and frozen quota string
currency Asset name string

Fund Transfer

POST Transfer from fund account to transaction account

Transfer funds from the Fund Account to a specified Trading Account.

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

POST HOST/v1/deposits/account

Authentication information

For authentication information of private information, please refer to Authentication Instructions

REQUEST EXAMPLE

{
  "amount": 100,
  "currency": "HKD"
}
Parameter Name Parameter Description Mandatory Data Type
amount Transfer amount true string
currency Name of transfer asset true string

RESPONSE EXAMPLE

{
  "amount": 100,
  "currency": "HKD"
}
Parameter Name Parameter Description Type
amount Transfer amount string
currency Name of transfer asset string

POST Transfer from trading account to capital account

Transfer the funds from the trading account to the capital account. After the transfer, you can carry out the cash withdrawal operation.

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

POST HOST/v1/withdrawals/account

Authentication information

For authentication information of private information, please refer to Authentication Instructions

REQUEST EXAMPLE

{
  "amount": 100,
  "currency": "HKD"
}
Parameter Name Parameter Description Mandatory Data Type
amount Transfer amount true string
currency Name of transfer asset true string

RESPONSE EXAMPLE

{
  "amount": 100,
  "currency": "HKD"
}
Parameter Name Parameter Description Type
amount Transfer amount string
currency Name of transfer asset string

Product

GET get all known trading products

Get all trading product information

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/v1/products

RESPONSE EXAMPLE

[
  {
    "product": "ETH_USD",
    "base_currency": "ETH",
    "quote_currency": "USD",
    "display_name": "ETH_USD",
    "status": "on",
    "maker_fees_rate": "0.01",
    "taker_fees_rate": "0.02",
    "quote_precision": "5",
    "trade_precision": "8",
    "amount_precision": "6",
    "max_buy_price_rate": "1.000000",
    "max_sell_price_rate": "1.000000",
    "max_trade_usd_per_order": "",
    "min_trade_usd_per_order": "",
    "max_market_taker_trade_rate": "1.000000",
    "min_market_taker_trade_rate": "1.000000",
    "max_market_trade_usd_per_order": "",
    "min_market_trade_usd_per_order": ""
  }
]

product: product

base_currency: base asset name

quote_currency : quote asset name

display_name: The display name of the transaction product, which is used as the unique identifier of the transaction product when placing an order

status : trading product status - on: has been launched, the product is open for trading, and orders can be placed and traded normally. - off: offline. This product closes all transactions, and orders that already have pending orders will be automatically canceled by the system. - pause: Trading is paused, the product closes some trades, but existing pending orders will not be canceled

amount_precision: transaction currency amount unit precision

quote_precision: Quotation currency quantity unit precision

trade_precision: trade currency price unit precision

maker_fees_rate: Maker fee rate

taker_fees_rate: taker fee rate

max_buy_price_rate: The rate at which the limit buy price cannot be higher than the latest price. If the rate exceeds the rate, the order will fail.

max_sell_price_rate: The rate at which a limit sell order cannot be lower than the latest price. If the ratio is exceeded, the order will fail to be placed.

max_trade_usd_per_order: The maximum order amount per order at the limit price. The amount will be converted into USD for calculation.

min_trade_usd_per_order: The minimum order amount per order at the limit price. The amount will be converted into USD for calculation.

max_market_taker_trade_rate: The rate at which the market buy price cannot be higher than the latest price. If the rate exceeds the rate, the order will fail.

min_market_taker_trade_rate : The rate at which market taker orders cannot be lower than the latest price. If the ratio is exceeded, the order will fail to be placed.

max_market_trade_usd_per_order : The minimum order amount for a single order at the market price. The amount will be converted into USD for calculation.

min_market_trade_usd_per_order : The minimum order amount for a single order at the market price. The amount will be converted into USD for calculation.

Parameter name Parameter description Type
product product string
base_currency base asset string
quote_currency Price asset name string
display_name display name string
amount_precision trading currency amount unit precision string
quote_precision quote currency quantity unit precision string
trade_precision trade currency price unit precision string
maker_fees_rate Seller fee rate string
taker_fees_rate taker fee rate string
max_buy_price_rate The buying price cannot be higher than the latest price (%) string
max_sell_price_rate The selling price cannot be lower than the latest price (%) string
max_trade_usd_per_order The maximum amount of a single order string
min_trade_usd_per_order Single minimum order amount string
max_market_taker_trade_rate The upper limit of taker trade price (%) string
min_market_taker_trade_rate Minimum limit of taker trade price (%) string
max_market_trade_usd_per_order The maximum amount of a single order string
min_market_trade_usd_per_order Single minimum order amount string
status status string

GET Get Single Product Details

Get the specified trading product information

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/v1/products/{product}

Parameter name Parameter description Required Data type
product commodity, for example: ETH_USD true string

RESPONSE EXAMPLE

[
  {
    "product": "ETH_USD",
    "base_currency": "ETH",
    "quote_currency": "USD",
    "display_name": "ETH_USD",
    "status": "on",
    "maker_fees_rate": "0.01",
    "taker_fees_rate": "0.02",
    "quote_precision": "5",
    "trade_precision": "8",
    "amount_precision": "6",
    "max_buy_price_rate": "1.000000",
    "max_sell_price_rate": "1.000000",
    "max_trade_usd_per_order": "",
    "min_trade_usd_per_order": "",
    "max_market_taker_trade_rate": "1.000000",
    "min_market_taker_trade_rate": "1.000000",
    "max_market_trade_usd_per_order": "",
    "min_market_trade_usd_per_order": ""
  }
]

product: product

base_currency: base asset name

quote_currency : quote asset name

display_name: The display name of the transaction product, which is used as the unique identifier of the transaction product when placing an order

status : trading product status - on: has been launched, the product is open for trading, and orders can be placed and traded normally. - off: offline. This product closes all transactions, and orders that already have pending orders will be automatically canceled by the system. - pause: Trading is paused, the product closes some trades, but existing pending orders will not be canceled

amount_precision: transaction currency amount unit precision

quote_precision: Quotation currency quantity unit precision

trade_precision: trade currency price unit precision

maker_fees_rate: Maker fee rate

taker_fees_rate: taker fee rate

max_buy_price_rate: The rate at which the limit buy price cannot be higher than the latest price. If the rate exceeds the rate, the order will fail.

max_sell_price_rate: The rate at which a limit sell order cannot be lower than the latest price. If the ratio is exceeded, the order will fail to be placed.

max_trade_usd_per_order: The maximum order amount per order at the limit price. The amount will be converted into USD for calculation.

min_trade_usd_per_order: The minimum order amount per order at the limit price. The amount will be converted into USD for calculation.

max_market_taker_trade_rate: The rate at which the market buy price cannot be higher than the latest price. If the rate exceeds the rate, the order will fail.

min_market_taker_trade_rate : The rate at which market taker orders cannot be lower than the latest price. If the ratio is exceeded, the order will fail to be placed.

max_market_trade_usd_per_order : The minimum order amount for a single order at the market price. The amount will be converted into USD for calculation.

min_market_trade_usd_per_order : The minimum order amount for a single order at the market price. The amount will be converted into USD for calculation.

Parameter name Parameter description Type
product product string
base_currency base asset string
quote_currency Price asset name string
display_name display name string
amount_precision trading currency amount unit precision string
quote_precision quote currency quantity unit precision string
trade_precision trade currency price unit precision string
maker_fees_rate Seller fee rate string
taker_fees_rate taker fee rate string
max_buy_price_rate The buying price cannot be higher than the latest price (%) string
max_sell_price_rate The selling price cannot be lower than the latest price (%) string
max_trade_usd_per_order The maximum amount of a single order string
min_trade_usd_per_order Single minimum order amount string
max_market_taker_trade_rate The upper limit of taker trade price (%) string
min_market_taker_trade_rate Minimum limit of taker trade price (%) string
max_market_trade_usd_per_order The maximum amount of a single order string
min_market_trade_usd_per_order Single minimum order amount string
status status string

Currency Information

GET Get all known currencies

Get information list of all currencies

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/v1/currencies

RESPONSE EXAMPLE

[
  {
    "currency": "ETH",
    "min_size": "0",
    "status": "on",
    "max_precision": "10",
    "type": "crypto",
    "deposit_status": "on",
    "withdraw_status": "on",
    "accuracy": "8",
    "details": [
      {
        "network_confirmations": "12",
        "sort_order": "3",
        "display_name": "ETH",
        "deposit_status": "on",
        "accuracy": "8",
        "withdraw_status": "on"
      }
    ]
  }
]

currency: currency name, which can uniquely identify the currency

accuracy: fiat deposit and withdrawal accuracy

max_precision : Maximum precision. Take the range in [18,-18]

min_size: minimum deposit and withdrawal amount

status: currency status

type: Currency type, fiat is fiat currency, crypto is digital currency

details: chain information, only digital currency type will have this part of information

deposit_status: fiat deposit status

withdraw_status: fiat withdrawal status

Parameter name Parameter description Type
currency currency name string
accuracy fiat deposit and withdrawal accuracy string
max_precision maximum precision string
min_size Minimum deposit and withdrawal amount string
status currency status string
type currency type string
details chain information string
deposit_status fiat deposit status string
withdraw_status fiat withdrawal status string

GET get single currency information

Get the information of the specified currency

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/v1/currencies/{currency}

Parameter name Parameter description Required Data type
currency currency name, for example: BTC true string

RESPONSE EXAMPLE

[
  {
    "currency": "ETH",
    "min_size": "0",
    "status": "on",
    "max_precision": "10",
    "type": "crypto",
    "deposit_status": "on",
    "withdraw_status": "on",
    "accuracy": "8",
    "details": [
      {
        "network_confirmations": "12",
        "display_name": "ETH",
        "accuracy": "8",
        "deposit_status": "on",
        "withdraw_status": "on"
      }
    ]
  }
]

currency: currency name, which can uniquely identify the currency

accuracy: fiat deposit and withdrawal accuracy

max_precision : Maximum precision. Take the range in [18,-18]

min_size: minimum deposit and withdrawal amount

status: currency status

type: Currency type, fiat is fiat currency, crypto is digital currency

details: chain information, only digital currency type will have this part of information

deposit_status: fiat deposit status

withdraw_status: fiat withdrawal status

Parameter name Parameter description Type
currency currency name string
accuracy fiat deposit and withdrawal accuracy string
max_precision maximum precision string
min_size Minimum deposit and withdrawal amount string
status currency status string
type currency type string
details chain information string
deposit_status fiat deposit status string
withdraw_status fiat withdrawal status string

Transactions And Orders

POST to create a new order

Orders can only be placed if your account has sufficient funds.

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

POST HOST/v1/orders

Authentication information

For authentication information of private information, please refer to Authentication Instructions

REQUEST EXAMPLE

{
  "product": "BTC_USDT",
  "side": "buy",
  "type": "limit",
  "stp": "dc",
  "price": "2.00",
  "size": "3.3000000000000000000",
  "client_oid": "QZ_2020-jj"
}

common parameters

product: Must be an existing product. For example BTC_USD. A list of products is available via products.

side: buy buys, sell sells.

type: order type

client_oid: Optional, default "0", user-defined order number, used for users to manage their own orders. The ID is non-unique, a string type with a length of no more than 32 characters, and must be composed of elements in uppercase and lowercase letters A-Z/a-z, numbers 0-9, underline_, and dash-, and special symbols other than those are not supported

stp: ie self trade prevention. BGE prohibits users from dealing with themselves. Users can use the stp option to specify the order processing strategy when the self-transaction scenario occurs.

time_in_force: optional, transaction command, currently supports GTC. The default is GTC

limit order parameters

price: item price

size: the quantity to buy or sell

market order parameters

size: expected transaction size. Require side to be sell, which means selling at the latest transaction price and expecting the maximum number of items sold.

funds: Expected transaction amount. side needs to be buy, which means buying at the latest transaction price and expecting to spend the maximum amount of assets.

Parameter name Parameter description Required Data type
product commodity, for example: ETH_USD true string
side buy/sell true string
type limit: limit order/market: market order true string
stp Self-transaction: dc: reduce and cancel (default) co: cancel the oldest cn: cancel the newest cb: cancel both true string
time_in_force trade command,GTC false string
funds Amount of quote currency to use false string
price price per coin false string
size Amount to buy or sell false string
client_oid User-defined order number false string

RESPONSE EXAMPLE


{
  "order_id": 129149436110880967,
  "client_oid": "Order_ower_1233"
}

order_id: the order number generated by BGE

client_oid: user-defined order number

Parameter name Parameter description Type
order_id The order number generated by BGE string
client_oid User-defined order number, default "0" string

GET query a single order according to the system order number

Get the specified order information.

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

GET HOST/v1/orders/{order_id}

Authentication information

For authentication information of private information, please refer to Authentication Instructions

Parameter name Parameter description Required Data type
order_id order ID true string

RESPONSE EXAMPLE

{
  "filled_size": "0.0000000000000000000",
  "filled_fees": "1.00",
  "filled_amount": "0.000000000000000000",
  "filled_average_price": "0",
  "created_at": "2021-12-14T03:19:15Z",
  "updated_at": "2022-01-04T06:57:34Z",
  "price": "2.00",
  "size": "3.3000000000000000000",
  "product": "BTC_USDT",
  "order_id": "127738628653088481",
  "funds": "0.0000000000000000000",
  "type": "limit",
  "side": "buy",
  "status": "7",
  "client_oid": "QZ_2020-jj"
}

status: transaction status, value range 0-7

Parameter name Parameter description Type
filled_fees filling fee string
filled_size transaction amount string
filled_amount Amount of transaction string
filled_average_price average transaction price string
funds Amount of quote currency to use string
order_id order number string
price price per unit of base currency string
product product string
side buy/sell string
size Amount of base currency to buy/sell string
status status string
type limit: limit order/market: market order string
created_at created time string
updated_at updated time string
client_oid User-defined order number string

GET Query a single order by user-defined order number

When the custom order corresponds to multiple system orders, only the latest system order will be returned.

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

GET HOST/v1/orders/single/{client_oid}

Authentication information

For authentication information of private information, please refer to Authentication Instructions

Parameter name Parameter description Required Data type
client_oid User-defined order number true string

client_oid: When the custom order corresponds to multiple system orders, only the latest system order will be returned

RESPONSE EXAMPLE

{
  "filled_size": "0.0000000000000000000",
  "filled_fees": "1.00",
  "filled_amount": "0.000000000000000000",
  "filled_average_price": "0",
  "created_at": "2021-12-14T03:19:15Z",
  "updated_at": "2022-01-04T06:57:34Z",
  "price": "2.00",
  "size": "3.3000000000000000000",
  "product": "BTC_USDT",
  "order_id": "127738628653088481",
  "funds": "0.0000000000000000000",
  "type": "limit",
  "side": "buy",
  "status": "7",
  "client_oid": "QZ_2020-jj"
}

status: transaction status, value range 0-7

Parameter name Parameter description Type
filled_fees filling fee string
filled_size transaction amount string
filled_amount Amount of transaction string
filled_average_price average transaction price string
funds Amount of quote currency to use string
order_id order number string
price price per unit of base currency string
product product string
side buy/sell string
size Amount of base currency to buy/sell string
status status string
type limit: limit order/market: market order string
created_at created time string
updated_at updated time string
client_oid User-defined order number string

GET Get Transaction Details

Qualified transaction details can be obtained according to different query conditions

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

GET HOST/v1/fills

Authentication information

For authentication information of private information, please refer to Authentication Instructions

Parameter name Parameter description Required Data type
after is used for pagination. Set end cursor to after date. false integer(int64)
before is used for pagination. set start cursor to before date false integer(int64)
limit limits the number of returned results, the default is 100, the maximum is 1000 false integer(int32)
product product id false string
order_id order id false string
client_oid User-defined order number false string

RESPONSE EXAMPLE

[
  {
    "product": "BTC_USDT",
    "order_id": "12808732377541664481",
    "liquidity": "maker",
    "price": "19.5600000000000000000",
    "size": "0.937686000000000000",
    "fee": "0",
    "created_at": "2022-01-04T10:17:03Z",
    "updated_at": "2022-01-04T10:17:03Z",
    "side": "sell"
  }
]
Parameter name Parameter description Type
created_at order creation time string
updated_at order update time string
fee The fee paid according to the current amount filled in string
liquidity liquidity: marker, taker string
order_id order number string
price price per unit of base currency string
product product number string
side buy/sell string
size Amount of base currency to buy/sell string

GET Get current unfinished orders

Get orders that have not been executed

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

GET HOST/v1/orders

Authentication information

For authentication information of private information, please refer to Authentication Instructions

This interface can query the details of a single order, or multiple orders based on the product

Parameter name Parameter description Required Data type
after is used for pagination. Set end cursor to after date. false integer(int64)
before is used for pagination. set start cursor to before date false integer(int64)
limit limits the number of returned results, the default is 100, the maximum is 1000 false integer(int32)
order_id order id false string
client_oid User-defined order number false string
product product id false string

RESPONSE EXAMPLE

[
  {
    "price": "19.5600000000000000000",
    "size": "35.447206000000000000",
    "product": "BTC_USDT",
    "order_id": "128087977541664481",
    "funds": "592.668000000000000000",
    "type": "limit",
    "side": "sell",
    "status": "2"
  }
]

status: transaction status, value range 0-7

Parameter name Parameter description Type
funds Amount of quote currency to use string
order_id order number string
price price per unit of base currency string
product product number string
side buy/sell string
size Amount of base currency to buy/sell string
status status string
type limit: limit order/market: market order string

DELETE Cancel a single order according to the system order number

Cancel the specified outstanding order

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

DELETE HOST/v1/orders/{order_id}

Authentication information

For authentication information of private information, please refer to Authentication Instructions

Parameter name Parameter description Required Data type
order_id order id true string

RESPONSE EXAMPLE

"1277087538632480481"
Parameter name Parameter description Data type
order_id order id string

DELETE Cancel a single order according to the user-defined order number

A single order can be canceled. If the custom order corresponds to multiple system orders, cancel the latest order. If the cancellation application is successful, the corresponding system order number will be returned.

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

DELETE HOST/v1/orders/single/{client_oid}

Authentication information

For authentication information of private information, please refer to Authentication Instructions

Parameter name Parameter description Required Data type
client_oid User-defined order number true string

RESPONSE EXAMPLE

"1277087538632480481"

A list of IDs of orders that are about to be canceled

DELETE Cancel all orders by item

This method is an asynchronous method. When the user receives the interface return, it does not mean that all orders have been canceled successfully. After BGE receives the request, it will query all unfilled orders corresponding to the commodity ID under the user account, and cancel these orders asynchronously. Users can query the transaction status of a single order through /orders/{order_id}.

Speed limit: 10 times/s

Speed limit rules: ApiKey

HTTP request

DELETE HOST/v1/orders

product: the product ID to be revoked, such as "BTC_USD"

Parameter name Parameter description Required Data type
product commodity true string

A list of IDs of orders that are about to be canceled

Public Data V2

GET Kline

Get K-line data. The K-line data is grouped and returned according to the requested granularity, and the most recent 2,000 K-line data can be retrieved.

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/public/v2/products/{product}/candles

parameter name required type description
product true string path parameter commodity, such as: ETH_USD
interval false string Default time granularity 1min Reference value: [1min, 5min, 15min, 30min, 60min, 4hour, 1day, 1week, 1mon] For details, please refer to K Line Channel Subscription
from true long start time, request data after this timestamp (seconds)
to true long end time, the data (seconds) before the requested timestamp
size false int default 500, maximum 1000[1,1000]

REQUEST EXAMPLE


GET /public/v2/products/ETH_USDT/candles?interval=1min&from=1639584000&to=1639584000&size=100

RESPONSE EXAMPLE

{
  "code": 200,
  "data":
  [
    {
      "id": 1690952460,
      "open": "3.5334",
      "close": "3.5334",
      "high": "3.5334",
      "low": "3.5334",
      "vol": "0",
      "count": 0,
      "filled_size": "0"
    },
    {
      "id": 1690952520,
      "open": "3.5334",
      "close": "3.5334",
      "high": "3.5334",
      "low": "3.5334",
      "vol": "0",
      "count": 0,
      "filled_size": "0"
    }
  ],
  "message": "OK"
}

parameter name type description
close string The last transaction price during this K-line period
high string The highest transaction price during this K-line
low string The lowest transaction price during this K-line period
open string The first transaction price during this K-line period
filled_size string turnover
count int The number of transactions during this k-line period
vol string volume
id long unique id

GET order book

Get Order-book data. Order-book data is sorted by price from high to low, and those with the same price are sorted by time.

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/public/v2/products/{product}/orderbook

parameter name required type description
product true string path parameter commodity, such as: ETH_USD
interval false string Indicator period Default value 0 Valid value range 0-11 Please refer to Deep Channel Subscription

REQUEST EXAMPLE


GET /public/v2/products/ETH_USDT/orderbook?interval=0

RESPONSE EXAMPLE

{
  "code": 200,
  "data":
  {
    "bids":
    [
      [
        "5", //price
        "3.6" //quantity
      ],
      [
        "3.5334",
        "3"
      ]
    ],
    "asks":
    [],
    "seq_id": 18867339
  },
  "message": "OK"
}

parameter name type description
seq_id string ordered and unique id
bids [] buyer
asks [] seller

GET 24-hour market data of all currency pairs

Get all product market information

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/public/v2/products/overview/tickers

REQUEST EXAMPLE


GET /public/v2/products/overview/tickers

RESPONSE EXAMPLE

{
  "code": 200,
  "data":
  [
    {
      "id": 1691132221,
      "product": "BTC_USDT",
      "open": "7.13",
      "close": "3.2713",
      "high": "7.13",
      "low": "2.9313",
      "vol": "1979.89",
      "count": 0,
      "change": "-3.8587",
      "seq_id": 22757,
      "filled_size": "6916.093957",
      "change_percent": "-0.5412"
    }
  ],
  "message": "OK"
}
parameter name type description
close int 24-hour latest transaction price
high int The highest transaction price within 24 hours
low int The lowest transaction price within 24 hours
open int The first transaction price started 24 hours ago
filled_size string turnover within 24 hours
vol string Trading volume within 24 hours
change string 24 hour price change
change_percent string 24 hour price change (percentage)
seq_id long unique and ordered id
count int 24-hour transaction count
product string commodity, for example: ETH_USD
id long unique id

GET single currency pair 24-hour market data

Obtain product market information

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/public/v2/products/{product}/ticker

parameter name required type description
product true string path parameter commodity, such as: ETH_USD

REQUEST EXAMPLE


GET /public/v2/products/ETH_USDT/ticker

RESPONSE EXAMPLE

{
  "code": 200,
  "data":
  {
    "id": 1691132024,
    "product": "ETH_USDT",
    "open": "7.13",
    "close": "3.2713",
    "high": "7.13",
    "low": "2.9313",
    "vol": "1979.89",
    "count": 0,
    "change": "-3.8587",
    "seq_id": 22757,
    "filled_size": "6916.093957",
    "change_percent": "-0.5412"
  },
  "message": "OK"
}
parameter name type description
close int 24-hour latest transaction price
high int The highest transaction price within 24 hours
low int The lowest transaction price within 24 hours
open int The first transaction price started 24 hours ago
filled_size string turnover within 24 hours
vol string Trading volume within 24 hours
change string 24 hour price change
change_percent string 24 hour price change (percentage)
seq_id long unique and ordered id
count int 24-hour transaction count
product string commodity, for example: ETH_USD
id long unique id

GET single currency pair real-time transaction data

Get the latest deals list for products

Speed Limit: None

Speed limit rules: None

HTTP request

GET HOST/public/v2/products/{product}/trades

parameter name required type description
product true string path parameter commodity, such as: ETH_USD
size false int size per request: default value 500 maximum value 1000

REQUEST EXAMPLE


GET /public/v2/products/ETH_USDT/trades?size=1

RESPONSE EXAMPLE

{
  "code": 200,
  "data":
  [
    {
      "vol": "0.1",
      "ts": 1691029846352,
      "price": "5",
      "direction": "sell",
      "id": 17078143
    }
  ],
  "message": "OK"
}
parameter name type description
direction string transaction direction buy / sell
price string transaction price
vol string volume
id string unique id
ts long transaction time stamp

WEBSOCKET

Welcome to the BGE digital currency exchange WebSocket subscription message protocol. The protocol allows you to subscribe to and receive market data, trading information and other relevant information in real time through a WebSocket connection.

Hope this document can help you quickly understand our digital currency exchange WebSocket subscription message protocol. If you have any questions or need further assistance, please do not hesitate to contact our technical support team. I wish you a happy use!

WEBSOCKET basic instructions

WebSocket is a network protocol for full-duplex communication over a single TCP connection, which provides a means of real-time data transfer between a client and a server. By using WebSocket, you can subscribe and receive real-time market data and other information from digital currency exchanges in real time.

Connection instructions

Before subscribing to messages, you need to establish a WebSocket connection. Connection instructions are as follows:

When subscribing to a public channel, use the address of the public service; when subscribing to a private channel, use the address of the private service

Please select the corresponding service address to connect to public or private channels according to your needs.

Subscription Limits

Each connection can send up to 50 messages in 1s, otherwise the connection will be closed forcibly

In order to maintain the stability and fairness of the connection, we have set a limit on sending messages, and each connection can send up to 50 messages per second. If you send more than 50 messages within 1 second, the connection will be forcibly closed, please be aware of this limit.

keep the connection

We will send ping messages regularly, expecting you to return pong messages as a response, if you do not receive your response for more than 30s, the server will close the connection

At the same time, you need to pay attention to the following situations:

Network problems: If there are network problems, the system will automatically disconnect.

Connection timeout: If the user does not subscribe within 30 seconds after the connection is successful or the server does not push data to the user within 30 seconds after the subscription, the system will automatically disconnect.

In order to ensure the liveness of the connection, we will regularly send ping messages in JSON format to the client: {"ping": timestamp}. You need to send a {"pong": timestamp} text message promptly after receiving the ping message to indicate that the connection is alive. If we do not receive a response from you within 30 seconds, we will close the connection and recommend the following:

  1. Reply a {"pong": timestamp} immediately after receiving a {"ping": timestamp} message.

  2. Expect a literal string {"ping": timestamp} as heartbeat message. If not received within N seconds, issue an error or reconnect.

  3. The timestamp in the pong message you reply should use the timestamp in the received ping message.

ping message example


{
    "ping": 1635065532000
}

pong message example


{
    "pong": 1635065532000
}

request error

Regardless of the private channel or public channel, when the server fails to process the request you send, the server will return a unified error message, which is convenient for the client to process.

Error messages mainly consist of two parts: error code and message. Codes are generic, but messages may vary.

For error codes and messages, please refer to: Status Code Comparison Table, Other Error Status Code Comparison Table

Error Message Response Parameter Description

parameter name type description
event string event name sent by user event list
msg string error message
code int status code status code comparison table

Description of common error codes

  1. Error code 400: Usually you need to check whether the request parameters you provide are correct, or whether there are required parameters that are not filled.

  2. Error code 401: Usually you need to ensure that you have received a successful login response, and this error will occur when you subscribe to a private channel without logging in.

  3. Error code 500: It is usually an internal server error. It is recommended that you try again later.

Bad request example 1 The request structure used in this example is wrong, please replace it with your actual request parameters.

{
    "event": "sub",
    "para": {
        "biz": "market",
        "type": "percent10",
        "product": "ETH_USDT"
    },
    "zip": true
}

Bad request response example 1

{
    "event": "sub",
    "code": "400",
    "msg": "Invalid request: {\"event\":\"sub\",\"para\":{\"biz\":\"market\",\"type\":\"percent10\ ",\"pairCode\":\"ETH_USDT\"},\"zip\":true}"
}

Bad request example 2 The access_key value used in this example is empty, please ensure that the required parameters are filled.

{
  "event": "login",
  "params": {
    "type": "api",
    "access_key": "",
    "access_sign": "sign",
    "access_timestamp": 14000000000
  }
}

Bad request response example 2

{
  "event": "login",
  "code": 40001,
  "msg": "ACCESS_KEY cannot be empty"
}

WEBSOCKET public channel V2

sequence number seq_id description

  1. seq_id is a serial number of the exchange market. When a user uses one or more WebSockets to connect to the same channel, in addition to the real-time transaction data, he will receive data pushes with the same serial number, and the user needs to handle the duplication by himself. data, a seq_id can be used to build a sequence of messages, which will allow the user to detect packet loss and ordering of messages.

  2. seq_id is a monotonically increasing number with a minimum value of 0.

K-line channel

Subscribe or request to get K-line (the latest K-line) data push

K-line chart interval parameters:

min -> minute; hour -> hour; day -> day; week -> week; mon -> month

Field Description:

subscription

request example

{
    "event": "sub",
    "biz": "market",
    "type": "candles",
    "product": "BTC_USDT",
    "interval": "15min",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "candles",
    "ts": 1666851880448,
    "code": 200,
    "status": "OK",
    "event": "sub",
    "product": "BTC_USDT",
    "interval": "15min"
}

unsubscribe

request example

{
    "event": "unsub",
    "biz": "market",
    "type": "candles",
    "product": "BTC_USDT",
    "interval": "15min",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "candles",
    "ts": 1666851880448,
    "code": 200,
    "status": "OK",
    "event": "unsub",
    "product": "BTC_USDT",
    "interval": "15min"
}

Push data

Push data example

{
    "id": "1689144300",
    "biz": "market",
    "type": "candles",
    "data":
    {
        "id": 1689144300,
        "open": "3.7366",
        "close": "3.7366",
        "high": "3.7366",
        "low": "3.7366",
        "filled_size": "0",
        "vol": "0",
        "count": 0,
        "seq_id": 112588635
    },
    "product": "BTC_USDT",
    "interval": "15min"
}

request data

Parameter Description:

Get the K-line data request example of the specified range

{
    "event": "req",
    "biz": "market",
    "type": "candles",
    "product": "BTC_USDT",
    "interval": "15min",
    "zip": false,
    "from": 1687561511,
    "to": 1688641511
}

Get the K-line data response example in the specified range

{
    "biz": "market",
    "type": "candles",
    "product": "BTC_USDT",
    "ts": 1690252632272,
    "code": 200,
    "status": "OK",
    "data":
    [
        {
            "id": 1688398200,
            "open": "3.3706",
            "close": "3.3706",
            "high": "3.3706",
            "low": "3.3706",
            "filled_size": "0",
            "vol": "0",
            "count": 0
        },
        {
            "id": 1688399100,
            "open": "3.3706",
            "close": "3.3706",
            "high": "3.3706",
            "low": "3.3706",
            "filled_size": "0",
            "vol": "0",
            "count": 0
        }
    ],
    "event": "req",
    "interval": "15min"
}



Close channel

Subscribe to obtain real-time transaction incremental push data of products

Get the latest transaction data, and push the transaction data when there is transaction data. Each push may contain multiple transaction data.

Field Description:

subscription

request example

{
    "event": "sub",
    "biz": "market",
    "type": "fills",
    "product": "BTC_USDT",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "fills",
    "product": "BTC_USDT",
    "ts": 1690165577416,
    "code": 200,
    "status": "OK",
    "event": "sub"
}

unsubscribe

request example


{
    "event": "unsub",
    "biz": "market",
    "type": "fills",
    "product": "BTC_USDT",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "fills",
    "ts": 1666851880448,
    "code": 200,
    "status": "OK",
    "event": "unsub",
    "product": "BTC_USDT"
}

Push data

Push data example

{
    "id": "310529",
    "biz": "market",
    "type": "fills",
    "data":
    [
        {
            "vol": "0.79",
            "ts": 1689152279117,
            "price": "3.4134",
            "direction": "buy",
            "id": 310529000
        }
    ],
    "product": "BTC_USDT"
}

Deep Channel

Subscribe to obtain product order book incremental push data

Push once every 500 milliseconds at the fastest, and also push when no event is triggered, bids and asks may be empty arrays if there is no data in the handicap

OrderBook subscription interval parameters: [The current gear supports the maximum precision, the current gear supports the maximum depth]:

Explanation: interval=5, the buyer's price in bids pushed can only be accurate to one decimal place, and the maximum array size of bids is 150

Field Description:

subscription

request example

{
    "event": "sub",
    "biz": "market",
    "type": "orderbook",
    "product": "BTC_USDT",
    "interval": "0",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "orderbook",
    "ts": 1666851880448,
    "code": 200,
    "status": "OK",
    "event": "sub",
    "product": "BTC_USDT",
    "interval": 0
}

unsubscribe

request example

{
    "event": "unsub",
    "biz": "market",
    "type": "orderbook",
    "product": "BTC_USDT",
    "interval": "0",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "orderbook",
    "ts": 1666851880448,
    "code": 200,
    "status": "OK",
    "event": "unsub",
    "product": "BTC_USDT",
    "interval": 0
}

Push data

Push data example


{
    "id": "1689143926",
    "biz": "market",
    "type": "orderbook",
    "data":
    {
        "seq_id": 112588640, //ordered and unique id
        "bids": //buyer
        [
            [
                "3.7366", //price
                "0.66" //quantity
            ],
            [
                "3.6866",
                "0.98"
            ],
            [
                "3.4666",
                "0.33"
            ],
            [
                "3.3766",
                "0.76"
            ],
            [
                "3.3666",
                "0.7"
            ],
            [
                "3.1966",
                "0.75"
            ],
            [
                "3.1766",
                "0.06"
            ],
            [
                "3.0666",
                "0.91"
            ],
            [
                "3.0266",
                "0.73"
            ]
        ],
        "asks": //Seller
        [
            [
                "3.9966", //price
                "0.9" //quantity
            ]
        ]
    },
    "product": "BTC_USDT",//trading pair
    "interval": "0"
}



Deep depth channel

Subscribe to obtain product depth map incremental push data

Explanation: Each buy and sell order takes up to 200 orders within 10% of the average price, sell 1 order within 10% of the upward price fluctuation, and buy 1 order within 10% downward fluctuation

Push once every 500 milliseconds at the fastest, and also push when no event is triggered, bids and asks may be empty arrays if there is no data in the handicap

Field Description:

subscription

request example

{
    "event": "sub",
    "biz": "market",
    "type": "percent10",
    "product": "BTC_USDT",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "percent10",
    "ts": 1666851880448,
    "code": 200,
    "status": "OK",
    "event": "sub",
    "product": "BTC_USDT"
}

unsubscribe

request example

{
    "event": "unsub",
    "biz": "market",
    "type": "percent10",
    "product": "BTC_USDT",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "percent10",
    "product": "BTC_USDT",
    "ts": 1690193555943,
    "code": 200,
    "status": "OK",
    "event": "unsub"
}

Push data

Push data example


{
    "id": "1689143539", //The unique id of the message
    "biz": "market",
    "seq_id": 112588640, //ordered and unique id
    "type": "percent10", //business type
    "data":
    {
        "bids": //buyer
        [
            [
                "3.8646667", //price
                "0" //quantity
            ]
        ],
        "asks": //Seller
        [
            [
                "3.8685333", //price
                "0" //quantity
            ],
            [
                "3.8704666",
                "0"
            ]
        ],
        "seq_id": 112588640
    },
    "product": "BTC_USDT"
}


Quote channel

Obtain product 24-hour ticker incremental push data

Field Description:

subscription

request example

{
    "event": "sub",
    "biz": "market",
    "type": "ticker",
    "product": "BTC_USDT",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "ticker",
    "ts": 1666851880448,
    "code": 200,
    "status": "OK",
    "event": "sub",
    "product": "BTC_USDT"
}

unsubscribe

request example

{
    "event": "unsub",
    "biz": "market",
    "type": "ticker",
    "product": "BTC_USDT",
    "zip": false
}

Response example

{
    "biz": "market",
    "type": "ticker",
    "ts": 1689946788754,
    "code": 200,
    "status": "OK",
    "event": "unsub",
    "product": "BTC_USDT"
}

Push data

Push data example


{
    "id": "1689144487",
    "biz": "market",
    "type": "ticker",
    "product": "BTC_USDT",
    "data":
    [
        {
            "id": 1689144487,
            "seq_id": 112588640,
            "open": "3.7366",
            "close": "3.7366",
            "high": "3.7366",
            "low": "3.7366",
            "filled_size": "0",
            "vol": "0",
            "count": 0,
            "change": "0",
            "change_percent": "0"
        }
    ]
}

Request the latest market data for the specified trading pair

Get the latest market data request example for a specified trading pair

{
    "event": "req",
    "biz": "market",
    "type": "ticker",
    "product": "BTC_USDT",
    "zip": false
}

Example of getting the latest market data response for a specified trading pair

{
    "biz": "market",
    "type": "ticker",
    "ts": 1689133337870,
    "code": 200,
    "status": "OK",
    "data":
    {
        "id": 1689133336,
        "seq_id": 112588640,
        "open": "3.7366",
        "close": "3.7366",
        "high": "3.7366",
        "low": "3.7366",
        "filled_size": "0",
        "vol": "0",
        "count": 0,
        "change": "0",
        "change_percent": "0"
    },
    "event": "req",
    "product": "BTC_USDT"
}

Public channel Request field description

Parameter name Type Mandatory Description Reference value
event string yes request event event
biz string yes line of business line of business
type string yes business type type
product string yes trading pair BTC_USDT
interval string no frequency 1min
zip bool yes whether to enable gzip true, false

Response field description of public channel

Parameter name Type Mandatory Description Reference value
event string yes request event event
biz string yes line of business line of business
type string yes business type type
product string yes trading pair BTC_USDT
interval string no frequency 1min
code int yes error code
status string yes error code status can be ignored
ts long yes unix timestamp ignorable
data json no business data refer to specific business data instructions

List of public channel events

Event Name Type Description
sub string Subscribe to events, initiated by the client
unsub string unsubscribe event, initiated by the client
req string request data event, initiated by the client

Public Channel Biz List

Biz Name Type Description
market string spot market

List of Public Channel Types

Type Name Type Description
fills string transaction data
candles string candlestick data
orderbook string order book
ticker string 24 hour ticker
percent10 string depth

WEBSOCKET private channel V2

Private channel login authentication

Login authentication is required before subscribing to a private channel. Only authenticated users can subscribe to the user's asset information and order status change information.

Note: If no login authentication operation is performed, subscribing to a private channel will return an error message

Login request example

{
  "event": "login",
  "params": {
    "type": "api",
    "access_key": "de0535f81d51c998b7fbcf00f189f294",
    "access_sign": "sign",
    "access_timestamp": 14000000000
  }
}

Login success response example status code comparison table

{
  "ts": 1690364037503,
  "code": 200,
  "status": "OK",
  "event": "login"
}

Login failure response example Please refer to the general error description

Login request parameter description

parameter name required type description
params.type yes string authentication method:
api:apiKey authentication;
params.access_key Yes string Authentication Description
params.access_sign Yes string Authentication Description
params.access_timestamp yes long authentication description
event yes string event name event list

Login response parameter description

parameter name type description
event string event name event list
status string status information can be ignored
code int status code status code comparison table
ts long unix timestamp

Private channel assets

Subscriber's asset changes will be pushed only when there is data update. Currently only supports subscription by product.

Please refer to Common Request Parameter Description and General Response Parameter Description for request and response parameter description

Subscribe to asset data

Subscription request example

{
  "event": "sub",
  "biz": "exchange",
  "type": "assets",
  "product": "ETH_USDT",
  "zip": false
}

Subscription success response example

{
  "biz": "exchange",
  "type": "assets",
  "product": "ETH_USDT",
  "ts": 1690357632710,
  "code": 200,
  "status": "OK",
  "event": "sub"
}

Asset push data example, this example is just to illustrate the data structure, the actual push data may only contain asset information of one currency


{
  "biz": "exchange",
  "type": "assets",
  "product": "ETH_USDT",
  "data":
  [
    {
      "currency": "USDT",
      "available": "999970.5238",
      "hold": "29.4762"
    },
    {
      "currency": "ETH",
      "available": "999970.5238",
      "hold": "29.4762"
    }
  ]
}

parameter name type description
product string product name/trading pair
$data.currency string currency name
$data.available string available quantity
$data.hold string hold amount

Request the user's asset data for a single trading pair

Request a single trading pair asset data example

{
  "event": "req",
  "biz": "exchange",
  "type": "assets",
  "product": "BTC_USDT",
  "zip": false
}

Request a single transaction pair asset data response example

{
  "biz": "exchange",
  "type": "assets",
  "product": "BTC_USDT",
  "ts": 1690357632710,
  "code": 200,
  "status": "OK",
  "event": "req",
  "data":
  [
    {
      "currency": "USDT",
      "available": "999970.5238",
      "hold": "29.4762"
    },
    {
      "currency": "BTC",
      "available": "999970.5238",
      "hold": "29.4762"
    }
  ]
}
parameter name type description
product string product name/trading pair
ts long unix timestamp
$data.currency string currency name
$data.available string available quantity
$data.hold string hold amount

Private Channel Orders

The status change of the subscription user's order will be pushed only when there is data update. Currently supports order status change subscription for all trading pairs. Supports asynchronous query of the user's current entrusted order data for a single trading pair.

Please refer to Common Request Parameter Description and General Response Parameter Description for request and response parameter description

Note: The order data supports subscribing to the full amount of trading pairs. When subscribing to orders of all trading pairs at once, please note that the product parameter uses all (ignoring case)

Subscription order transaction pair order data

Subscribe to order data for all trading pairs

Subscription order trading pair order request example

{
  "event": "sub",
  "biz": "exchange",
  "type": "orders",
  "product": "ETH_USDT",
  "zip": false
}

Subscribe to all trading pairs order request example

{
  "event": "sub",
  "biz": "exchange",
  "type": "orders",
  "product": "all",
  "zip": false
}

Subscription order transaction pair order response success example

{
  "biz": "exchange",
  "type": "orders",
  "product": "ETH_USDT",
  "ts": 1690363716709,
  "code": 200,
  "status": "OK",
  "event": "sub"
}

Subscribe to all transaction pairs order response success example

{
  "biz": "exchange",
  "type": "orders",
  "product": "all",
  "ts": 1690363716709,
  "code": 200,
  "status": "OK",
  "event": "sub"
}

Subscribe to all trading pairs order data failure response example error code comparison table

{
  "biz": "exchange",
  "type": "orders",
  "product": "all",
  "ts": 1690362052646,
  "code": 500,
  "status": "FAIL",
  "event": "sub"
}

Subscription order trading pair push order data example

{
  "biz": "exchange",
  "type": "orders",
  "product": "BTC_USDT",
  "data": [
    {
      "order_id": "179577241915696235",
      "product": "BTC_USDT",
      "side": "buy",
      "price": "3.53340000",
      "size": "1.00000000",
      "filled_amount": "0.00000000",
      "funds": "1.00000000",
      "filled_size": "0.00000000",
      "type": "limit",
      "status": "1",
      "client_oid": ""
    }
  ]
}

Subscribe to all trading pairs to push orders and send data examples

{
  "biz": "exchange",
  "type": "orders",//Note that this is different from a single trading pair
  "product": "all",//Note that this is different from a single trading pair
  "data":
  [
    //....Structure reference single transaction pair push order data example
  ]
}

*Request a single transaction pair for the current entrusted order data, if the request fails, a failed response will be returned. *

Request the user's single transaction pair current entrusted order data example

{
  "event": "req",
  "biz": "exchange",
  "type": "orders",
  "product": "BTC_USDT",
  "zip": false
}

An example of a successful response to requesting a single transaction from the user for the current entrusted order data

{
  "biz": "exchange",
  "type": "orders",
  "product": "BTC_USDT",
  "ts": 1690375715106,
  "code": 200,
  "status": "OK",
  "data":
  [
    //....Structure reference single transaction pair push order data example
  ],
  "event": "req"
}
Parameter name Parameter description Type
orders_id order ID string
product commodity string
side buy/sell string
price price per unit of base currency string
size Amount of base currency to buy/sell string
filled_amount filled amount string
funds Amount of quote currency to use string
filled_size transaction amount string
type limit: limit order/market: market order/ string
status status string
client_oid default "0", user-defined order number string

status: transaction status, value range 0-7


Private channel general request parameter description

parameter name required type description
biz is string subscription module type
type yes string subscription business type
product yes string product information
event yes string event name event list
zip yes bool whether to enable gzip

Private channel general response parameter description

Parameter name Type Mandatory Description Reference value
event string yes request event event
biz string yes line of business line of business
type string yes business type type
product string yes trading pair BTC_USDT
code number yes error code
status string yes error code status
ts long yes unix timestamp

Private channel event list

Event Name Type Description
sub string Subscribe to events, initiated by the client
login string login event, initiated by the client
unsub string unsubscribe event, initiated by the client
req string request event, initiated by the client

Private Channel Biz List

Biz Name Type Description
exchange string spot transaction

Private Channel Type List

Type Name Type Description Whether to support data push subscription for all trading pairs
assets string asset changes no
orders string order status change yes

Authentication information

Each user can create up to 50 APIKeys;

Do not disclose your APIKey to anyone else to avoid loss of assets. It is recommended to bind the APIKey to an IP address for better security of your account. Multiple IP addresses are separated in English, and a maximum of 10 IP addresses are supported. API not bound to an IP address is only valid for 180 days;

Please note that binding an APIKey to a third-party platform may pose security risks that you should act with caution;

To access the private information interface, the following request headers will have to be added

Header Name Meaning
ACCESS-KEY API KEY created by the user on the BGE platform
ACCESS-SIGN Signature for the request, which is generated based on the user-created API KEY to authenticate the request’s legitimacy ACCESS-SING generation algorithm
ACCESS-TIMESTAMP Request time, usually the current timestamp Example:2022-01-08T07:19:56.339Z,or a millisecond timestamp

ACCESS-SING generation algorithm

requestPath: Consistent with the path in the documentation, e.g. /v1/products

queryString: List of request parameters. Note: Parameters needs to be orderly arranged. See remarks

params: When the request is GET or DELETE or WEBSOCKET channel for authentication, fill in ""

Parameter Name Parameter Type Description
method string GET or POST or DELETE;"" when calculating ws sign
secretKey string API KEY name created by the user on BGE
requestPath string Request path; "" for ws sign calculation
queryString string Request parameter; "" for ws sign calculation
params string Transfer data content; "" for ws sign calculation
timestamp string Current timestamp e.g.2022-01-08T07:19:56.339Z,or millisecond timestamp

Sign http request

  String timestamp=OpenAPiUtils.createTimestamp();
  String sign=OpenAPiUtils.createSign(OpenAPiUtils.POST,
  "43767b4dec6e78e07c81f89af47018dc3ab57585721bf57a389f7637a9d0506b",
  "/v1/accounts",
  "",
  s,timestamp);

Sign web socket request

  String timestamp=OpenAPiUtils.createTimestamp();
  String sign=OpenAPiUtils.createSign("","43767b4dec6e78e07c81f89af47018dc3ab57585721bf57a389f7637a9d0506b","","","",timestamp);

Generation algorithm tool class

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.HmacUtils;

public class OpenAPiUtils {
  public static final String GET = "GET";
  public static final String POST = "POST";
  public static final String DELETE = "DELETE";
  public static final Gson gson = new Gson();

  public static String createTimestamp() {
    return Instant.now().toString();
  }

  /**
   * 获取当前时间戳 例:2022-01-08T07:19:56.339Z
   * @return
   */
  public static String createTimestamp() {
    return Instant.now().toString();
  }

  /**
   * sign
   * @param method POST or GET or DELETE
   * @param secretKey for example:HKBGE-xxxxx
   * @param requestPath for example:/v1/orders
   * @param queryString Request parameters
   * @param body string empty when method is `GET`
   * @param timestamp  for example:2022-01-08T07:19:56.339Z
   * @return string
   */
  public static String createSign(String method, String secretKey, String requestPath, String queryString, String body, String timestamp) {
    String sign = "";
    method = method.toUpperCase();
    if (timestamp == null) {
      timestamp = Instant.now().toString();
    }
    if (method.equals("POST")) {
      sign = generate(timestamp, method, requestPath, queryString, body, secretKey, "HmacSHA256");
    }
    if (method.equals("GET") || method.equals("DELETE")) {
      sign = generate(timestamp, method, requestPath, queryString, "", secretKey, "HmacSHA256");
    }
    if ("".equalsIgnoreCase(method)) {
      sign = generate(timestamp, method, requestPath, queryString, "", secretKey, "HmacSHA256");
    }
    return sign;
  }

  public static String generate(final String timestamp, String method, final String requestPath,
                                String queryString, String body, final String secret, final String alg) {
    body = StringUtils.defaultIfBlank(body, StringUtils.EMPTY);
    queryString = StringUtils.isEmpty(queryString) ? "" : "?" + queryString;
    final String preHash = timestamp + method + requestPath + queryString + body;
    return encodeBase64(alg, secret, preHash);
  }

  public static String encodeBase64(final String alg, final String secret, final String data) {
    Validate.notNull(alg, "SignatureAlgorithm cannot be null.");
    Validate.notNull(data, "Signing Secret cannot be null.");
    switch (alg) {
      case "HmacMD5":
        return Base64.encodeBase64String(new HmacUtils("HmacMD5", secret).hmac(data));
      case "HmacSHA1":
        return Base64.encodeBase64String(new HmacUtils("HmacSHA1", secret).hmac(data));
      case "HmacSHA224":
        return Base64.encodeBase64String(new HmacUtils("HmacSHA224", secret).hmac(data));
      case "HmacSHA256":
        try {
          return Base64.encodeBase64String(new HmacUtils("HmacSHA256",
            secret.getBytes("UTF-8")).hmac(data.getBytes("UTF-8")));
        } catch (UnsupportedEncodingException e) {
          throw new RuntimeException(e.getMessage());
        }
      case "HmacSHA384":
        return Base64.encodeBase64String(new HmacUtils("HmacSHA384", secret).hmac(data));
      case "HmacSHA512":
        return Base64.encodeBase64String(new HmacUtils("HmacSHA512", secret).hmac(data));
      default:
        throw new IllegalArgumentException("The '" + alg.name() + "' algorithm cannot be used for signing.");
    }
  }

}

When calculating data signatures, the parameters must be transmitted in the same order as the signature string, and the queryString must not start with “?” or end with “&” to avoid authentication failure. For example: when calculating the signature for GET "http://api.bg.exchange/hk/v1/demo?a=2&b=3"

Add the api key, sign and timestamp generated by the user on BGE to the http request header.

Fill in the HTTP HEADERS in requests

RequestBuilders.post("/openapi/exchange/BTC_USDT/orders")
                        .header("ACCESS-KEY", "HKBGE-6fc437d24902cce8635806b6d79921f2")
                        .header("ACCESS-SIGN", sign)
                        .header("ACCESS-TIMESTAMP", timestamp)
                        .characterEncoding("UTF-8")
                        .content(s.getBytes(StandardCharsets.UTF_8))
                        .contentType(MediaType.APPLICATION_JSON_VALUE)

Data Dictionary

WEBSOCKET error code comparison table

Error code Instructions
200 Success
400 Invalid Request
401 Not logged in
500 System error, please try again later

User authentication error code comparison table

Error code Instructions
40001 ACCESS_KEY cannot be empty
40002 ACCESS_SIGN cannot be empty
40003 ACCESS_TIMESTAMP cannot be empty
40005 Invalid ACCESS_TIMESTAMP
40006 Invalid ACCESS_KEY
40008 Request timestamp expired
40010 API verification failed
40012 Invalid API User
40013 User banned
40014 User frozen
40015 Invalid IP request
40016 API_KEY has expired

Business error code comparison table

amount limit value is the upper and lower limit of the transaction amount/quantity configured by the product. In order to protect the market stability, BGE has limited the transaction limit according to the real-time market conditions, and the specific amount will fluctuate in real time with the market transaction situation.

Error code Instructions
999 The query data is empty
1000 No login
1001 Parameter error
1006 Currency information does not exist
1008 K line does not exist
1009 Quote does not exist
1050 Pair does not exist
1051 Notch depth does not exist
1053 Order has been blocked
1054 Less than the minimum order quantity
1055 Amount is less than balance
1056 Greater than the maximum order quantity
1057 Market order amount is invalid
1058 Failed to place an order
1059 Order does not exist
1060 Cancellation failed
1061 Order canceled
1062 Order completed
1063 Cancellation failed
1099 Currency does not exist
1029 Transferred amount is greater than transferable amount
1049 The user requests the interface too frequently
1100 Insufficient balance available
1064 KYC verification failed
1065 You have been frozen and cannot place an order
1066 Transaction password invalid
1067 Price, Price ≥ ${amount limit value}
1068 Price, Price ≤ ${amount limit value}
1069 Transaction amount precision is incorrect
1070 Quantity precision is incorrect
1071 Incorrect price precision
1072 The order quantity cannot be less than or equal to 0
1073 The order price cannot be less than or equal to 0
1074 Insufficient account balance
1075 Quantity, Amount ≥ ${amount limit value}
1076 Quantity, Amount ≤ ${amount limit value}
1077 Amount, Total ≥ ${amount limit value}
1078 Quantity, Amount ≥ ${amount limit value}
1079 Amount, Total ≤ ${amount limit value}
1080 Quantity, Amount ≤ ${amount limit value}
1081 The market order buy order has reached the highest transaction limit price, and the order has been automatically canceled
1082 The sell order of the market order has reached the minimum transaction limit price, and the order has been automatically canceled
1083 Failed to obtain user data
1084 No current order
1085 Exceeded the maximum number of orders
1087 No data found
1088 No way to verify user identity
1089 One of order_id or product cannot be empty
1090 client_oid already exists
1091 client_oid does not meet the rules
1092 The available balance of the current trading account is insufficient, whether to automatically transfer the ${0} in the fund account to the trading account, and initiate an order
1093 Insufficient account balance
1094 Transfer fail
1095 The quantity is too large
1096 Account does not exist
1097 System timeout
1098 The system is busy