- Introduction
- Start to use
- API interface encryption verification
- Spot business API reference
Welcome to use [TokenBetter][]developer documentation. This document provides an introduction of TokenBetter crypto-crypto trading service API usage methods such as market inquiry, trading, and account management . The market API is a public interface that provides market data of the crypto trading market; the trading and account API require identity authentication for functions such as order placing, order cancellation and account information query .
REST,the abbreviation of Representational State Transfer,is a kind of popular internet transfer architecture featured with clear and standard structure ,scalablity and easy operation .The advantages are as follows:
- In a RESTful architecture, each URL represents a kind of resource;
- A layer of presentation of such resources between the client end and the server;
- The client end operates on the server-side resources through four HTTP commands to realize "presentation layer state conversion". Developers are advised to use the REST API for market queries, crypto trading, and account management,etc.
Before signing any request, you must generate an API KEY via the TokenBetter website [User Center] - [API]. After generating the API KEY, you will get 3 pieces of information that you must remember:
- API Key
- Secret Key
- Passphrase API Key and Secret Key will be generated randomly.Passphrase will be set by users.
All REST requests must contain the following title:
- ACCESS-KEY API Key as a string
- ACCESS-SIGN Use base64 encoding signature (refer to signature message)
- ACCESS-TIMESTAMP As the timestamp of your request
- ACCESS-PASSPHRASE Passphrase that you set when generating the API KEY
- All requests should contain application/json type content and it should be valid JSON.
The request header of ACCESS-SIGN is gotten by encrypting the string timestamp + method + requestPath + "?" + queryString + body (+ indicates string concatenation) with HMAC SHA256 method and BASE64 Coded output. Among them, the value of timestamp is the same as the ACCESS-TIMESTAMP request header.
- method refers to request method (POST/GET/PUT/DELETE),all the letters have to be capitalized .
- requestPath refers to the request interface path
- queryString refers to the query string in the GET request
- Body is the string of the request body. If the request has no body (usually a GET request), the body can be omitted. For example: sign the following request parameters
- Get depth information, taking LTC_BTC as an example
Timestamp = 1540286290170
Method = "GET"
requestPath = "/openapi/exchange/public/LTC_BTC/orderBook"
queryString= "?size=100"Generate a string to be signed
Message = '1540286290170GET/openapi/exchange/public/LTC_BTC/orderBook?size=100' - Place an order,taking LTC_BTC as an example
Timestamp = 1540286476248
Method = "POST"
requestPath = "/openapi/exchange/LTC_BTC/orders"
body = {"price":"1","side":"buy","source":"web","systemOrderType":"limit","volume":"1"}Generate a string to be signed
Message = '1540286476248POST/openapi/exchange/LTC_BTC/orders{"price":"1","side":"buy","source":"web","systemOrderType":"limit","volume":"1"}' Then, adding the private key parameter to the string to be signed so as to generate the final string to be signed
hmac = hmac(secretkey, Message, SHA256)
```Base64 encoding for hmac before use
```java
Signature = base64.encode(hmac.digest())Root URL for REST access:`https://www.tokenbetter.com
All requests are based on the Https protocol, and the Content-Type in the request header information needs to be uniformly set to: 'application/json'. Request interaction description 1、Request parameters: encapsulate parameter according to interface request parameters. 2、Submit request parameters: Submit the encapsulated request parameters to the server through POST/GET/DELETE. 3、Server response: The server first performs parameter security verification on the user request data, and returns the response data to the user in JSON format according to the business logic after verification. 4、Data processing: Processing server response data. Success The HTTP status code 200 indicates a successful response and may contain content. If the response contains content, it will be displayed in the corresponding return content. Common error code
- 400 Bad Request – Invalid request format
- 401 Unauthorized – Invalid API Key
- 403 Forbidden – You do not have access to the requested resource
- 404 Not Found – No request found
- 429 Too Many Requests – Restricted by the system because of too frequent requests.
- 500 Internal Server Error – We had a problem with our server If it fails, the Response body has an error description
All timestamps in the API are returned in microseconds unless otherwise specified. The unit of ACCESS-TIMESTAMP in the request signature is seconds, allowing decimals to represent more precise time. The requested timestamp must be within 30 seconds of the API service time, otherwise the request will be considered expired and rejected. If there is a large deviation between the local server time and the API server time, then we recommend that you update the Http Header by querying the API server time.
1524801032573
In order to maintain the integrity of the accuracy across platforms, decimal numbers are returned as strings. It is recommended that you also convert numbers to strings when invoking a request to avoid truncation and precision errors. Integers (such as transaction numbers and order) are not quoted.
If the request is too frequent, the system will automatically limit the request and return 429 Too many requests status code in the Http Header.
- Public interface: We restrict the invocation of public interfaces by IP: at most 6 requests every 2 seconds.
- Private interface: We restrict the call of the private interface by user ID: at most 6 requests every 2 seconds.
- The special restrictions on some interfaces are noted on the corresponding interfaces.
Request
# Request
GET /openapi/exchange/public/currenciesResponse
# Response
[{
"baseIncrement": 0,
"baseSymbol": "BTC",
"makerFeesRate": "0",
"maxPrice": 4,
"maxVolume": 4,
"minTrade": 0.00001000,
"online": 0,
"pairCode": "BTC_USDT",
"quoteIncrement": 0,
"quotePrecision": 0,
"quoteSymbol": "USDT",
"sort": 1,
"tickerFeesRate": "0"
}, {
"baseIncrement": 0,
"baseSymbol": "ETH",
"makerFeesRate": "0",
"maxPrice": 4,
"maxVolume": 4,
"minTrade": 0.01000000,
"online": 0,
"pairCode": "ETH_USDT",
"quoteIncrement": 0,
"quotePrecision": 0,
"quoteSymbol": "USDT",
"sort": 2,
"tickerFeesRate": "0"
},...]Return value description
| Return field | Field description |
|---|---|
| baseIncrement | The minimum changing amount of transactions |
| baseSymbol | Traded currency |
| makerFeesRate | maker rate |
| maxPrice | Trading price decimals places number |
| maxVolume | Minimum decimals places of trading amount |
| minTrade | Minimum order amount |
| online | Online or not |
| pairCode | the combination between Base and quote BTC_USD |
| quoteIncrement | Minimum trading unit |
| quotePrecision | Unit accuracy of pricing currency quantity |
| quoteSymbol | Pricing currency |
| sort | Sort value |
| tickerFeesRate | ticker rate |
Request
# Request
GET /openapi/exchange/public/{pairCode}/orderBookResponse
# Response
{
"asks":[
[
"10463.3399",
"0.0025"
],
...
],
"bids":[
[
"7300.2456",
"0.0022"
],
...
]
}Return value description
| Return field | Field description |
|---|---|
| asks | Asker's depth |
| bids | Bider's depth |
Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | Yes | Trading pairs,example:LTC_BTC |
Snapshot information of last trading price,bid 1 price, ask 1 price, 24h higest price, 24h lowest price, 24h open price and 24h trading volume. Request
# Request
GET /openapi/exchange/public/{pairCode}/tickerResponse
# Response
{
"buy": "9512.70000000",
"change24": "19.60000000",
"changePercentage": "",
"changeRate24": "0.0020000000000000",
"close": "",
"createOn": 1564404929000,
"high": "9729.50000000",
"high24": "9729.50000000",
"last": "9525.20000000",
"low": "9171.80000000",
"low24": "9171.80000000",
"open": "9505.60000000",
"pairCode": "BTC_USDT",
"quoteVolume": "39140860.67498000",
"sell": "9515.60000000",
"volume": "4101.34040000"
}Return value description
| Return field | Field description |
|---|---|
| buy | last bid price |
| change24 | 24h change |
| changePercentage | change percentage |
| changeRate24 | 24h change rate |
| close | 24h close |
| createOn | create time |
| high | Highest trading price |
| high24 | 24h highest trading price |
| last | last trading price |
| low | Lowest trading price |
| low24 | 24h lowest trading price |
| open | 24h open |
| pairCode | trading pairs information |
| quoteVolume | trade volume of pricing currency |
| sell | last ask price |
| volume | trade volume of benchmark currency |
Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | Yes | trading pair,example:ETH_BTC |
Request
# Request
GET /openapi/exchange/public/{pairCode}/fillsResponse
# Response
{
["9581.4","0.091084","sell",1590897543720]
...
}Return value description (in order)
| Return field | Field description |
|---|---|
| 9581.4 | price |
| 0.091084 | amount |
| sell | buy/sell |
| 1590897543720 | timestamp |
Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | 是 | 币对如btc_usdt |
Request
# Request
GET /openapi/exchange/public/{pairCode}/candles?interval=1min&start=start_time&end=end_timeResponse
# Response
{
[ 1415398768, 0.32, 0.42, 0.36, 0.41, 12.3 ]
...
}Return value description (in order)
| Return field | Field description |
|---|---|
| 1415398768 | K line start timestamp |
| 0.32 | Lowest price |
| 0.42 | Highest price |
| 0.36 | Open price(the first transaction) |
| 0.41 | Close price(the last transaction ) |
| 12.3 | Trade volume (calculated with traded currency ) |
| Request parameters |
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | Yes | Trading pair example:btc_usdt |
| interval | String | Yes | K line cycle type, such as1min/1hour/day/week/month |
| start | String | No | Start time based on ISO 8601 standard |
| end | String | No | End time based on ISO 8601 standard |
The interface to get the time of the API server.
Request
# Request
GET /openapi/exchange/public/timeResponse
# Reponse
{
"epoch": "1524801032.573"
"iso": "2015-01-07T23:47:25.201Z",
"timestamp": 1524801032573
}Return value description
| Return field | Field description |
|---|---|
| epoch | Server time expressed in seconds as a timestamp |
| iso | Server time for ISO 8061 standard time string representation |
| timestamp | Server time expressed in milliseconds as a timestamp |
1. Get account information Get the balance list of crypto account, check the balance of each currency and their freeze and availability status.
Request
# Request
GET /openapi/exchange/assets
Response
# Response
[
{
"brokerId":10000,
"symbol":"BTC",
"available":"1",
"hold":"0",
"baseBTC":1,
"withdrawLimit":"1",
},
...
]
Return value description
| Return field | Field description |
|---|---|
| brokerId | broker id |
| symbol | currency |
| available | balance |
| hold | frozen |
| baseBTC | convert to BTC |
| withdrawLimit | Withdraw amount limit |
Provide limit orders and market orders. Request
# Request
POST /openapi/exchange/{pairCode}/orders
Response
# Response
10000Return value description Order id
Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | Yes | trading pair,example:BTC_USDT |
| side | String | Yes | bid is buy,ask is sell |
| systemOrderType | String | Yes | limit is limit order,market is market price |
| volume | String | No | Transmit parameters when there is limit order or ask order with market price, representing the traded currency amount. |
| price | String | No | Transmit parameters when there is limit order , representing the trading price. |
| quoteVolume | String | No | Transmit parameters when there is bid order with market price , representing the pricing currency amount. |
Cancel all unfilled orders of the target trading pair, 50 cancellations at most. The interface has no return value because the cancellations are conducted asynchronously. Request
# Request
DELETE /openapi/exchange/{pairCode}/cancel-all
Response
# Response
{ ...}Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | Yes | trading pair, example:BTC_USDT |
| Currently canceling 200 pending orders in batches. |
The specified order is cancelled according to the order id. The interface has no return value because the cancellations are conducted asynchronously. Request
# Request
DELETE /openapi/exchange/{pairCode}/orders/{id}Response
# Response
{...}Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| code | String | Yes | trading pair,example:BTC_USDT |
| orderId | String | Yes | The ID of the unfilled order that needs to be canceled |
Query orders by order status.
Request
# Request
GET /openapi/exchange/ordersResponse
# Response
[
[
"id": 1524801032573,
"pairCode": "BTC_USDT",
"userId": 1001,
"brokerId": 10000,
"side": "buy",
"entrustPrice": "1",
"amount": "1",
"dealAmount": "1",
"quoteAmount": "1",
"dealQuoteAmount": "1",
"systemOrderType": "limit",
"status": 0,
"sourceInfo": "web",
"createOn": 1524801032573,
"updateOn": 1524801032573,
"symbol": "BTC",
"trunOver": "1",
"notStrike": "0",
"averagePrice": "1",
"openAmount": "1"
],
...
]Return value description
| Return field | Field description |
|---|---|
| id | Order id |
| pairCode | the combination between Base and quote BTC_USD |
| userId | User id |
| brokerId | Broker id |
| side | Side bid,ask |
| entrustPrice | order price |
| amount | order amount |
| dealAmount | trading amount |
| quoteAmount | benchmark currency amount only used in bid order with market price |
| dealQuoteAmount | trading amount of benchmark currency |
| systemOrderType | 10:limit price 11:market price |
| status | 0:unfilled 1:partially filled 2:filled 3:cancelling -1:canceled |
| sourceInfo | order source web,api,Ios,android |
| createOn | create time |
| updateOn | modify time |
| symbol | currency |
| trunOver | trade volume dealQuoteAmount * dealAmount |
| notStrike | unfilled amount |
| averagePrice | average trading price |
| openAmount | order amount |
Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | No | Trading pair,example:BTC_USDT |
| startDate | Long | No | Start time milliseconds |
| endDate | Long | No | End time milliseconds |
| price | BigDecimal | No | Order price |
| amount | BigDecimal | No | Order amount |
| systemOrderType | Integer | No | 10:limit price 11:market price |
| source | String | No | Trading pair,example:LTC_BTCweb,api,Ios,android |
| page | Integer | No | Page number |
| pageSize | Integer | No | Terms number per page |
Get the bills of crypto-crypto trading. Request
# Request
GET /openapi/exchange/billsResponse
# Response
{
"bills": [{
"afterAssets": 97.0000000000000000,
"amount": -2.00000000,
"assets": 97,
"beforeAssets": 99.0000000000000000,
"brokerId": 10000,
"createOn": 1565590577000,
"fee": 0E-8,
"id": 0,
"makerTaker": "maker",
"pairCode": "LTC_USDT",
"price": 400.0000000000000000,
"referId": 51815389100048,
"symbol": "LTC",
"tradeNo": "",
"type": 8,
"updateOn": 0,
"userId": 0
}, {
"afterAssets": 899.1000000000000000,
"amount": 800.00000000,
"assets": 899.1,
"beforeAssets": 99.9000000000000000,
"brokerId": 10000,
"createOn": 1565590577000,
"fee": -0.80000000,
"id": 0,
"makerTaker": "maker",
"pairCode": "LTC_USDT",
"price": 400.0000000000000000,
"referId": 51815389100048,
"symbol": "USDT",
"tradeNo": "",
"type": 7,
"updateOn": 0,
"userId": 0
}],
"paginate": {
"page": 1,
"pageSize": 2,
"total": 4
}
}Return value description
| Return field | Field description |
|---|---|
| afterAssets | Asset after change |
| amount | Change amount |
| beforeAssets | Asset before change |
| brokerId | Broker id |
| createOn | Create time |
| fee | Fee |
| makerTaker | Maker taker |
| pairCode | Pair |
| price | Price |
| referId | Referral id |
| symbol | Coin |
| tradeNo | Transaction number There is a unique transaction number when transferring asset. |
| type | Bill type |
| updateOn | Update time |
| userId | User id |
Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| page | Integer | Yes | current page number |
| pageSize | Integer | Yes | terms number of per page |
| startDate | Long | No | Start timestamp millisecond |
| endDate | Long | No | End timestamp millisecond |
| symbol | String | No | Coin, such as BTC |
| type | Integer | No | RECHARGE(1),WITHDRAW(2),BUY(7),SELL(8),TRANSFER_IN(43),TRANSFER_OUT(44),SERVICE_FEE_BUY(88),SERVICE_FEE_SELL(89) |
| isHistory | Boolean | No | History data or not |
Get trading history of the requested trading pairs,can be queried with pagination . Request
# Request
GET /openapi/exchange/{pairCode}/fulfillmentResponse
# Response
[
[
"id": 1524801032573,
"pairCode": "BTC_USDT",
"userId": 1001,
"brokerId": 10000,
"side": "buy",
"entrustPrice": "1",
"amount": "1",
"dealAmount": "1",
"quoteAmount": "1",
"dealQuoteAmount": "1",
"systemOrderType": "limit",
"status": 0,
"sourceInfo": "web",
"createOn": 1524801032573,
"updateOn": 1524801032573,
"symbol": "BTC",
"trunOver": "1",
"notStrike": "0",
"averagePrice": "1",
"openAmount": "1"
],
...
]Return value description
| Return field | Field description |
|---|---|
| id | order id |
| pairCode | the combination between Base and quote BTC_USD |
| userId | user id |
| brokerId | broker id |
| side | side bid, ask |
| entrustPrice | order price |
| amount | order amount |
| dealAmount | trading amount |
| quoteAmount | benchmark currency amount , only used in bid orders with market price |
| dealQuoteAmount | trading amount of benchmark currency |
| systemOrderType | 10:limit price 11:market price |
| status | 0:unfilled 1:partially filled 2:filled 3:cancelling -1:canceled |
| sourceInfo | order source web,api,Ios,android |
| createOn | create time |
| updateOn | modify time |
| symbol | currency |
| trunOver | trade volume dealQuoteAmount * dealAmount |
| notStrike | unfilled amount |
| averagePrice | average trading price |
| openAmount | order amount |
Request parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| pairCode | String | Yes | trading pair,example:LTC_BTC |
| startDate | Long | No | Start time,example:1524801032573 |
| endDate | Long | No | end time,example:1524801032573 |
| systemOrderType | Integer | No | 10:limit price 11:market price |
| price | BigDecimal | No | Price |
| amount | BigDecimal | No | Amount |
| source | String | No | Trading pair,example:LTC_BTCweb,api,Ios,android |
| isHistory | Boolean | No | Whether to check historical data, the data of one week ago is historical data, default false |
| page | Integer | No | Page number |
| pageSize | Integer | No | terms number of per page |
Description
- Trade side represents the maker's side in each filled orders, and the maker refers to the trader who places the order on the order depth chart ,that is, the passive trading side.
- Buy represents a dropping market, because the maker places the bid order, and his order is filled, resulting in price falls; On the contrary, sell represents the market going up, because the maker places the ask order, and the order is filled, indicating the rise of price.