NAV Navbar
python cURL

Introduction

Welcome to the OceanEx trading API! You can use our API to access OceanEx endpoints, which can get information and place orders on various markets. Some API supports both get and post method, but we strongly recommend only to use post method for all API requests.

Currently, we only have language bindings in Python. Other languages like Shell, Ruby, and JavaScript are coming soon. You can view code examples in the dark area to the right.

Spot Trading

Public REST API

The base URL for all REST API is: https://api.oceanex.cc/v1.

base_url = "https://api.oceanex.cc/v1"
API endpoint:
https://api.oceanex.cc/v1

Markets post

This API gets a list of available markets for trading. (get method supported)

import requests

method_url = base_url + "/markets"
r = requests.post(method_url)
curl -X POST \
  https://api.oceanex.cc/v1/markets

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": [
    {"id": "btcusdt", "name": "BTC/USDT"},
    {"id": "ethusdt", "name": "ETH/USDT"},
    {"id": "vetusdt", "name": "VET/USDT"},
    {"id": "ethbtc", "name": "ETH/BTC"},
    {"id": "vetbtc", "name": "VET/BTC"},
    {"id": "veteth", "name": "VET/ETH"},
    {"id": "vthovet", "name": "VTHO/VET"},
    {"id": "shavet", "name": "SHA/VET"},
    {"id": "shabtc", "name": "SHA/BTC"}
  ]
}

Rate limit: 3000 req/min

Ticker post

This API gets ticker of specific market. The snapshot includes the last trade (tick), best bid/ask and volume. (get method supported)

Parameters:

Name Location Description Required Schema
market path The market you want information about. You can find the list of valid markets by calling the /markets endpoint. Yes string
import requests

market = "veteth"
method_url = base_url + "/tickers/{}".format(str(market))
r = requests.post(method_url, timeout=5)
curl -X POST \
  https://api.oceanex.cc/v1/tickers/veteth

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": {
    "at": 1548123813,
    "ticker": {
      "buy": "0.0000353",
      "sell": "0.00003532",
      "low": "0.00003426",
      "high": "0.00003572",
      "last": "0.00003531",
      "vol": "25430185.0"
    }
  }
}

Rate limit: 3000 req/min

Multiple Tickers post

This API gets tickers of a list of markets. The snapshot includes the last trade (tick), best bid/ask and volume. (get method supported)

Parameters:

Name Location Description Required Schema
markets query A dictionary of markets you want information about. Yes a dictionary
import requests

method_url = base_url + "/tickers_multi"
markets = ["veteth", "ethusdt"]
data = {
  "markets[]": markets
}
r = requests.post(method_url, data=data)
curl -X POST -g \
  'https://api.oceanex.cc/v1/tickers_multi?markets[]=veteth&markets[]=ethusdt'

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": [
    {
      "at": 1548123910,
      "market": "veteth",
      "ticker": {
        "buy": "0.00003524",
        "sell": "0.00003526",
        "low": "0.00003426",
        "high": "0.00003572",
        "last": "0.00003526",
        "vol": "25421706.0"
      }
    },
    {
      "at": 1548123910,
      "market": "ethusdt",
      "ticker": {
        "buy": "116.28",
        "sell": "116.92",
        "low": "113.94",
        "high": "117.74",
        "last": "116.63",
        "vol": "73.80781"
      }
    }
  ]
}

All Tickers post

This API gets tickers of all the markets. This snapshot include the last trade (tick), best bid/ask, volume and etc.

import requests

method_url = base_url + "/tickers"
r = requests.post(method_url)
curl -X POST 'https://api.oceanex.cc/v1/tickers'

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": {
    {
      "vetusdt": {
        "name":"VET/USDT",
        "display_name":"VET/USDT",
        "base_unit":"vet",
        "quote_unit":"usdt",
        "position":130,
        "low":"0.005299",
        "high":"0.005999",
        "first":"0.005851",
        "last":"0.005682",
        "open":"0.005845",
        "volume":"1650819818.7",
        "sell":"0.005697",
        "buy":"0.005668",
        "at":1563209046,
        "h24_trend":"-2.888395146"
      }
    },
    {
      "ocevet": {
        "name":"OCE/VET",
        "display_name":"OCE/VET",
        "base_unit":"oce",
        "quote_unit":"vet",
        "position":0,
        "low":"0.8599",
        "high":"0.8821",
        "first":"0.8791",
        "last":"0.8755",
        "open":"0.8788",
        "volume":"102124237.0",
        "sell":"0.8778",
        "buy":"0.8755",
        "at":1563209046,
        "h24_trend":"-0.409509726"
      }
    },
  }
}

Rate limit: 3000 req/min

Order Book post

This API gets the order book of a specified market. Both asks and bids are sorted from highest price to lowest. (get method supported)

Parameters:

Name Location Description Required Schema
market query The market you want information about. You can find the list of valid markets by calling the /markets endpoint. Yes string
limit query Limit the number of returned price levels. Default to 300. No integer
import requests

market = "veteth"
limit = 5
method_url = base_url + "/order_book"
data = {
    "market": market,
    "limit": limit
}    
r = requests.post(method_url, data=data)
curl -X POST \
  'https://api.oceanex.cc/v1/order_book?market=veteth&limit=5'

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": {
    "timestamp": 1548123910,
    "asks": [
      ["0.8", "879.0"],
      ["0.1", "100.0"],
      ["0.091", "2548.0"],
      ["0.08", "500.0"]
    ],
    "bids": [
      ["0.00003537", "217.0"],
      ["0.0000353", "248.0"],
      ["0.00003525", "48643.0"],
      ["0.00003524", "246.0"]
    ]
  }
}

Rate limit: 3000 req/min

Multiple Order Books post

This API gets the order books of a list of specified markets. Both asks and bids are sorted from highest price to lowest. (get method supported)

Parameters:

Name Location Description Required Schema
markets query A list of markets you want information about. Yes a list of string
limit query Limit the number of returned price levels. Apply to all markets. Default to 300. No integer
import requests

method_url = base_url + "/order_book/multi"
markets = ["veteth", "ethusdt"]
limit = 5
data = {
  "markets[]": markets,
  "limit": limit  
}
r = requests.post(method_url, data=data)
curl -X POST -g  \
 'https://api.oceanex.cc/v1/order_book/multi?markets[]=vetusdt&markets[]=ethusdt&limit=1'

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": [
    {
      "market": "veteth",
      "timestamp": 1539819839,
      "asks": [
        ["0.8", "879.0"],
        ["0.1", "100.0"],
        ["0.091", "2548.0"],
        ["0.08", "500.0"]
      ],
      "bids": [
        ["0.00003537", "217.0"],
        ["0.0000353", "248.0"],
        ["0.00003525", "48643.0"],
        ["0.00003524", "246.0"]
      ]
    },
    {
      "market": "ethusdt",
      "timestamp": 1539819839,
      "asks": [
        ["127.79", "0.56954"],
        ["124.43", "0.50626"],
        ["122.7", "0.38205"],
        ["122.26", "0.3396"]
      ],
      "bids": [
        ["116.68", "0.55"],
        ["116.57", "0.2547"],
        ["116.48", "0.3797"],
        ["116.26", "1.8537"]
      ]
    }
  ]
}

Rate limit: 3000 req/min

Trades post

This API gets recent trades on market. Each trade is included only once. Trades are sorted in reverse creation order. (get method supported)

Parameters:

Name Location Description Required Schema
market query The market you want information about. You can find the list of valid markets by calling the /markets endpoint. Yes string
limit query Limit the number of returned trades. Default to 50. No integer
start query Query start timestamp. If set only trades created after the start time will be returned No integer
end query Query end timestamp. If set only trades before the end time will be returned No interger
from query Trade id. If set, only trades created after the trade will be returned. No integer
to query Trade id. If set, only trades created before the trade will be returned. No integer
order_by query If set, returned trades will be sorted in specific order. Choose from "asc" or "desc". Default to "desc". No string
import requests

method_url = base_url + "/trades"
market = "veteth"
limit = 10
start_time = 1547451655
end_time = 1547778117
from_id = 1000
to_id = 1200000
data = {
    "market": market,
    "limit": limit,
    "start": start_time,
    "end": end_time,
    "from": from_id,
    "to": to_id
}
r = requests.post(method_url, data=data)
curl -X POST \
  'https://api.oceanex.cc/v1/trades?market=veteth&limit=1&start=1555693743&end=1556693743&from=1000&to=1200000'

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": [
    {
      "id": 1018348,
      "price": "0.00003526",
      "volume": "6953.0",
      "funds": "0.24516278",
      "market": "veteth",
      "created_at": "2019-01-18T02:21:57Z",
      "created_on": 1547778117,
      "side": null
    },
    {
      "id": 1018342,
      "price": "0.00003526",
      "volume": "6263.0",
      "funds": "0.22083338",
      "market": "veteth",
      "created_at": "2019-01-14T07:40:55Z",
      "created_on": 1547451655,
      "side": null
    }
  ]
}

Rate limit: 3000 req/min

K Line post

This API gets K-line data, including open-high-low-close info. (get method supported)

Parameters:

Name Location Description Required Schema
market query The market you want information about Yes String
limit query Limit the number of returned data points, default to 30. No Integer
period query Time period of K line, default to 1. You can choose between 1, 5, 15, 30, 60, 120, 240, 360, 720, 1440, 4320, 10080 No Integer
timestamp query An integer represents the seconds elapsed since Unix epoch. If set, only k-line data after that time will be returned No Integer
import requests
method_url = base_url + "/k"
data = {
  'market': 'btcusdt',
  'limit': 2,
  'period': 5,
  'timestamp': 1559232000,
}
r = requests.post(method_url, data=data)
curl -X POST \
 'https://api.oceanex.cc/v1/k?market=btcusdt&limit=2&period=5&timestamp=1559232000'

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": [
    [1559232000,8889.22,9028.52,8889.22,9028.52,0.3121],
    [1559232300,9052.86,9052.86,8971.44,8996.5,0.1469]
  ]
}

Rate limit: 3000 req/min

Trading Fees post

This API gets trading fees for markets. (get method supported)

import requests

method_url = base_url + "/fees/trading"
r = requests.post(method_url)
curl -X POST \
  https://api.oceanex.cc/v1/fees/trading

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": [
    {
      "market": "btcusdt",
      "ask_fee": {"type": "relative", "value": "0.001"},
      "bid_fee": {"type": "relative", "value": "0.001"}
    },
    {
      "market": "ethusdt",
      "ask_fee": {"type": "relative", "value": "0.001"},
      "bid_fee": {"type": "relative", "value": "0.001"}
    },
    {
      "market": "vetusdt",
      "ask_fee": {"type": "relative", "value": "0.0005"},
      "bid_fee": {"type": "relative", "value": "0.0005"}
    },
    {
      "market": "ethbtc",
      "ask_fee": {"type": "relative", "value": "0.001"},
      "bid_fee": {"type": "relative", "value": "0.001"}
    },
    {
      "market": "vetbtc",
      "ask_fee": {"type": "relative", "value": "0.0005"},
      "bid_fee": {"type": "relative", "value": "0.0005"}
    },
    {
      "market": "veteth",
      "ask_fee": {"type": "relative", "value": "0.0005"},
      "bid_fee": {"type": "relative", "value": "0.0005"}
    },
    {
      "market": "vthovet",
      "ask_fee": {"type": "relative", "value": "0.0005"},
      "bid_fee": {"type": "relative", "value": "0.0005"}
    },
    {
      "market": "shavet",
      "ask_fee": {"type": "relative", "value": "0.0005"},
      "bid_fee": {"type": "relative", "value": "0.0005"}
    },
    {
      "market": "shabtc",
      "ask_fee": {"type": "relative", "value": "0.001"},
      "bid_fee": {"type": "relative", "value": "0.001"}
    }
  ]
}

Rate limit: 3000 req/min

API Server Time post

This API gets the API server"s time (in seconds since Unix epoch). (get method supported)

import requests

method_url = base_url + "/timestamp"
r = requests.post(method_url)
curl -X POST \
  https://api.oceanex.cc/v1/timestamp

The above command returns JSON structured like this:

{
  "code": 0,
  "message": "Operation successful",
  "data": 1548127147
}

Rate limit: 3000 req/min

REST Authentication

Users need to provide uid, apikey_id, and user_private_key to authenticate. In addition, users need to add their IP address to the whitelist. All authenticated API will call the function construct_request_body by feeding three arguments. The first and second arguments specify the method (e.g. get or post) and the corresponding URL. The last argument includes all parameters needed for the particular API.

To generate key pairs, use the following code in terminal.

Generate an RSA private key, of size 2048, and output it to a file named key.pem:

$ openssl genrsa -out key.pem 2048

Extract the public key from the key pair:

$ openssl rsa -in key.pem -outform PEM -pubout -out public.pem
$ cat public.pem

# public key format
# -----BEGIN PUBLIC KEY-----
# MIIBI***9XNmrQIDAQAB
# -----END PUBLIC KEY-----

Upload user_public_key

a. Get public key by instructions b. Access OceanEx dashboard and head to 'Setting' page

c. Click Apikey tab. (User must pass verification to using trading API and link Google Authenticator)

d. Set lable, public key, permissions, and trusted IPs. Click Add a new key button to submit

e. After submitting, using uid and apikey_id (key Id) to send API request

Using Python

API request via python demo

import jwt # pip install PyJWT
import requests

uid = "ID6A9EAFD896"
apikey_id = "KIDF4A8334E1E"
with open("key.pem", "rb") as private_file:
  user_private_key = private_file.read()

def construct_request_body(data):
  pay_load = {
     "uid": uid,
     "apikey_id": apikey_id, #optional
     "data": data
  }

  JWT_TOKEN = jwt.encode(pay_load, user_private_key, algorithm="RS256")
  request_body = {
      "user_jwt": JWT_TOKEN
  }    
  return request_body

method_url = base_url + "/key"
data = {}
request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
print(r.text())

Using Curl Command

Generate JWT_Token using bash


set -o pipefail

header_template='{
    "typ": "JWT",
    "alg": "RS256"
}'

b64enc() { openssl enc -base64 -A | tr '+/' '-_' | tr -d '='; }
json() { jq -c . | LC_CTYPE=C tr -d '\n'; }
rs_sign() { openssl dgst -binary -sha"${1}" -sign <(printf '%s\n' "$2"); }

sign() {
        local algo payload header sig secret=$3
        algo=${1:-RS256}; algo=${algo^^}
        header=${header_template}
        payload=${2:-$payload}
        signed_content="$(json <<<"$header" | b64enc).$(json <<<"$payload" | b64enc)"
        sig=$(printf %s "$signed_content" | rs_sign "${algo#RS}" "$secret" | b64enc)
        printf '%s.%s\n' "${signed_content}" "${sig}"
}


payload='{
    "uid": "IDXXXXXXXXX",
    "data": {

    }
}'
rsa_secret=$(cat key.pem)
sign rs256 "$payload" "$rsa_secret"
#JWT_token printed

Use generated JWT_Token to send Curl command

$ curl -X POST https://api.oceanex.cc/v1/API -F user_jwt= JWT_TOKEN

Private API needs encoded JWT_Token to ensure security. Use bash commands to generate JWT_Token first. Then, send curl command with it.

Before use bash commands, ensure jq, openssl, and base64 installed

Private REST API

Scope of the Key post

This API gets the scope of your key. (get method supported)

import requests

method_url = base_url + "/key"
data = {}
request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/key?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": [
    {
      "scopes": ["query","sell/buy"],
      "apikey_id": "KIDF4A8334***",
      "created_at": "2018-01-01T00:00:00.000Z",
      "ips": ["35.237.103.8", "35.245.144.195"],
      "state": "1",
      "pub_key": "*******",
      "alias_name": "test1",
      "id": "21"
    }
  ]
}

Response Details from the data field.

Key Description Schema
scopes The scope of your key. There are three level: "query", "sell/buy", and "withdraws/deposits". string
apikey_id The id of apikey
created_at The created time of API key
state The indicator of whether the key is still enabled. 1: enabled, 0: disabled. binary
ips IPs in the whitelist.,Separated by ",". string
pub_key The public key
alias_name The alias of your key. string
id apikey ID

Rate limit: 3000 req/min

Account Info post

This API gets the information about your account. (get method supported)

import requests

method_url = base_url + "/members/me"
data = {}
request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/members/me?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "code":0,
  "message":"Operation successful",
  "data":{
    "accounts": [
      {
        "currency":"vet",
        "balance":"1967.031",
        "locked":"0.0"
      },
      {
        "currency":"btc",
        "balance":"0.0",
        "locked":"0.0"
      },
      {
        "currency":"eth",
        "balance":"0.0",
        "locked":"0.0"
      }
    ]
  }
}

Rate limit: 3000 req/min

New Order post

This API submits a new order.

Parameters:

Name Description Required Schema
market The market you want information about. You can find the list of valid markets by calling the /markets endpoint. Yes string
side Either "sell" or "buy". Yes string
volume The amount user want to sell or buy. Yes string/float
price Price for each unit. Price is required for "limit" order only. No need for "market" order. Yes/No string/float
ord_type Default "limit". Supported "limit", "market", "stop_limit" order. "stop_market" will be available later No string
stop_price Used by "stop_limit order" as trigger requirement. Required if "ord_type" is "stop_limit" Yes/No string/float
trigger_condition Accepted value: "gte" (Greater or equal), "lte" (Less or equal). Required if "ord_type" is "stop" order Yes/No string
import requests

method_url = base_url + "/orders"
#eg: Limit Order
data = {
    "market": "veteth",
    "side": "buy",
    "volume": 0.75,
    "price": 1000,
    "ord_type": "limit"    
}
"""
#eg: Market Order
data = {
    "market": "veteth",
    "side": "buy",
    "volume": 20,
    "ord_type" : "market"
}

# eg:  Stop Limit Order
data = {
    "market": "veteth",
    "side": "buy",
    "volume": 20,
    "price": 1000,
    "ord_type": "stop_limit",
    "stop_price": 900,
    "trigger_condition": "lte"
}
"""

request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/orders?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": {
    "created_at": "2019-01-18T00:38:17Z",
    "trades_count": 0,
    "remaining_volume": "0.75",
    "price": "1000.0",
    "created_on": "1547771897",
    "side": "buy",
    "volume": "0.75",
    "state": "wait",
    "ord_type": "limit",
    "avg_price": "0.0",
    "executed_volume": "0.0",
    "id": 473791,
    "market": "veteth"
  }
}

Response Details from the data field. These fields are commonly shared accross multiple APIs involving /orders, /order/delete, /orders/clear, /orders/multi, etc. For orders, we have the following states:[wait wait_trigger cancel done cancelling]. Order in wait(for normal order only) or wait_trigger(for stop-limit order only) state means the order is placed and not yet triggered(for stop-limit order only), filled(for normal order only), cancelling(all types of orders) or cancelled(all types of orders). Order in cancel state means the order is cancelled by the end user or by system. Order in cancelling state means the order is cancelling and not yet settled. Furthermore, order in cancelling state will be removed from orderbook and thus will not be further matched. However, the already matched portion will still be granted. Order in done state means the order is fully filled.

Key Description Schema
remaining_volume The remaining volume of the order. string
trades_count How many trades of the order has been executed. integer
created_at The time when the order created. string
side Either “buy” or “sell”. string
id Order ID. integer
volume The original volume of the order. string
ord_type "limit" string
price The price the order was issued at (can be null for market orders). string
created_on The timestamp when the order created integer
avg_price The average price at which this order as been executed so far. 0 if the order has not been executed at all. string
state "wait", "wait_trigger", "cancel", "done, "cancelling" string
executed_volume How much of the order has been executed. string
market The market name the order belongs to. string

Rate limit: 1200 order/min

Market Minimum_trading_amount
btcusdt 10.0000000000000000
ethbtc 0.0010000000000000
ethusdt 10.0000000000000000
oceusdt 0.0000000000000000
ocevet 100.0000000000000000
shabtc 0.0010000000000000
shavet 100.0000000000000000
ticvet 100.0000000000000000
vetbtc 0.0010000000000000
veteth 0.0100000000000000
vetusdt 10.0000000000000000
vthovet 100.0000000000000000
vthousdt 1.0000000000000000

Multiple New Orders post

This API submits several new orders at once.

Parameters:

Name Description Required Schema
market The market you want information about. You can find the list of valid markets by calling the /markets endpoint. Yes string
orders A list of orders. Each order a dictionary which has the same entries as the API for creating a single order except without "market". Yes a list of dictionary
import requests

method_url = base_url + "/orders/multi"
orders = [{"side":"buy", "volume":.2, "price":1001},
          {"side":"sell", "volume":.2, "price":1002}]
data = {
    "market": "veteth",
    "orders": orders
}
request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/orders/multi?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": [
    {
      "created_at": "2019-01-18T00:38:18Z",
      "trades_count": 0,
      "remaining_volume": "0.2",
      "price": "1001.0",
      "created_on": "1547771898",
      "side": "buy",
      "volume": "0.2",
      "state": "wait",
      "ord_type": "limit",
      "avg_price": "0.0",
      "executed_volume": "0.0",
      "id": 473797,
      "market": "veteth"
    },
    {
      "created_at": "2019-01-18T00:38:18Z",
      "trades_count": 0,
      "remaining_volume": "0.2",
      "price": "1002.0",
      "created_on": "1547771898",
      "side": "sell",
      "volume": "0.2",
      "state": "wait",
      "ord_type": "limit",
      "avg_price": "0.0",
      "executed_volume": "0.0",
      "id": 473798,
      "market": "veteth"
    }
  ]
}

Rate limit: 1200 order/min

Order Status get

This API gets information of a list of specified order.

Parameters:

Name Description Required Schema
ids A list of unique order id. Yes a list of integer
import requests

method_url = base_url + "/orders"
data = {
    "ids": [473797, 473798]
}
request_body = construct_request_body(data)

r = requests.get(method_url, data=request_body)
curl -X GET \
  https://api.oceanex.cc/v1/orders?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": [
    {
      "created_at": "2019-01-18T00:38:18Z",
      "trades_count": 0,
      "remaining_volume": "0.2",
      "price": "1001.0",
      "created_on": "1547771898",
      "side": "buy",
      "volume": "0.2",
      "state": "wait",
      "ord_type": "limit",
      "avg_price": "0.0",
      "executed_volume": "0.0",
      "id": 473797,
      "market": "veteth"
    },
    {
      "created_at": "2019-01-18T00:38:18Z",
      "trades_count": 0,
      "remaining_volume": "0.2",
      "price": "1002.0",
      "created_on": "1547771898",
      "side": "sell",
      "volume": "0.2",
      "state": "wait",
      "ord_type": "limit",
      "avg_price": "0.0",
      "executed_volume": "0.0",
      "id": 473798,
      "market": "veteth"
    }
  ]
}

Rate limit: 3000 req/min

Order Status with Filters post

This API gets your orders, results is paginated. You are able to filter the results based on various options. (get method supported)

Parameters:

Name Description Required Schema
market The market you want information about. You can find the list of valid markets by calling the /markets endpoint. Yes string
states Filter order by a list of states. Choose from "wait", "done" or "cancel". Default to "wait". No a list of string
limit Limit the number of returned orders per page, default to 100. No integer
page Specify the page of paginated results. No integer
from Trade id. If set, only trades created after the trade (including the set id) will be returned. No integer
to Trade id. If set, only trades created before the trade (including the set id) will be returned. No integer
order_by If set, returned orders will be sorted by their ids in a specific order. Choose from "asc" or "desc". Default to "desc". No string
need_price If set, returned orders will include price. NO boolean
import requests

method_url = base_url + "/orders/filter"
data = {
    "market": "veteth",
    "states": ["cancel", "done"], # wait, done or cancel
    "limit": 3,
    "page": 1,
    "from": 50,
    "to": 51,
    "order_by": "desc",
    "need_price": "True"
}
request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/orders/filter?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": [
    {
      "num_of_orders": 0,
      "state": "cancel",
      "orders": []
    },
    {
      "state": "done",
      "num_of_orders": 2,
      "orders": [
        {
          "created_at": "2018-09-28T12:40:51.000Z",
          "trades_count": 1,
          "remaining_volume": "0.0",
          "market_id": "veteth",
          "price": "1000",
          "created_on": "1538138451",
          "side": "buy",
          "volume": "0.5",
          "state": "done",
          "ord_type": "limit",
          "market_name": "VET/ETH",
          "avg_price": "11.0",
          "executed_volume": "0.5",
          "market_display_name": "VET/ETH",
          "id": 50
        },
        {
          "created_at": "2018-09-28T12:40:52.000Z",
          "trades_count": 1,
          "remaining_volume": "0.0",
          "market_id": "veteth",
          "price": "1000",
          "created_on": "1538138452",
          "side": "sell",
          "volume": "0.5",
          "state": "done",
          "ord_type": "limit",
          "market_name": "VET/ETH",
          "avg_price": "11.0",
          "executed_volume": "0.5",
          "market_display_name": "VET/ETH",
          "id": 51
        }
      ]
    }
  ]
}

Rate limit: 3000 req/min

Cancel Order post

This API cancels an order.

Parameters:

Name Description Required Schema
id Unique order id. Yes integer
import requests

method_url = base_url + "/order/delete"
data = {
    "id": 473797
}
request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/order/delete?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": {
    "created_at": "2019-01-18T00:38:18Z",
    "trades_count": 1,
    "remaining_volume": "0.0",
    "price": "1001.0",
    "created_on": "1547771898",
    "side": "buy",
    "volume": "0.2",
    "state": "done",
    "ord_type": "limit",
    "avg_price": "1001.0",
    "executed_volume": "0.2",
    "id": 473797,
    "market": "veteth"
  }
}

Rate limit: 3000 req/min

Cancel Multiple Orders post

This API cancels a list of orders.

Parameters:

Name Description Required Schema
ids A list of unique order id. Yes a list of integer
import requests

method_url = base_url + "/order/delete/multi"
data = {
    "ids": [473797, 473798]
}
request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/order/delete/multi?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": [
    {
      "created_at": "2019-01-18T00:38:18Z",
      "trades_count": 1,
      "remaining_volume": "0.0",
      "price": "1001.0",
      "created_on": "1547771898",
      "side": "buy",
      "volume": "0.2",
      "state": "done",
      "ord_type": "limit",
      "avg_price": "1001.0",
      "executed_volume": "0.2",
      "id": 473797,
      "market": "veteth"
    },
    {
      "created_at": "2019-01-18T00:38:18Z",
      "trades_count": 0,
      "remaining_volume": "0.2",
      "price": "1002.0",
      "created_on": "1547771898",
      "side": "sell",
      "volume": "0.2",
      "state": "wait",
      "ord_type": "limit",
      "avg_price": "0.0",
      "executed_volume": "0.0",
      "id": 473798,
      "market": "veteth"
    }
  ]
}

Rate limit: 3000 req/min

Cancel All Orders post

This API cancels all orders.

Parameters:

Name Description Required Schema
side Either "buy" or "sell". If present, only sell orders (asks) or buy orders (bids) will be canncelled. No string
import requests

method_url = base_url + "/orders/clear"
data = {}
request_body = construct_request_body(data)

r = requests.post(base_url + method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/orders/clear?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
  "message": "Operation successful",
  "code": 0,
  "data": [
    {
      "created_at": "2018-10-18T00:14:33Z",
      "trades_count": 1,
      "remaining_volume": "0.12873111",
      "price": "950.47527434",
      "created_on": "1539821673",
      "side": "buy",
      "volume": "0.57765189",
      "state": "wait",
      "ord_type": "limit",
      "avg_price": "950.47527434",
      "executed_volume": "0.44892078",
      "id": 469417,
      "market": "veteth"
    },
    {
      "created_at": "2018-10-18T00:38:19Z",
      "trades_count": 1,
      "remaining_volume": "0.2",
      "price": "963.18955699",
      "created_on": "1539823099",
      "side": "buy",
      "volume": "0.94792349",
      "state": "wait",
      "ord_type": "limit",
      "avg_price": "963.18955699",
      "executed_volume": "0.74792349",
      "id": 473803,
      "market": "veteth"
    }
  ]
}

Rate limit: 3000 req/min

Contract Trading

Contract Public API

K Line

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/quote' \
  --form 'contractID=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/quote"
payload = {
'contractID': 1,
'limit': 2
}
response = requests.request("GET", endpoint, data = payload)
print(response.text.encode('utf8'))

Example Response

[
  [1592405880,9101.0,9101.0,9101.0,9101.0,0],
  [1592405940,9101.0,9101.0,9101.0,9101.0,0]
]

This API gets K-line data, response data structure as [timestamp, open_price, high_price, low_price, close_price, volume]

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/quote

Query Parameter

Key Type Description
contractID Integer currency market contract id
limit Integer/Optional Limit the number of returned data points, default to 30
period Integer/Optional Time period of K line. Optional value: [1, 5, 15, 30, 60, 120, 240, 360, 720, 1440, 4320, 10080]
timestamp Integer/Optional Seconds elapsed since Unix epoch. If set, only k-line data after that time will be returned.
end_time Integer/Optional Seconds elapsed since Unix epoch. If set, only k-line data before that time will be returned
type String/Optional The type of kline. Default: market_price. Options: [index_price, fair_price, market_price]

Ticker

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/tickers' \
  --form 'contractID=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/tickers"
payload = {
'contractID': 1,
}
response = requests.request("GET", endpoint, data = payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data":{
    "last":"9101.0",
    "open":"9101.0",
    "close":"0.0",
    "low":"9100.0",
    "high":"9130.0",
    "volume":"45.0",
    "sell":"0.0",
    "buy":"0.0",
    "index_price":"9408.215",
    "fair_basis":"0.0",
    "fair_value":"0.0",
    "quote_rate":"0.0",
    "base_rate":"0.0",
    "interest_rate":"0.0",
    "premium_index":"-0.009577518953961103175475223",
    "funding_rate":"-0.00375",
    "next_funding_at":1592438400,
    "h24_trend":"0.0",
    "at":1592417517
  }
}

Lists ticker data

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/tickers

Query Parameter

Key Type Description
contractID Integer currency market contract id

Trades

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/trades' \
  --form 'contractID=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/trades"
payload = {
'contractID': 1,
'size': 1
}
response = requests.request("GET", endpoint, data = payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data":{"num_of_resources":14,
    "trades":[
      {
        "order_id":33,
        "trade_id":14,
        "contract_id":1,
        "trade_tid":"f534b243-7591-4050-8d18-a723a941c0f9",
        "deal_price":"9101.0",
        "deal_vol":"1.0",
        "make_fee":"-0.00027303",
        "take_fee":"0.0009101",
        "way":4,
        "fluctuation":"-0.24",
        "created_at":"2020-06-16T03:27:52Z"
      }
    ]
  }
}

Lists trades data

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/trades

Query Parameter

Key Type Description
contractID Integer currency market contract id
offset Integer/Optional Page Number, defautl 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default desc

Order Book

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/depth' \
  --form 'contractID=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/depth"
payload = {
  'contractID': 1,
  'limit': 2
}
response = requests.request("GET", endpoint, data = payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data":{
    "timestamp":1592423710,
    "asks":[],
    "bids":["7500.0", "1000.0"]
  }
}

Lists order book data. Return order book data structure as [price, volume]

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/depth

Query Parameter

Key Type Description
contractID Integer currency market contract id
limit Integer/Optional Limit the number of returned price levels. Default 300
precision Integer/Optional The precision is used to get the order book

Contracts

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/contracts' \
  --form 'contractID=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/contracts"
payload = {}
response = requests.request("GET", endpoint, data = payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data":{
    "contracts":[
      {
        "contract": {
          "contract_id": 1,"index_id": 1,
          "name": "BTCUSDT(USDT)",
          "display_name": "BTCUSDT(USDT)", "contract_type": 1,
          "base_coin": "btc", "quote_coin": "usdt", "price_coin": "btc",
          "contract_size": "0.0001", "delivery_cycle": "28800.0",
          "min_leverage": "10.0", "max_leverage": "100.0", "leverage_step": "0.1",
          "price_unit": "0.01", "vol_unit": "1.0", "value_unit": "0.0001",
          "price_precision": 2, "volume_precision": 0, "value_precision": 4,
          "min_vol": "1.0", "max_vol": "300000.0",
          "liquidation_warn_ratio": "0.85", "fast_liquidation_ratio": "0.8",
          "settle_type": 1, "open_type": 3, "compensate_type": 1,
          "status": 1, "display_index": 1,
          "index_sources": {"binance": 50, "coinbase": 50},
          "created_at": "2020-06-11T18:13:34Z", "updated_at": "2020-06-11T18:13:34Z"
        },
        "risk_limit": {
          "contract_id": 1,
          "base_limit": "1000000.0", "step": "500000.0",
          "maintenance_margin": "0.005", "initial_margin": "0.01"
        },
        "fee_config": {
          "contract_id": 1,
          "maker_fee": "-0.0003", "taker_fee": "0.001", "settlement_fee": "0.0"
        },
        "plan_order_config": {
          "contract_id": 1
        }
      }
    ]
  }
}

Lists all contracts data or specify contract. If the quote_coin equals price_coin the contract is reversed contract.

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/contracts

Query Parameter

Key Type Description
contractID Integer/optional Request Contract ID

Funding Rate

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/fundingrate' \
  --form 'contractID=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/fundingrate"
payload = {
'contractID': 1
}
response = requests.request("GET", endpoint, data = payload)
print(response.text.encode('utf8'))

Example Response

{
  "code": 0,
  "message": "Operation is successful",
  "data": {
    "num_of_resources": 18,
    "funding_rate": [{
      "rate": "-0.00375",
      "contract_name": "BTCUSDT(USDT)",
      "delivery_cycle": "28800.0",
      "timestamp": 1592409600
    }, {
      "rate": "-0.00375",
      "contract_name": "BTCUSDT(USDT)",
      "delivery_cycle": "28800.0",
      "timestamp": 1592380800
    }]
  }
}

Lists funding rate data

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/fundingrate

Query Parameter

Key Type Description
contractID Integer currency market contract id
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Insurance Balance

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/insuranceBalance' \
  --form 'contractID=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/insuranceBalance"
payload = {
'contractID': 1
}
response = requests.request("GET", endpoint, data = payload)
print(response.text.encode('utf8'))

Example Response

{
  "code": 0,
  "message": "Operation is successful",
  "data": {
    "num_of_resources": 18,
    "insurance_balance": [{
      "contract_id": 1,
      "currency_id": "usdt",
      "balance": "0.000149985",
      "timestamp": 1592409600
    }, {
      "contract_id": 1,
      "currency_id": "usdt",
      "balance": "0.000149985",
      "timestamp": 1592380800
    }]
  }
}

Lists Insurance balance data

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/insuranceBalance

Query Parameter

Key Type Description
contractID Integer currency market contract id
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Contract API Authentication

Get Account JWT

  1. Log in oceanex
  2. Press F12 to open browser developer tools, and navigate to Network tab
  3. Open account page
  4. Check Network tab and find account api call.
  5. Get Bearer token in request headers.

Contract Private API

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/userLiqRecords?contractID=1' \
 --header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
 --header 'Authorization: Bearer ACCOUNT_JWT'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/userLiqRecords"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'contract_id': 1
}
response = requests.request("GET", endpoint, headers=headers, params=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data":{
    "num_of_resources": 41,
    "records": [
        {
            "order_id": 16439,
            "contract_id": 1,
            "position_id": 40,
            "account_id": 2,
            "type": 4,
            "trigger_price": "9718.377566349523",
            "order_price": "9718.377566349523",
            "mmr": "0.0",
            "subsidies": "0.0",
            "state": "done",
            "created_at": "2020-02-13T06:02:58+01:00"
        }
    ]
  }
}

Private API. Get user related liquidation

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/userLiqRecords

Query Parameter

Key Type Description
contractID Integer currency market contract id
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"
curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/orderTrades?contractID=1&orderID=1' \
 --header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
 --header 'Authorization: Bearer ACCOUNT_JWT'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/orderTrades"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'contractID': 1,
'orderID': 1
}

response = requests.request("GET", endpoint, headers=headers, params=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "num_of_resources": 1,
    "trades": [
      {
          "trade_id": 2,
          "order_id": 1,
          "trade_tid": "4f7d103c-e8d8-41a1-82dc-52647e775a34",
          "contract_id": 1,
          "deal_price": "9000.0",
          "deal_vol": "1000.0",
          "fee": "-0.45",
          "way": 1,
          "fluctuation": "0",
          "created_at": "2020-01-28T05:21:57+01:00"
      }
    ]
  }
}

Private API. Get order related trades

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/orderTrades

Query Parameter

Key Type Description
contractID Integer currency market contract id
orderID Integer order id
curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/userTrades?contractID=1' \
 --header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
 --header 'Authorization: Bearer ACCOUNT_JWT'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/userTrades"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'contractID': 1
}

response = requests.request("GET", endpoint, headers=headers, params=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "num_of_resources": 12890,
    "trades": [
      {
          "trade_id": 40926,
          "order_id": 16440,
          "trade_tid": "89669469-f944-498d-a30e-35bb22e87369",
          "contract_id": 1,
          "deal_price": "10000.0",
          "deal_vol": "1000.0",
          "fee": "-0.5",
          "way": 1,
          "fluctuation": "0",
          "created_at": "2020-02-14T18:38:52+01:00"
      }
    ]
  }
}

Private API. Get authenticated user related trades

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/userTrades

Query Parameter

Key Type Description
contractID Integer currency market contract id
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Accounts

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/accounts?coinCode=usd' \
 --header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
 --header 'Authorization: Bearer ACCOUNT_JWT'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/accounts"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'coinCode': 'usd'
}

response = requests.request("GET", endpoint, headers=headers, params=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "accounts": [
      {
        "account_id": 2,
        "coin_code": "usd",
        "available_vol": "99675.7034968120137321",
        "cash_vol": "99675.7034968120137321",
        "freeze_vol": "0.0",
        "hold_vol": "203.1499999999999999",
        "realised_vol": "-1.0",
        "earning_vol": "-1.0",
        "created_at": "2020-01-28T04:04:06+01:00",
        "updated_at": "2020-02-14T18:39:23+01:00"
      }
    ]
  }
}

Private API. Get authenticated user coin accounts

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/accounts

Query Parameter

Key Type Description
coinCode String The currency id of the account

Orders

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/userOrders?contractID=1' \
 --header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
 --header 'Authorization: Bearer ACCOUNT_JWT'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/userOrders"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'contractID': 1,
'status': 4
}

response = requests.request("GET", endpoint, headers=headers, params=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "num_of_resources": 16432,
    "orders": [
      {
        "order_id": 16441,
        "contract_id": 1,
        "contract_name": "btcusdt",
        "price": "10000.0",
        "vol": "3000.0",
        "done_avg_price": "10000.0",
        "done_vol": "1000.0",
        "open_type": 1,
        "way": 4,
        "leverage": "10.0",
        "category": 1,
        "origin": "unknown",
        "created_at": "2020-02-14T18:38:48+01:00",
        "finished_at": "2020-02-14T18:39:23.000+01:00",
        "status": 5,
        "errno": 0
      }
    ]
  }
}

Private API. Get authenticated user orders

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/userOrders

Query Parameter

Key Type Description
contractID Integer currency market contract id
status Integer Order status. submitted: 1, filling: 2, submitted+ filling: 3, completed(include cancelled): 4
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Positions

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/userPositions?status=1' \
 --header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
 --header 'Authorization: Bearer ACCOUNT_JWT'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/userPositions"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'status': 1
}

response = requests.request("GET", endpoint, headers=headers, params=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "num_of_resources": 2,
    "positions": [
      {
        "position_id": 42,
        "account_id": 2,
        "contract_id": 1,
        "hold_vol": "1000.0",
        "freeze_vol": "0.0",
        "close_vol": "0.0",
        "hold_avg_price": "10000.0",
        "close_avg_price": "0.0",
        "liquidate_price": "9048.5728592889334001",
        "im": "101.5",
        "mm": "5.0",
        "realised_profit": "0.5",
        "earnings": "0.5",
        "hold_fee": "0.0",
        "open_type": 1,
        "position_type": 1,
        "status": 1,
        "errno": 0,
        "created_at": "2020-02-14T18:38:53+01:00",
        "updated_at": "2020-02-14T18:38:53+01:00"
      }      
    ]
  }
}

Private API. Get authenticated user related positions

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/userPositions

Query Parameter

Key Type Description
contractID Integer/Optional currency market contract id
coinCode String/Optional currency code
status Integer Order status. submitted: 1, filling: 2, submitted+ filling: 3, completed(include cancelled): 4
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Adjust Margin

curl --request POST 'https://contract.oceanex.cc/api/v1/ifcontract/marginOper' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
--header 'Authorization: Bearer ACCOUNT_JWT' \
--form 'contract_id=1' \
--form 'position_id=7' \
--form 'vol=5' \
--form 'oper_type=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/marginOper"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'contract_id': '1',
'position_id': '7',
'vol': '5',
'oper_type': '1'
}

response = requests.request("POST", endpoint, headers=headers, data=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful"
}

Private API. Increase or decrease margin for a specific position

Request Endpoint: POST https://contract.oceanex.cc/api/v1/ifcontract/marginOper

Query Parameter

Key Type Description
contract_id Integer currency market contract id
position_id Integer
vol Integer The marin you want to increase or decrease
oper_type Integer 1: Increase, 2: Decrease

Cancel Order

curl --request POST 'https://contract.oceanex.cc/api/v1/ifcontract/cancelOrder' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
--header 'Authorization: Bearer ACCOUNT_JWT' \
--form 'id=1'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/cancelOrder"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'id': 9
}

response = requests.request("POST", endpoint, headers=headers, data=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful"
}

Private API. Cancel an order by id

Request Endpoint: POST https://contract.oceanex.cc/api/v1/ifcontract/cancelOrder

Query Parameter

Key Type Description
id Integer order id

Create Order

curl --request POST 'https://contract.oceanex.cc/api/v1/ifcontract/submitOrder' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
--header 'Authorization: Bearer ACCOUNT_JWT' \
--form 'contract_id=1' \
--form 'category=1' \
--form 'way=1' \
--form 'price=6900' \
--form 'vol=1000' \
--form 'leverage=10' \
--form 'position_id=6' \
--form 'origin=Web'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/submitOrder"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {
'contract_id': '1',
'category': '1',
'way': '1',
'price': '6900',
'vol': '1000',
'leverage': '10',
'position_id': '6',
'origin': 'Web'
}

response = requests.request("POST", endpoint, headers=headers, data=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "order_id": 3885,
    "contract_id": 1,
    "contract_name": "BTC/USDT",
    "price": "10200.0",
    "vol": "1000.0",
    "done_avg_price": "0",
    "done_vol": "0.0",
    "open_type": 1,
    "way": 4,
    "leverage": "10.0",
    "value": "1020.0",
    "category": 1,
    "origin": "Web",
    "created_at": "2020-02-19T01:24:20Z",
    "finished_at": null,
    "status": 1,
    "errno": 0
  }
}

Private API. Create Order

Request Endpoint: POST https://contract.oceanex.cc/api/v1/ifcontract/submitOrder

Query Parameter

Key Type Description
contractID Integer currency market contract id
category Integer limit: 1, market: 2, post_only: 7
way Integer open_long: 1, close_short: 2, close_long: 3, open_short: 4
price Integer price
vol Integer Volume
leverage Integer Position leverage
position_id Integer If the way is 2 or 3, position_id will be a required field.
origin String The source of incoming request

Fund Transfer

curl --request POST 'https://contract.oceanex.cc/api/v1/ifcontract/funds/transfer' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
--header 'Authorization: Bearer ACCOUNT_JWT' \
--form 'coinCode=usd' \
--form 'category=deposit' \
--form 'amount=2' \
--form 'nonce={{timestamp}}'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/funds/transfer"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {'coinCode': 'usd',
'category': 'deposit',
'amount': '2',
'nonce': '{{timestamp}}'}

response = requests.request("POST", endpoint, headers=headers, data=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "id": 1,
    "order_num": "contract_a78cce70-4226-44ac-b416-246d506ff167",
    "currency_id": "usd",
    "category": "withdraw",
    "state": "processing",
    "amount": "20.0",
    "created_at": 1578688239,
    "updated_at": 1578688239
  }
}

Private API. Transfer Funds

Request Endpoint: POST https://contract.oceanex.cc/api/v1/ifcontract/funds/transfer

Query Parameter

Key Type Description
coinCode String The currency id of the account
category String Direction of the transfer. peatio->contract: deposit; contract -> peatio: withdraw
amount Integer
nonce Integer The unique request id. Could use timestamp

Create Contract Account

curl --request POST 'https://contract.oceanex.cc/api/v1/ifcontract/createContractAccount' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
--header 'Authorization: Bearer ACCOUNT_JWT' \
--form 'contract_id=1' \
--form 'coinCode=usd'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/createContractAccount"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {'contract_id': '1',
'coinCode': 'usd'}

response = requests.request("POST", endpoint, headers=headers, data=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "account_id": 5,
    "coin_code": "usd",
    "available_vol": "99775.95",
    "cach_vol": "99775.2",
    "freeze_vol": "0.0",
    "hold_vol": "223.3",
    "realised_vol": "-0.75",
    "cash_vol": "-0.75",
    "earning_vol": "-0.75",
    "created_at": "2019-12-23T17:10:15Z",
    "updated_at": "2020-01-10T16:00:00Z"
  }
}

Private API. Create a contract account. Either contractID or coinCode

Request Endpoint: POST https://contract.oceanex.cc/api/v1/ifcontract/createContractAccount

Query Parameter

Key Type Description
coinCode String The currency id of the account
contractID Integer currency market contract id

Profile

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/profile' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
--header 'Authorization: Bearer ACCOUNT_JWT' \
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/profile"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {}

response = requests.request("GET", endpoint, headers=headers, params=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "sn": "SN0D7C982707",
    "email": "[email protected]"
  }
}

Private API. Get account profile

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/profile

Fund Transfer Record

curl --request GET 'https://contract.oceanex.cc/api/v1/ifcontract/funds/transfer' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' \
--header 'Authorization: Bearer ACCOUNT_JWT' \
--form 'coinCode=usd' \
--form 'category=deposit' \
--form 'status=3'
import requests

endpoint = "https://contract.oceanex.cc/api/v1/ifcontract/funds/transfer"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS',
  'Authorization': ACCOUNT_JWT
}

data = {'coinCode': 'usd',
'category': 'deposit',
'status': '3'}

response = requests.request("GET", endpoint, headers=headers, data=data)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "num_of_resources": 2,
    "account_transfers": [
      {
        "id": 3,
        "order_num": "contract_b51982d7-3afa-45c4-9927-e510734d45b0",
        "currency_id": "btc",
        "category": "deposit",
        "state": "completed",
        "amount": "950.0",
        "created_at": 1582748967,
        "updated_at": 1582748968
      }
    ]
  }
}

Private API. Get funds transfer records

Request Endpoint: GET https://contract.oceanex.cc/api/v1/ifcontract/funds/transfer

Query Parameter

Key Type Description
coinCode String The currency id of the account
category String Direction of the transfer. peatio->contract: deposit; contract -> peatio: withdraw
status Integer Status of position. holding: 1, system_in: 2, holding + system_in: 3, closed: 4
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Contract Key User API

Authentication/Get API Key

  1. Generate EC key pair
  2. Upload to contract server
openssl ecparam -genkey -name prime256v1 -noout -out private.pem
openssl ec -in private.pem -pubout -out public.pem

url="https://contract.oceanex.cc/api/v1/ifcontract/auth/apikey"
content_type='Content-Type: application/json'
x_api_key='x-api-key: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS'
authorization="Authorization: Bearer $(ACCOUNT_JWT)"

public_key=$(base64 $(PUBLIC_KEY) | tr -d '\n')
body="{ \"public_key\": \"$public_key\" }"

curl -X POST -H "$content_type" -H "$x_api_key" -H "$authorization" \
 -d "$body" $url

Generate JWT

import requests
import jwt
import time
with open("eckey.pem") as private_file:
  user_private_key = private_file.read()

def encode_params(params):
    now = int(time.time())
    expire = now + 600  # 10 minutes since hosts might be off by minutes
    payload = {'exp': expire, 'data': params}
    jwt_token = jwt.encode(payload, user_private_key, algorithm="ES256")
#    jwt_token = jwt_token.decode('utf-8')
    params = {'user_jwt': jwt_token}
    return params

data = {
'contract_id': 2
#'currency_id': 'vet'
}

payload = encode_params(data)
print(payload)

Accounts

curl --request GET 'https://contract.oceanex.cc/key_user_api/v1/ifcontract/accounts?user_jwt=user_jwt' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' 
import requests

endpoint = "https://contract.oceanex.cc/key_user_api/v1/ifcontract/accounts"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS'
}

data = {'currency_id': 'usd'}

payload = encode_params(data)
response = requests.request("GET", endpoint, headers=headers, params=payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "accounts": [
      {
        "account_id": 2,
        "coin_code": "usd",
        "available_vol": "99675.7034968120137321",
        "cash_vol": "99675.7034968120137321",
        "freeze_vol": "0.0",
        "hold_vol": "203.1499999999999999",
        "realised_vol": "-1.0",
        "earning_vol": "-1.0",
        "created_at": "2020-01-28T04:04:06+01:00",
        "updated_at": "2020-02-14T18:39:23+01:00"
      }
    ]
  }
}

Private Key API. Get accounts

Request Endpoint: GET https://contract.oceanex.cc/key_user_api/v1/ifcontract/accounts

Query Parameter

Key Type Description
currency_id String currency id

Orders

curl --request GET 'https://contract.oceanex.cc/key_user_api/v1/ifcontract/userOrders?user_jwt=user_jwt' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' 
import requests

endpoint = "https://contract.oceanex.cc/key_user_api/v1/ifcontract/userOrders"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS'
}

data = {
'contract_id': 1,
'status': 3
}

payload = encode_params(data) # {'user_jwt': USER_JWT}
response = requests.request("GET", endpoint, headers=headers, params=payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "num_of_resources": 16432,
    "orders": [
      {
        "order_id": 16441,
        "contract_id": 1,
        "contract_name": "btcusdt",
        "price": "10000.0",
        "vol": "3000.0",
        "done_avg_price": "10000.0",
        "done_vol": "1000.0",
        "open_type": 1,
        "way": 4,
        "leverage": "10.0",
        "category": 1,
        "origin": "unknown",
        "created_at": "2020-02-14T18:38:48+01:00",
        "finished_at": "2020-02-14T18:39:23.000+01:00",
        "status": 5,
        "errno": 0
      }
    ]
  }
}

Private Key API. Get user Orders

Request Endpoint: GET https://contract.oceanex.cc/key_user_api/v1/ifcontract/userOrders

Query Parameter

Key Type Description
contractID Integer currency market contract id
status Integer Status of order. submitted: 1, filling: 2, submitted+ filling: 3, completed(include cancelled): 4
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Get one Order

curl --request GET 'https://contract.oceanex.cc/key_user_api/v1/ifcontract/userOrderInfo?user_jwt=user_jwt' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' 
import requests

endpoint = "https://contract.oceanex.cc/key_user_api/v1/ifcontract/userOrderInfo"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS'
}

data = {
'contract_id': 1,
'order_id': 3
}

payload = encode_params(data) # {'user_jwt': USER_JWT}
response = requests.request("GET", endpoint, headers=headers, params=payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "order_id": 3,
    "contract_id": 1,
    "contract_name": "btcusdt(usd)",
    "price": "8500.0",
    "vol": "1000.0",
    "done_avg_price": "0",
    "done_vol": "0.0",
    "open_type": 1,
    "way": 1,
    "leverage": "10.0",
    "value": "850.0",
    "category": 1,
    "origin": "Web",
    "created_at": "2020-03-02T22:36:26+01:00",
    "finished_at": null,
    "status": 2,
    "errno": 0
  }
}

Private Key API. Get an order by id

Request Endpoint: GET https://contract.oceanex.cc/key_user_api/v1/ifcontract/userOrderInfo

Query Parameter

Key Type Description
contract_id Integer currency market contract id
order_id Integer order id

Positions

curl --request GET 'https://contract.oceanex.cc/key_user_api/v1/ifcontract/userPositions?user_jwt=user_jwt' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' 
import requests

endpoint = "https://contract.oceanex.cc/key_user_api/v1/ifcontract/userPositions"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS'
}

data = {
'status': 3
}

payload = encode_params(data) # {'user_jwt': USER_JWT}
response = requests.request("GET", endpoint, headers=headers, params=payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "num_of_resources": 2,
    "positions": [
      {
        "position_id": 42,
        "account_id": 2,
        "contract_id": 1,
        "hold_vol": "1000.0",
        "freeze_vol": "0.0",
        "close_vol": "0.0",
        "hold_avg_price": "10000.0",
        "close_avg_price": "0.0",
        "liquidate_price": "9048.5728592889334001",
        "im": "101.5",
        "mm": "5.0",
        "realised_profit": "0.5",
        "earnings": "0.5",
        "hold_fee": "0.0",
        "open_type": 1,
        "position_type": 1,
        "status": 1,
        "errno": 0,
        "created_at": "2020-02-14T18:38:53+01:00",
        "updated_at": "2020-02-14T18:38:53+01:00"
      }
    ]
  }
}

Private Key API. Get positions

Request Endpoint: GET https://contract.oceanex.cc/key_user_api/v1/ifcontract/userPositions

Query Parameter

Key Type Description
contract_id Integer/Optional currency market contract id
currency_id String/Optional currency id
status Integer Status of position. holding: 1, system_in: 2, holding + system_in: 3, closed: 4
offset Integer/Optional Page number, default 0
size Integer/Optional Number of results per page, default 30
order_by String/Optional Order results by certain sequence, default "desc"

Cancel Order

curl --request POST 'https://contract.oceanex.cc/key_user_api/v1/ifcontract/cancelOrder?user_jwt=user_jwt' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' 
import requests

endpoint = "https://contract.oceanex.cc/key_user_api/v1/ifcontract/cancelOrder"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS'
}

data = {
'id': 3
}

payload = encode_params(data) # {'user_jwt': USER_JWT}
response = requests.request("POST", endpoint, headers=headers, data=payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful"
}

Private Key API. Cancel a specific order

Request Endpoint:POST https://contract.oceanex.cc/key_user_api/v1/ifcontract/cancelOrder

Query Parameter

Key Type Description
order_id Integer order id

Create order

curl --request POST 'https://contract.oceanex.cc/key_user_api/v1/ifcontract/submitOrder?user_jwt=user_jwt' \
--header 'X-API-KEY: kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS' 
import requests

endpoint = "https://contract.oceanex.cc/key_user_api/v1/ifcontract/submitOrder"

headers = {
  'X-API-KEY': 'kFi7onLYRYfUKAzVjXaRn6kKwKLpCVgS'
}

data = {
'id': 3
}

payload = encode_params(data) # {'user_jwt': USER_JWT}
response = requests.request("POST", endpoint, headers=headers, params=payload)
print(response.text.encode('utf8'))

Example Response

{
  "code":0,
  "message":"Operation is successful",
  "data": {
    "order_id": 3885,
    "contract_id": 1,
    "contract_name": "BTC/USDT",
    "price": "10200.0",
    "vol": "1000.0",
    "done_avg_price": "0",
    "done_vol": "0.0",
    "open_type": 1,
    "way": 4,
    "leverage": "10.0",
    "value": "1020.0",
    "category": 1,
    "origin": "Web",
    "created_at": "2020-02-19T01:24:20Z",
    "finished_at": null,
    "status": 1,
    "errno": 0
  }
}

Private Key API. Get positions

Request Endpoint:POST https://contract.oceanex.cc/key_user_api/v1/ifcontract/submitOrder

Query Parameter

Key Type Description
contract_id Integer currency market contract id
category Integer limit: 1, market: 2, post_only: 7
way Integer open_long: 1, close_short: 2, close_long: 3, open_short: 4
price Integer price
vol Integer Volume
leverage Integer Position leverage
position_id Integer If the way is 2 or 3, position_id will be a required field.
origin String The source of incoming request

Contract Websocket

Public Websocket

OceanEx Contract websocket data is Compressed data: Base64(Gzip(data))

K line

Syntax: contract-k-#{contract_id}-#{type}-#{period}

type options: market_price, index_price or fair_price period options: 1, 5, 15, 30, 60, 120, 240, 360, 720, 1440, 4320, 10080

example request

{"event":"pusher:subscribe","data":{"channel":"contract-k-1-market_price-30"}}

example response

{
  "event": "k_line",
  "data": "[[1579041000,7500.0,7500.0,7500.0,7500.0,0]]",
  "channel": "contract-k-1-market_price-30"
}

Order Book(Depth)

Syntax: contract-depth-#{contract_id}

example request

{"event":"pusher:subscribe","data":{"channel":"contract-depth-1"}}

example response

{
  "event": "update",
  "data": "{\"asks\":[],\"bids\":[[\"7500.0\",\"1000.0\"]]}",
  "channel": "contract-depth-1"
}

Ticker

Syntax: contract-ticker-#{contract_id}

example request

{"event":"pusher:subscribe","data":{"channel":"contract-ticker-1"}}

Trade

Syntax: contract-trade-#{contract_id}

example request

{"event":"pusher:subscribe","data":{"channel":"contract-trade-1"}}

Account (Private)

Account

Syntax: contract-private-#{sn}-account-#{currency}

example request

{"event":"pusher:subscribe","data":{"channel":"contract-private-SN0D7C982707-account-usd"}}

Position

Syntax: contract-private-#{sn}

Subscribe events: position, order, trade

Order status Remove it if status = 4 || 5

Position status Remove it if status = 4

example request

{"event":"pusher:subscribe","data":{"channel":"contract-private-SN0D7C982707"}}

Withdraw API

WAPI Endpoints (to be released)

Special Withdraw post

import requests

method_url = base_url + "/withdraws/special/new"
data = {
    "rid": "0x7781a6C9B25B529037a85ad637669D848a1F9796",
    "currency": "vet",
    "amount": 10,
    "memo": "A note about the withdraw"   
}

request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/withdraws/special/new?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
    "code": 0,
    "message": "Operation successful",
    "data": {
        "id":1372,
        "currency":"VET",
        "chain_name":"",
        "type":"coin",
        "amount":"10.0",
        "fee":"1.0",
        "blockchain_txid":null,
        "rid":"0x7781a6C9B25B529037a85ad637669D848a1F9796",
        "is_combination_address":false,
        "address":"0x7781a6C9B25B529037a85ad637669D848a1F9796",
        "memo":"A note about the withdraw",
        "state":"fund_requesting",
        "created_at":"2019-11-06T14:58:06Z",
        "updated_at":"2019-11-06T14:58:06Z",
        "completed_at":null,
        "created_on":1573052286,
        "updated_on":1573052286,
        "completed_on":null,
        "done_at":null
    }
}

Make a withdraw while bypassing Google authentication and email verification. Requires address (rid) to be whitelisted.

Parameters:

Name Description Required Schema
tid The shared transaction ID. Must not exceed 64 characters. The system will generate one automatically unless supplied. No string
rid Withdraw destination address or beneficiary ID Yes string
currency Currency ID Yes string
chain_name The chain name of the currency (if applicable) No string
amount Amount to withdraw Yes float
memo Memo of withdraw No string

Transaction Response Parameters:

Key Description Schema
id Transaction id of OceanEx Interger
currency Currency name String
chain_name Blockchain name String
type Withdraw currency type String
amount Withdraw amount Float
fee Fee charged Float
blockchain_txid Blockchain Transaction Id String
rid Withdraw destination address or beneficiary ID String
is_combination_address Whether address is combination address Boolean
address Destination address String
memo Transaction Memo String
state Transaction state String
created_at Transaction created time(ISO8601) Datetime
updated_at Transaction updated time(ISO8601) Datetime
completed_at Transaction completed time(ISO8601) Datetime
created_on Transaction created time Timestamp
updated_on Transaction updated time Timestamp
completed_on Transaction completed time Timestamp
done_at Transaction completed time(ISO8601) Datetime

Rate limit: 3000 req/min

Deposit Address post

import requests

method_url = base_url + "/deposit_address"
data = {
    "currency": "vet"  
}

request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/deposit_address?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
    "code": 0,
    "message": "Operation successful",
    "data": {
        "currency": "vet",
        "address": "0x12B937eF96553948fAE98e9Ba1e3c027Da3ae548"
    }
}

Get your deposit address for a currency.

Parameters:

Name Description Required Schema
currency Currency ID Yes string

Rate limit: 3000 req/min

Deposit Addresses post

import requests

method_url = base_url + "/deposit_addresses"
data = {
    "currency": "eth"  
}

request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/deposit_addresses?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
    "code": 0,
    "message": "Operation successful",
    "data": {
        "data": {
          "currency_id": "vet",
          "display_name": "VET",
          "num_of_resources": 1,
          "resources": [
            {
              "chain_name": "",
              "currency_id": "vet",
              "address": "0x12B937eF96553948fAE98e9Ba1e3c027Da3ae548",
              "memo": "",
              "deposit_status": "enabled"
            }
          ]
        }
    }
}

Get deposit addresses for a currency.

Parameters:

Name Description Required Schema
currency Currency ID Yes string

Deposit History post

import requests

method_url = base_url + "/deposit_history"
data = {
    "currency": "vet",
    "limit": 5,
    "state": "accepted",
    "page": 1
}

request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/deposit_history?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
    "code": 0,
    "message": "Operation successful",
    "data": {
        "num_of_resources": 6,
        "resources": [
            {
                "id": 1071,
                "currency": "VET",
                "amount": "99.0",
                "fee": "0.0",
                "txid": "0x390b89847b080228bcb10c609291cf73ffdb501a8725e48c8c09b61694d47d5c",
                "is_combination_address": false,
                "address": "0x12B937eF96553948fAE98e9Ba1e3c027Da3ae548",
                "memo": "",
                "created_at": "2019-10-15T16:27:48Z",
                "created_on": 1571156868,
                "confirmations": 7,
                "completed_at": "2019-10-15T16:28:49Z",
                "completed_on": 1571156929,
                "state": "accepted"
            }
        ]
    }
}

Get a list of your deposits.

Parameters:

Name Description Required Schema
currency Currency ID No string
page Page number (defaults to 1) No Integer
limit Set result limit No Integer
state State of deposits No String

Possible values for state

[submitted, canceled, rejected, reverted, accepted, pending, processing settled, suspending, suspended, suspend_failed, clearing, clear_failed]

Rate limit: 3000 req/min

Withdraw History post

import requests

method_url = base_url + "/withdraw_history"
data = {
    "currency": "vet",
    "limit": 3,
    "page": 1
}

request_body = construct_request_body(data)

r = requests.post(method_url, data=request_body)
curl -X POST \
  https://api.oceanex.cc/v1/withdraw_history?user_jwt= JWT_TOKEN

The above command returns JSON structured like this:

{
    "code": 0,
    "message": "Operation successful",
    "data": {
        "num_of_resources": 1,
        "resources": [
           {
             "id": 1372,
             "currency": "VET",
             "chain_name": "",
             "type": "coin",
             "amount": "10.0",
             "fee": "1.0",
             "blockchain_txid": null,
             "rid": "0x7781a6C9B25B529037a85ad637669D848a1F9796",
             "is_combination_address": false,
             "address": "0x7781a6C9B25B529037a85ad637669D848a1F9796",
             "memo": "",
             "state": "rejected",
             "created_at": "2019-11-06T14:58:06Z",
             "updated_at": "2019-11-06T15:17:36Z",
             "completed_at": "2019-11-06T15:17:36Z",
             "created_on": 1573052286,
             "updated_on": 1573053456,
             "completed_on": 1573053456,
             "done_at": "2019-11-06T15:17:36Z"
           }
        ]
    }
}

Get a list of the your withdraws.

Parameters:

Name Description Required Schema
currency Currency ID No string
limit Number of withdraws per page (defaults to 100, maximum is 1000) No Integer
page Page number (defaults to 1) No Integer

Rate limit: 3000 req/min

Websocket

Websockets

import json 
from websocket import create_connection # pip install websocket-client

ws = create_connection("wss://ws.oceanex.cc/ws/v1")

The base URL for all websockets is: wss://ws.oceanex.cc/ws/v1.

Request Parameter

field description type
identifier format as { handler: "MyHandler" }.to_json string
command command message string
data format as {action: "MyAction", uuid: "RequestUUID", args: {}}.to_json string

Response Parameter

field description type
identifier format as "{\"handler\":\"YourHandler\"}" string
message format as {action: 'Action',uuid: 'RequestUUID',code: StatusCode,data: {}} object

Websocket Protocol

Handshake Protocol

When client tries to build connection with server, server will:

  1. Accept the connection. Server returns welcome message as {"type":"welcome", "message": 60}. message indicates ping timeout. If client doesn't receive following ping request from server, client needs to reconnect with server; if does receieve, ping timeout will reset

  2. Reject the connection. Server return disconnect message as {"type":"disconnect", "reason":"unauthorized", "reconnect":false}

Ping/Pong Protocol

After connection building successfully, server will send ping request every 30 seconds as { "type": "ping", "message": <Time.now.to_i>}. Client should send pong response back as { "command": "pong" }.

If server doesn't receive any pong response back in every 90 seconds (3 ping request period). Server will stop the connection.

Websocket Authentication

import json
from websocket import create_connection
import time
import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import padding

uid = "ID2A4CE69293"
apikid = "KID3EB0E91D2C"
with open("key.pem", "rb") as private_file:
    user_private_key = private_file.read()

cur = int(time.time()*1000)

def generate_signature():
   private_key = serialization.load_pem_private_key(
    user_private_key.encode('ascii'),
    password=None,
    backend=default_backend()
   )
   path = "GET|/ws/v1|{}|".format(cur)
   sign = private_key.sign(
      path.encode('utf-8'),
      padding.PKCS1v15(),
      hashes.SHA256()
   )
   signature = base64.b64encode(sign).decode()
   return signature

ws = create_connection("wss://ws.oceanex.cc/ws/v1")

auth = {
  "identifier": json.dumps({"handler":"AuthHandler"}),
  "command": "message",
  "data": json.dumps({
        "action":"login",
        "uuid":"69ac1055-147f-460d-b170-5e035bbde74f",
        "args":{},
        "header":{
            "uid":uid,
            "api_key":apikid,
            "signature": generate_signature(),
            "nonce": cur,
            "verb":"GET",
            "path":"/ws/v1"
        }
     }
  )
}

ws.send("Hello") # initiate connection

print("login")
ws.send(json.dumps(auth))
print("login response")
print(ws.recv())

example success response

{
    "identifier":"{\"handler\": \"AuthHandler\"}",
    "message":{
        "action":"login",
        "uuid":"69ac1055-147f-460d-b170-5e035bbde74f",
        "code":0,
        "data":{
            "scopes":{"query":true,"sell/buy":true,"withdraw":true}
        }
    }
}

example fail response

{
"type":"disconnect", 
"reason":"unauthorized", 
"reconnect":false
}

To access private API/channel, client needs to be authenticated. After logging, clients do not need to be authenticated again until connection break

Signature Generation

Login in API Header Parameters

Websocket Timestamp

Get Server Timestamp

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
data = {
  "identifier": json.dumps({"handler":"ToolHandler"}),
  "command": "message",
  "data": json.dumps({"action":"timestamp","uuid":"3dafadd9-39e5-442a-8905-836fa277aacc","args":{}})
}
print("Websocket connect")
while True:
  ws.send(json.dumps(data))
  result =  ws.recv()
  print("Received '%s'" % result)
ws.close()

The expected return like this

{
    "identifier":"{\"handler\": \"ToolHandler\"}",
    "message":{
        "action":"timestamp",
        "uuid":"3dafadd9-39e5-442a-8905-836fa277aacc",
        "code":0,
        "data":1581023119
    }
}

Websocket Markets

Get all markets

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
data = {
     "identifier": "{\"handler\":\"MarketsHandler\"}",
     "command": "message",
     "data": "{\"action\":\"index\",\"uuid\":\"6c3679c8-9b58-4a91-b1ce-9b22678aaf5c\",\"args\":{}}"
}
print("Websocket connect")
while True:
  ws.send(json.dumps(data))
  result =  ws.recv()
  print("Received '%s'" % result)
ws.close()

The expected return like this

{
  "identifier": "{\"handler\":\"MarketsHandler\"}",
  "message": {
  "action": "index",
  "uuid": "6c3679c8-9b58-4a91-b1ce-9b22678aaf5c",
  "code": 0,
  "data": [
        {
          "id": "usdvet",
          "name": "USD/VET",
          "display_name": "USD/VET",
          "ask_precision": 4,
          "bid_precision": 4,
          "enabled": true,
          "price_precision": 8,
          "amount_precision": 8,
          "usd_precision": 8,
          "minimum_trading_amount": "0.0",
          "group": "VET"
        }
    ]
  }
}

Websocket Trading Fee

Get all market trading fee

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
data = {
 "identifier": "{\"handler\":\"FeeHandler\"}",
 "command": "message",
 "data": "{\"action\":\"trading_fee\",\"uuid\":\"65e87a36-aba8-484e-b685-b55b24959d1a\",\"args\":{}}"
}
print("Websocket connect")
while True:
  ws.send(json.dumps(data))
  result =  ws.recv()
  print("Received '%s'" % result)
ws.close()

The expected return like this

{
    "identifier":"{\"handler\":\"FeeHandler\"}",
    "message":{
        "action":"trading_fee",
        "uuid":"65e87a36-aba8-484e-b685-b55b24959d1a",
        "code":0,
        "data":[
            {
                "market_id":"eosusdt",
                "ask_fee":{"type":"relative","value":"0.001"},
                "bid_fee":{"type":"relative","value":"0.001"}
            },
            {
                "market_id":"ethbtc",
                "ask_fee":{"type":"relative","value":"0.001"},
                "bid_fee":{"type":"relative","value":"0.001"}
            }
        ]
    }
}

Websocket Tickers

API

Get ticker information. market_ids is optional. Default to all enabled market_ids array

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
data = {
  "identifier": "{\"handler\":\"TickerHandler\"}",
  "command": "message",
  "data": "{\"action\":\"index\",\"uuid\":\"1310421e-a163-4f7a-9dc3-412c49c7dfc1\",\"args\":{\"market_ids\":[\"vetoce\"]}}"
}
print("Websocket connect")
while True:
  ws.send(json.dumps(data))
  result =  ws.recv()
  print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
  "identifier":"{\"handler\":\"TickerHandler\"}", 
  "message":{
    "action":"index",
    "uuid":"1310421e-a163-4f7a-9dc3-412c49c7dfc1",
    "code":0,
    "data":{
        "vetoce":{
            "name":"VET/OCE",
            "display_name":"VET/OCE",
            "base_unit":"vet",
            "quote_unit":"oce",
            "position":64,
            "open":"0.0",
            "volume":"0.0",
            "funds":"0.0",
            "sell":"1.72550056",
            "buy":"1.6906296",
            "low":"0.0","high":"0.0",
            "first":"0.0","last":"1.68970844",
            "h24_trend":"0.0",
            "at":1581024183
        }
    }
  }
}

Websocket Order Book

Get orderbook information.

Parameter

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
data = {
     "identifier": "{\"handler\":\"OrderBookHandler\"}",
     "command": "message",
     "data": "{\"action\":\"index\",\"uuid\":\"1bd05222-5755-4563-946c-3db8695e4d26\",\"args\":{\"market_id\":\"vetoce\",\"level\":2,\"precision\":6}}"
}
print("Websocket connect")
while True:
  ws.send(json.dumps(data))
  result =  ws.recv()
  print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderBookHandler\"}",
    "message":{
        "action":"index",
        "uuid":"1bd05222-5755-4563-946c-3db8695e4d26",
        "code":0,
        "data":{
            "asks":[["1.725501","50000.0"],["1.72557","50000.0"]],
            "bids":[["1.690629","50000.0"],["1.690492","50000.0"]]
        }
    }
}

Websocket K Line

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")

data = {
 "identifier": "{\"handler\":\"KlineHandler\"}",
 "command": "message",
 "data": "{\"action\":\"index\",\"uuid\":\"58bacf08-0a68-41b2-97fe-35b7f1b6f696\",\"args\":{\"market_id\":\"vetoce\",\"limit\":30,\"period\":5}}"
}
print("Websocket connect")
while True:
  ws.send(json.dumps(data))
  result =  ws.recv()
  print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
  "identifier": "{\"handler\":\"KlineHandler\"}",
  "message": {
    "action": "index",
    "uuid": "58bacf08-0a68-41b2-97fe-35b7f1b6f696",
    "code": 0,
    "data": [[1581104400, 1.68970844, 1.68970844, 1.68970844, 1.68970844, 0], 
            [1581104700, 1.68970844, 1.68970844, 1.68970844, 1.68970844, 0]]
  }
}

Get K Line history data.

Parameter

Websocket Account

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
     "identifier": "{\"handler\":\"AccountHandler\"}",
     "command": "message",
     "data": "{\"action\":\"index\",\"uuid\":\"84b21ad5-2818-4b15-a57d-20f9ce8f7d7c\",\"args\":{}}"
   }
print("Websocket connect")
while True:
  ws.send(json.dumps(data))
  result =  ws.recv()
  print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
  "identifier":"{\"handler\":\"AccountHandler\"}",
  "message":{
    "action":"index",
    "uuid":"84b21ad5-2818-4b15-a57d-20f9ce8f7d7c",
    "code":0,
    "data": [{
        "currency":"vet", 
        "type":"coin", 
        "deposit":"enabled",
        "withdraw":"enabled",
        "exchange":"enabled",
        "balance":"24707768.7679",
        "btc_equivalent_balance":"13.074097065630021396",
        "locked":"0.0",
        "is_combination_address":false,
        "markets":[{"display_name":"VET/ETH","base_unit":"vet","quote_unit":"eth"},
                {"display_name":"VET/OCE","base_unit":"vet","quote_unit":"oce"},
                {"display_name":"VET/USDT","base_unit":"vet","quote_unit":"usdt"}]
    }]
  }
}

Get Account information.

Websocket Order Create

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
    "identifier": "{\"handler\":\"OrderHandler\"}",
    "command": "message",
    "data": json.dumps({
                        "action":"create",
                        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
                        "args":{
                            "market": "vetusdt",
                            "side": "buy",
                            "volume": 0.75,
                            "price": 1000,
                            "ord_type": "limit"    
                        }
                       })
}
print("Websocket connect")
ws.send(json.dumps(data))
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderHandler\"}", 
    "message":{
        "action":"create",
        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
        "code":0,
        "data":{
            "id":44441592,
            "side":"bid",
            "ord_type":"limit",
            "price":"1000.0",
            "avg_price":"0.0",
            "state":"wait",
            "market":"vetusdt",
            "market_name":"VET/USDT",
            "market_display_name":"VET/USDT",
            "created_at":"2020-02-07T20:45:59Z",
            "created_on":1581108359,
            "volume":"0.7",
            "remaining_volume":"0.7",
            "executed_volume":"0.0",
            "trades_count":0
        }
    }
}

Parameter

Websocket Order Info

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
    "identifier": "{\"handler\":\"OrderHandler\"}",
    "command": "message",
    "data": json.dumps({
                        "action":"show",
                        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
                        "args":{
                            "id": 44441592
                        }
                       })
}
print("Websocket connect")
ws.send(json.dumps(data))
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderHandler\"}", 
    "message":{
        "action":"show",
        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
        "code":0,
        "data":{
            "id":44441592,
            "side":"bid",
            "ord_type":"limit",
            "price":"1000.0",
            "avg_price":"0.0",
            "state":"wait",
            "market":"vetusdt",
            "market_name":"VET/USDT",
            "market_display_name":"VET/USDT",
            "created_at":"2020-02-07T20:45:59Z",
            "created_on":1581108359,
            "volume":"0.7",
            "remaining_volume":"0.7",
            "executed_volume":"0.0",
            "trades_count":0,
            "trades": []
        }
    }
}

Get active Order Info by ID

Parameter

Websocket Order Cancel

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
    "identifier": "{\"handler\":\"OrderHandler\"}",
    "command": "message",
    "data": json.dumps({
                        "action":"cancel",
                        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
                        "args":{
                            "ids": [44441592]
                        }
                       })
}
print("Websocket connect")
ws.send(json.dumps(data))
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderHandler\"}", 
    "message":{
        "action":"cancel",
        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
        "code":0,
        "data":[44441592]
    }
}

Cancel open order by id

Parameter

Websocket All Order Cancel

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
    "identifier": "{\"handler\":\"OrderHandler\"}",
    "command": "message",
    "data": json.dumps({
                        "action":"clear",
                        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
                        "args":{}
                       })
}
print("Websocket connect")
ws.send(json.dumps(data))
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderHandler\"}", 
    "message":{
        "action":"clear",
        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
        "code":0,
        "data":[44441592]
    }
}

Cancel all open order

Parameter

Websocket All Open Order

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
    "identifier": "{\"handler\":\"OrderHandler\"}",
    "command": "message",
    "data": json.dumps({
                        "action":"index",
                        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
                        "args":{
                            "ord_type": "limit",
                            "market": "vetusdt"
                        }
                       })
}
print("Websocket connect")
ws.send(json.dumps(data))
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderHandler\"}",
    "message":{
        "action":"index",
        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
        "code":0,
        "data":{
              "resources_count": 11,
              "resources": [
                {
                  "id":44441592,
                  "side":"bid",
                  "ord_type":"limit",
                  "price":"1000.0",
                  "avg_price":"0.0",
                  "state":"wait",
                  "market":"vetusdt",
                  "market_name":"VET/USDT",
                  "market_display_name":"VET/USDT",
                  "created_at":"2020-02-07T20:45:59Z",
                  "created_on":1581108359,
                  "volume":"0.7",
                  "remaining_volume":"0.7",
                  "executed_volume":"0.0",
                  "trades_count":0
                }
              ]
        }
    }
}

Get all open orders

Parameter

Websocket History Order

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
    "identifier": "{\"handler\":\"OrderHistoryHandler\"}",
    "command": "message",
    "data": json.dumps({
                        "action":"show",
                        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
                        "args":{
                            "id": 44441592
                        }
                       })
}
print("Websocket connect")
ws.send(json.dumps(data))
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderHistoryHandler\"}",
    "message":{
        "action":"show",
        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
        "code":0,
        "data":{
            "id":44441592,
            "side":"bid",
            "ord_type":"limit",
            "price":"1000.0",
            "avg_price":"0.03317",
            "state":"done",
            "market":"vetusdt",
            "market_name":"VET/USDT",
            "market_display_name":"VET/USDT",
            "created_at":"2020-02-07T20:45:59Z",
            "created_on":1581108359,
            "volume":"0.7",
            "remaining_volume":"0.0",
            "executed_volume":"0.7",
            "trades_count":1,
            "trades":[{
                "id":17023288,
                "price":"0.03317",
                "volume":"0.7",
                "funds":"0.023219",
                "market":"vetusdt",
                "market_name":"VET/USDT",
                "market_display_name":"VET/USDT",
                "created_at":"2020-02-07T20:46:00Z",
                "created_on":1581108360,
                "side":"bid",
                "bid_fee_currency_id":"vet",
                "bid_fee":"0.0014",
                "fee":"0.002",
                "order_id":44441592}]
        }
    }
}

Get History Order Info by id (done)

Parameter

Websocket All History Order

import json
from websocket import create_connection
ws = create_connection("wss://ws.oceanex.cc/ws/v1")
## Authentication

data = {
    "identifier": "{\"handler\":\"OrderHistoryHandler\"}",
    "command": "message",
    "data": json.dumps({
                        "action":"index",
                        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
                        "args":{
                            "market": "vetusdt"
                        }
                       })
}
print("Websocket connect")
ws.send(json.dumps(data))
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

The expected return likes this:

{
    "identifier":"{\"handler\":\"OrderHistoryHandler\"}",
    "message":{
        "action":"index",
        "uuid":"66c1d126-ad97-4b0a-b9e9-a381e3c88a5a",
        "code":0,
        "data":{
                "resources_count":6,
                "resources":[
                {
                    "id":44441592,
                    "side":"bid",
                    "ord_type":"limit",
                    "price":"1000.0",
                    "avg_price":"0.03317",
                    "state":"done",
                    "market":"vetusdt",
                    "market_name":"VET/USDT",
                    "market_display_name":"VET/USDT",
                    "created_at":"2020-02-07T20:45:59Z",
                    "created_on":1581108359,
                    "volume":"0.7",
                    "remaining_volume":"0.0",
                    "executed_volume":"0.7",
                    "trades_count":1
                }
                ]
        }
    }
}

Get All History Order Info

Parameter

Example Code

Long live connection example code

import json
import websocket

def on_message(ws, message):
    message = json.loads(message)
    print("*** Receive Message as {}".format(message))
    if "type" in message and message['type'] == "ping":
        print("return pong")
        ws.send(json.dumps({ "command": "pong" }))

def on_error(ws, error):
    print(error)

def on_close(ws):
    print("### closed ###")

def on_open(ws):
    print("######## WS Opened ########")
    ws.send("Hello")
    data = {
      "identifier": json.dumps({"handler":"ToolHandler"}),
      "command": "message",
      "data": json.dumps({"action":"timestamp","uuid":"3dafadd9-39e5-442a-8905-836fa277aacc","args":{}})
    }
    ws.send(json.dumps(data))



if __name__ == "__main__":
    ws = websocket.WebSocketApp("wss://ws.oceanex.cc/ws/v1",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    ws.run_forever()

REST Errors

Common authentication errors include:

The key is disabled.

{
  "data": {},
  "code": 1008,
  "message": "Your key is disabled"
}

Invalid Key.

{
  "message": "Token verification failed",
  "code": 1010,
  "data": {}
}

IP is not on a white list.

{
  "message": "This IP "22.222.222.222" is not allowed",
  "code": 1011,
  "data": {}
}

The scope is insufficient.

{
  "message": "You do not have API "post:/v2/orders/multi" permissions, or the API does not exist",
  "code": 9003,
  "data": {}
}

The OceanEx trading API uses the following error codes:

Error Code Meaning
-1, -2, -9, 1005 Server error -- Please be patient.
1003, 9001 Algorithm error -- Your JWT encoding algorithm is wrong, RS 256 encoding is required.
1004, 9002 Missing parameters or invalid format in authentication payload.
1001 JWT error -- Token is not in a valid JWT format.
1002 Payload cannot be empty.
1006 The account does not exist.
1007 Your account has no public key.
1008 Your key is disabled.
1010 Token verification failed.
1011 This IP "xxx.xxx.xxx.xxx" is not allowed.
2001 Token expired. Authorization failed
2002 Failed to create order. Error parameter or exceeding request limit
2003 Failed to cancel order
2004 Order doesn't exit
2012 Deposit doesn't exit
3001 Withdraw amount less than required amount
3002 Withdraw rid is not whitelisted
9003 You do not have API "xx:/xx/xxx" permissions, or the API does not exist.