OpenOcean CEX API

Instruction of OpenOcean CEX API for Centralized users

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:

https://open-api.openocean.finance/exchange/spot/open/v1/createOrder?
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2017-05-11T15%3A19%3A30
&order-id=1234567890
&Signature=calculated value

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:

https://open-api.openocean.finance/exchange/spot/open/v1/createOrder?
AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2017-05-11T15:19:30
&order-id=1234567890

The request Method (GET or POST, WebSocket use GET), append line break "\n"

GET \n

The host with lower case, append line break "\n"

open-api.openocean.finance \n

The path, append line break "\n"

/exchange/spot/open/v1/createOrder \n

The parameters are URL encoded, and ordered based on ASCII

For example below is the original parameters:

  AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx  
  order-id=1234567890  
  SignatureMethod=HmacSHA256  
  SignatureVersion=2  
  Timestamp=2017-05-11T15%3A19%3A30

Then above parameter should be ordered like below:

  AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx  
  SignatureMethod=HmacSHA256  
  SignatureVersion=2  
  Timestamp=2017-05-11T15%3A19%3A30  
  order-id=1234567890

Use char "&" to concatenate all parameters

  AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
  &SignatureMethod=HmacSHA256
  &SignatureVersion=2
  &Timestamp=2017-05-11T15%3A19%3A30&order-id=1234567890

Assemble the pre-signed text

  GET\n  open-api.openocean.finance\n  
  /exchange/spot/open/v1/createOrder\n  
  AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
  &SignatureMethod=HmacSHA256&SignatureVersion=2
  &Timestamp=2017-05-11T15%3A19%3A30
  &order-id=1234567890

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.

  b0xxxxxx-c6xxxxxx-94xxxxxx-dxxxx

Encode the hash code with base-64 to generate the signature.

  4F65x5A2bLyMWVQj3Aqp+B4w+ivaA7n5Oi2SuYtCJ9o=

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:

  https://open-api.openocean.finance/exchange/spot/open/v1/createOrder?
  AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
  &order-id=1234567890
  &SignatureMethod=HmacSHA256
  &SignatureVersion=2
  &Timestamp=2017-05-11T15%3A19%3A30
  &Signature=4F65x5A2bLyMWVQj3Aqp%2BB4w%2BivaA7n5Oi2SuYtCJ9o%3D

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

{
    "exchangeCode": "binance", 
    "pairCode": "BNB/BUSD", 
    "direction": "0", 
    "orderType": "1", 
    "price": "10", 
    "volume": "10"
}
  • Response:

{
    "code": 0, 
    "msg": "Correct response", 
    "ts": 1608715168529, 
    "data": null, 
    "error": false
}

2. Cancel order

Request:

  • Method: POST

  • URL:/exchange/spot/open/v1/cancelOrder

  • Parameter:

Parameter Name

Type

Example

Description

localOrderId

String

1

local order id

{
    "localOrderId": "1"
}
  • Response:

{
    "code": 0, 
    "msg": "Correct response", 
    "ts": 1608715168529, 
    "data": null, 
    "error": false
}

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

{
    "code": 0, 
    "msg": "Correct response", 
    "ts": 1608715168529, 
    "data": [
        {
            "coinType": "BNB", 
            "available": 390.7, 
            "forzen": 0
        }
    ], 
    "error": false
}

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

{
    "code": 0, 
    "msg": "Correct response", 
    "ts": 1608715168529, 
    "data": {
        "pageInfo": {
            "total": 2, 
            "page": 1
        }, 
        "result": [
            {
                "localOrderId": "1774y3812418", 
                "exchangeSymbol": "Binance", 
                "pairCode": "BAKE/BNB", 
                "orderType": "Limit", 
                "direction": "Buy", 
                "orderStatus": "Canceled", 
                "orderPrice": "0.000357", 
                "orderVolume": "350.000000", 
                "tradePrice": "0.000000", 
                ja"tradeVolume": "0.000000", 
                "tradeAmount": "0.000000", 
                "fee": "0.000000", 
                "orderTime": 1611755902000
            }
        ]
    }, 
    "error": false
}

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

{
    "code": 0, 
    "msg": "Correct response", 
    "ts": 1608715168529, 
    "data": {
        "pageInfo": {
            "total": 2, 
            "page": 1
        }, 
        "result": [
            {
                "localOrderId": "1774y3812418", 
                "exchangeSymbol": "Binance", 
                "pairCode": "BAKE/BNB", 
                "orderType": "Limit", 
                "direction": "Buy", 
                "orderStatus": "Canceled", 
                "orderPrice": "0.000357", 
                "orderVolume": "350.000000", 
                "tradePrice": "0.000000", 
                "tradeVolume": "0.000000", 
                "tradeAmount": "0.000000", 
                "fee": "0.000000", 
                "orderTime": 1611755902000
            }
        ]
    }, 
    "error": false
}

Last updated