CEX API 2.0

1. Preparation

Before you use API, you need to login the website to create API Key with proper permissions.
Please remember below information after creation:
  • AccessKey It is used in API request
  • SecretKey It is used to generate the signature (only visible once after creation)

2. Authentication instruction

The API request may be tampered during internet, therefore all private API must be signed by your API Key (Secrete Key).
Each API Key has permission property, please check the API permission, and make sure your API key has proper permission.
A valid request consists of below parts:
  • API Path: open-api.openocean.finance/exchange/spot/open/v1/createOrder
  • API Access Key: The 'AccessKey' in your API Key
  • Signature Method: The Hash method that is used to sign, it uses HmacSHA256
  • Signature Version: The version for the signature protocol, it uses 2
  • Timestamp: The UTC time when the request is sent, e.g. 2017-05-11T16:22:06. It is useful to prevent the request to be intercepted by third-party.
  • Parameters: Each API Method has a group of parameters, you can refer to detailed document for each of them.
    • For GET request, all the parameters must be signed.
    • For POST request, the parameters needn't be signed and they should be put in request body.
  • Signature: The value after signed, it is guarantee the signature is valid and the request is not be tempered.
example:
1
https://open-api.openocean.finance/exchange/spot/open/v1/createOrder?
2
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
3
&SignatureMethod=HmacSHA256
4
&SignatureVersion=2
5
&Timestamp=2017-05-11T15%3A19%3A30
6
&order-id=1234567890
7
&Signature=calculated value
Copied!

3. Signature method

The signature may be different if the request text is different, therefore the request should be normalized before signing.
Below signing steps take the order query as an example:
1
https://open-api.openocean.finance/exchange/spot/open/v1/createOrder?
2
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
3
&SignatureMethod=HmacSHA256
4
&SignatureVersion=2
5
&Timestamp=2017-05-11T15:19:30
6
&order-id=1234567890
Copied!
The request Method (GET or POST, WebSocket use GET), append line break "\n"
1
GET \n
Copied!
The host with lower case, append line break "\n"
1
open-api.openocean.finance \n
Copied!
The path, append line break "\n"
1
/exchange/spot/open/v1/createOrder \n
Copied!
The parameters are URL encoded, and ordered based on ASCII
For example below is the original parameters:
1
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
2
order-id=1234567890
3
SignatureMethod=HmacSHA256
4
SignatureVersion=2
5
Timestamp=2017-05-11T15%3A19%3A30
Copied!
Then above parameter should be ordered like below:
1
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
2
SignatureMethod=HmacSHA256
3
SignatureVersion=2
4
Timestamp=2017-05-11T15%3A19%3A30
5
order-id=1234567890
Copied!
Use char "&" to concatenate all parameters
1
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
2
&SignatureMethod=HmacSHA256
3
&SignatureVersion=2
4
&Timestamp=2017-05-11T15%3A19%3A30&order-id=1234567890
Copied!
Assemble the pre-signed text
1
GET\n open-api.openocean.finance\n
2
/exchange/spot/open/v1/createOrder\n
3
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
4
&SignatureMethod=HmacSHA256&SignatureVersion=2
5
&Timestamp=2017-05-11T15%3A19%3A30
6
&order-id=1234567890
Copied!
Use the pre-signed text and your Secret Key to generate a signature
Use the pre-signed text in step 6 and your API Secret Key to generate hash code by HmacSHA256 hash function.
1
b0xxxxxx-c6xxxxxx-94xxxxxx-dxxxx
Copied!
Encode the hash code with base-64 to generate the signature.
1
4F65x5A2bLyMWVQj3Aqp+B4w+ivaA7n5Oi2SuYtCJ9o=
Copied!
Put the signature into request URL
For Rest interface:
  • Put all the parameters in the URL
  • Encode signature by URL encoding and append in the URL with parameter name "Signature".
Finally, the request sent to API should be:
1
https://open-api.openocean.finance/exchange/spot/open/v1/createOrder?
2
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
3
&order-id=1234567890
4
&SignatureMethod=HmacSHA256
5
&SignatureVersion=2
6
&Timestamp=2017-05-11T15%3A19%3A30
7
&Signature=4F65x5A2bLyMWVQj3Aqp%2BB4w%2BivaA7n5Oi2SuYtCJ9o%3D
Copied!

4. API docs

1. Create order

Request:

  • Method: POST
  • URL:/exchange/spot/open/v1/createOrder
  • Parameter:
Parameter Name
Type
Example
Description
exchangeCode
String
binance
exchange code
pairCode
String
BNB/BUSD
direction
String
0
0:buy 1:sell
orderType
String
1
1:market 2:limit
price
String
10
price
volume
String
10
1
{
2
"exchangeCode": "binance",
3
"pairCode": "BNB/BUSD",
4
"direction": "0",
5
"orderType": "1",
6
"price": "10",
7
"volume": "10"
8
}
Copied!
  • Response:
1
{
2
"code": 0,
3
"msg": "Correct response",
4
"ts": 1608715168529,
5
"data": null,
6
"error": false
7
}
Copied!

2. Cancel order

Request:
  • Method: POST
  • URL:/exchange/spot/open/v1/cancelOrder
  • Parameter:
Parameter Name
Type
Example
Description
localOrderId
String
1
local order id
1
{
2
"localOrderId": "1"
3
}
Copied!
  • Response:
1
{
2
"code": 0,
3
"msg": "Correct response",
4
"ts": 1608715168529,
5
"data": null,
6
"error": false
7
}
Copied!

3. List funds

Request:

  • Method: GET
  • URL:/exchange/spot/open/v1/listFunds
  • Parameter:
Parameter Name
Type
Example
Description
pairCode
String
BNB/BUSD
pair code
Response:
Field Name
Type
Example
Description
coinType
String
BNB
coin type
available
String
390.70
frozen
String
0
1
{
2
"code": 0,
3
"msg": "Correct response",
4
"ts": 1608715168529,
5
"data": [
6
{
7
"coinType": "BNB",
8
"available": 390.7,
9
"forzen": 0
10
}
11
],
12
"error": false
13
}
Copied!

4. List current order

Request:
  • Method: GET
  • URL:/exchange/spot/open/v1/listCurrentOrder
  • Parameter:
Parameter Name
Type
Example
Description
page
Number
1
pageNum
length
Number
10
pageSize
Response:
Field Name
Type
Example
Description
localOrderId
String
1774y3812418
local order id
exchangeSymbol
String
Binance
exchange symbol
pairCode
String
BNB/USDT
pair code
direction
String
Buy
orderType
String
Limit
orderStatus
String
Canceled
NotFilled、PartFilled
orderPrice
String
0.000357
order price
orderVolume
String
350.000000
order volume
tradePrice
String
0.000000
trade price
tradeVolume
String
0.000000
trade volume
tradeAmount
String
0.000000
trade amount
fee
String
0.000000
fee
orderTime
String
1611755902000
order time
1
{
2
"code": 0,
3
"msg": "Correct response",
4
"ts": 1608715168529,
5
"data": {
6
"pageInfo": {
7
"total": 2,
8
"page": 1
9
},
10
"result": [
11
{
12
"localOrderId": "1774y3812418",
13
"exchangeSymbol": "Binance",
14
"pairCode": "BAKE/BNB",
15
"orderType": "Limit",
16
"direction": "Buy",
17
"orderStatus": "Canceled",
18
"orderPrice": "0.000357",
19
"orderVolume": "350.000000",
20
"tradePrice": "0.000000",
21
"tradeVolume": "0.000000",
22
"tradeAmount": "0.000000",
23
"fee": "0.000000",
24
"orderTime": 1611755902000
25
}
26
]
27
},
28
"error": false
29
}
Copied!

5. List history order

Request:
  • Method: GET
  • URL:/exchange/spot/open/v1/listHistoryOrder
  • Parameter:
Parameter Name
Type
Example
Description
page
Number
1
pageNum
length
Number
10
pageSize
pairCode
String
BNB/USDT
pair code
startTime
String
1611755902000
timestamp
endTime
String
1611755902000
timestamp
  • Response
1
{
2
"code": 0,
3
"msg": "Correct response",
4
"ts": 1608715168529,
5
"data": {
6
"pageInfo": {
7
"total": 2,
8
"page": 1
9
},
10
"result": [
11
{
12
"localOrderId": "1774y3812418",
13
"exchangeSymbol": "Binance",
14
"pairCode": "BAKE/BNB",
15
"orderType": "Limit",
16
"direction": "Buy",
17
"orderStatus": "Canceled",
18
"orderPrice": "0.000357",
19
"orderVolume": "350.000000",
20
"tradePrice": "0.000000",
21
"tradeVolume": "0.000000",
22
"tradeAmount": "0.000000",
23
"fee": "0.000000",
24
"orderTime": 1611755902000
25
}
26
]
27
},
28
"error": false
29
}
Copied!
Last modified 27d ago