NAV
json c++ javascript python

Introduction

Welcome to CoinFLEX's v2 application programming interface (API). Please note, this is a beta version and should be considered a test net.

CoinFLEX's APIs provide our clients programmatic access to control aspects of their accounts and to place orders on CoinFLEX's trading platform. CoinFLEX provides the following APIs:

Using these interfaces it is possible to place both authenticated and unauthenticated API commands for public and prvate commands respectively.

To get started please register for a TEST account at https://v2stg.coinflex.com/user-console/register

API Key Management

An API key is required to make an authenticated API command. API keys (public and corresponding secret key) can be generated via the CoinFLEX GUI within a clients account.

By default, API Keys are read-only and can only read basic account information, such as positions, orders, and trades. They cannot be used to trade such as placing, modifying or cancelling orders.

If you wish to execute orders with your API Key, clients must select the Can Trade permission upon API key creation.

API keys are also only bound to a single sub-account, defined upon creation. This means that an API key will only ever interact and return account information for a single sub-account.

Change Log

2020-09-25 - Added physical delivery API endpoints - Added position WebSocket channel - Added balance WebSocket channel - Added GET /v2/accountinfo - Added GET /v2/ticker - Added rate limits - Added guidance for maintaining connections

2020-07-25 - Added GET /v2/publictrades/{marketCode} - Added GET /v2/trades/{marketCode}

2020-06-16 - Added general guidance for getting a login/password to create tokens - Updated some addresses for REST API

2020-06-15 - First version of beta API endpoints - Websocket and REST

Rate Limit

CoinFLEX's application programming interface (API) allows our clients to access and control their accounts or view our market data using custom-written software. To protect the performance of the system, we impose certain limits:

Type Limit
Rest API 100 per second
Websocket API 200 per second

Session Keep Alive

To maintain an active WebSocket connection it is imperative to either be subscribed to a channel that pushes data at least once per minute (Depth or Balance) or send a ping to the server once per minute.

Websocket API

Request format

{
  "op": "<value>",
   "args": ["<value>"]
}

OR

{
  "op": "<value>,
  "data": {"<key1>": "<value1>",.....}
}

Success response format

{
  "event": "<op value>",
  "channel": "<args value>",
  "success": true
}

OR

{
  "event": "<op value>",
  "success": true
}

Failure response format

{
  "event": "error",
  "message": "<errorMessage>",
  "code": "<code>",
  "success": false
}

TEST site

LIVE site

CoinFLEX's application programming interface (API) provides our clients programmatic access to control aspects of their accounts and to place orders on the CoinFLEX trading platform. The API is accessible via WebSocket connection to the URIs listed above. Commands, replies, and notifications all traverse the WebSocket in text frames with JSON-formatted payloads.

Websocket commands can be sent in either of the following two formats:

For subscription based commands

{"op": "<value>", "args": ["<value>"]}

op: can either be:

args: the value is the channel name, for example:

All other commands

{"op": "<command>", "data": {"<key1>":"<value1>",.....}}

op: can be:

data: JSON string of the request object containing the required parameters

Authentication

Request format

{
  "op": "login",
  "tag": "<integer>",
  "data":{
          "apiKey": "<string>",
          "timestamp": "<string>",
          "signature": "<string>"
         }
}
import websockets
import asyncio
import time
import hmac
import base64
import hashlib
import json

api_key = 'API-KEY'
api_secret = 'API-SECRET'
ts = str(int(time.time() * 1000))
sig_payload = (ts+'GET/auth/self/verify').encode('utf-8')
signature = base64.b64encode(hmac.new(api_secret.encode('utf-8'), sig_payload, hashlib.sha256).digest()).decode('utf-8')

msg_auth = \
{
  "op": "login",
  "tag": 1,
  "data": {
           "apiKey": api_key,
           "timestamp": ts,
           "signature": signature
          }
}

async def subscribe():
    async with websockets.connect('wss://api-test-v2.coinflex-cn.com/v2/websocket') as ws:
        await ws.send(json.dumps(msg_auth))
        while ws.open:
            resp = await ws.recv()
            print(resp)

asyncio.get_event_loop().run_until_complete(subscribe())
var apiKey = "API-KEY";
var secretKey = "API-SECRET";
const ts = '' + Date.now();

var sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(secretKey, ts +'GET/auth/self/verify'));
var msg = '{"op":"login","data":{"apiKey":"' + apiKey + '", "timestamp": "'+ ts + '", "signature":"'+ sign + '"}}';

var ws = new WebSocket('wss://api-test-v2.coinflex-cn.com/v2/websocket');

ws.onmessage = function (e) {
  console.log('websocket message from server : ', e.data);
};

ws.onopen = function () {
    ws.send(msg);
};

Success response format

{
  "event": "login",
  "success": true,
  "tag": "1",
  "timestamp": "1592491808"
}
{
  "event": "login",
  "success": True,
  "tag": "1",
  "timestamp": "1592491808"
}
{
  "event":"login",
  "success":true,
  "tag":"1",
  "timestamp":"1592491808"
}

Failure response format

{
  "event": "login",
  "success": false,
  "code": "<code>",
  "message": "<errorMessage>",
  "tag": "1",
  "timestamp": "1592492032"
}
{
  "event": "login",
  "success": False,
  "code": "<code>",
  "message": "<errorMessage>",
  "tag": "1",
  "timestamp": "1592492032"
}
{
  "event":"login",
  "success":false,
  "code":"<code>",
  "message":"<errorMessage>",
  "tag":"1",
  "timestamp":"1592492032"
}

The Websocket API consists of public and private methods. The public methods do not require authentication. The private methods requires an authenticated websocket connection.

To autenticate a websocket connection a "login" message must be sent containing the clients signature.

To construct the signature a clients API-Secret key is required. API keys (public and corresponding secret key) can be generated via the GUI within the clients account.

The signature is calculated as:

Parameters - Login

Parameter Type Required Description
op STRING Yes 'login'
tag INTEGER No If given, it will be echoed in the reply.
data ARRAY object Yes
>apiKey STRING Yes Clients public API key, visible in the GUI when created.
>timestamp STRING Yes Current millisecond timestamp
>signature STRING Yes Base64(HmacSHA256(API-Secret, timestamp + 'GET/auth/self/verify'))

Place Order

Limit Order

Request format

{
  "op": "placeorder",
  "data":{
          "clientOrderId": 1,
          "marketCode": "BTC-USD-SWAP-LIN",
          "side": "BUY",
          "orderType": "LIMIT",
          "quantity": 1.5,
          "timeInForce": "GTC",
          "price": 9431.48
          },
  "tag": 1
}

Submitted response format

{
  "event": "placeorder",
  "submitted": true,
  "tag": "1",
  "data":{
          "clientOrderId": "1",
          "marketCode": "BTC-USD-SWAP-LIN",
          "side": "BUY",
          "orderType": "LIMIT",
          "quantity": "1.5",
          "timeInForce": "GTC",
          "price": "9431.48"
         },
  "timestamp": "1592491945"
}

Failure response format

{
  "event": "placeorder",
  "message": "<errorMessage>",
  "code": "<code>",
  "submitted": false,
  "tag": "1",
  "timestamp": "1592491503"
}

Requires authentication. Please also subscribe to the user order channel to receive push notifications for all message udpates related to a clients orders.

Request Parameters Specification:

Parameters Type Required Description
clientOrderId INTEGER No Customized order ID to identify your orders
marketCode STRING Yes Market Code i.e. BTC-USD-SWAP-LIN
orderType STRING Yes LIMIT for limit orders
price DECIMAL Yes Price
quantity DECIMAL Yes Quantity (denominated by contractValCurrency)
side STRING Yes BUY / SELL
timeInForce ENUM No
  • GTC (Good-till-Cancel) - Default
  • IOC (Immediate or Cancel, i.e. Taker-only)
  • FOK (Fill or Kill, for full size)
  • MAKER_ONLY (i.e. Post-only)
  • MAKER_ONLY_REPRICE (Reprices order to the best maker price if specified price otherwise leads to a taker trade)
tag INTEGER No Iff given and non-zero, it will be echoed in the reply.

Market Order   **NOT AVAILABLE**

Stop Limit Order   **NOT AVAILABLE**

Requires authentication. Please subscribe user order channel to receive the order updates.

Request format

{
  "op": "placeorder",
  "data":{
          "clientOrderId": 1,
          "marketCode": "BTC-USD-SWAP-LIN",
          "side": "BUY",
          "orderType": "STOP",
          "quantity": 10,
          "stopPrice": 100,
          "limitPrice": 120
         }
}

Request Parameters Specification:

Parameters Type Required Description
clientOrderId NUMBER No User-generated order ID to identify orders
limitPrice NUMBER Yes Limit price for the stop-limit order.

The limit price must be greater or equal to the stop price for buy-side.

The limit price must be less or equal to the stop price for sell-side.

marketCode STRING Yes Market Code i.e. BTC-USD-SWAP-LIN
orderType STRING Yes STOP for Stop-Limit orders (no Stop-market currently)
quantity NUMBER Yes Quantity (denominated by contractValCurrency)
side STRING Yes BUY/ SELL
stopPrice NUMBER Yes Stop price for the stop-limit order.

Triggered by the best bid price for the SELL side stop-limit order.

Triggered by the best ask price for the BUY side stop-limit order.

Cancel Order

Request format

{
  "op": "cancelorder",
  "data":{
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": 12
         },
  "tag": 1
}

Requires authentication. Please subscribe user order channel to receive the order updates.

Request Parameters Specification:

Parameters TYPE REQUIRED Description
marketCode STRING YES Market Code i.e. BTC-USD-SWAP-LIN
orderId INTEGER YES Order ID is generated by the server.

Submitted response format

{
  "event": "cancelorder",
  "submitted": true,
  "data":{
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "12"
         },
  "tag": "1",
  "timestamp": "1592491173"
}

Failure response format

{
  "event": "cancelorder",
  "message": "<errorMessage>",
  "code": "<code>",
  "submitted": false,
  "tag": "1",
  "timestamp": "1592491473"
}

Modify Order

Request format

{
  "op": "modifyorder",
  "data":{
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": 888,
          "side": "BUY",
          "price": 9800,
          "quantity": 2
         },
  "tag": 1
}

Submitted response format

{
  "event": "modifyorder",
  "submitted": true,
  "data":{
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": 888,
          "side": "BUY",
          "price": 9800,
          "quantity": 2
         },
  "tag": "1",
  "timestamp": "1592491032"
}

Failure response format

{
  "event": "modifyorder",
  "message": "<errorMessage>",
  "code": "<code>",
  "submitted": false,
  "tag": "1",
  "timestamp": "1592491173"
}

Requires authentication. Please subscribe user order channel to receive the order updates.

Parameters Type Required Description
marketCode string Yes market id
orderId integer Yes Order ID generated by the server
side string Yes BUY or SELL
price decimal Yes Price for limit orders
quantity decimal Yes Quantity (denominated by contractValCurrency)

Subscriptions - Private

User Balance Channel

Request format

{"op": "subscribe", "args": ["balance:all"], "tag": 1}
{"op": "subscribe", "args": ["balance:USD"], "tag": 1}

Requires authentication. Get the user's order information.

Channel Name : balance: <all or assetId>\

Update Speed : 250ms

Unfiltered balance update format


{
    "accountId": "3",
    "data": [
        {
            "total": "10000",
            "reserved": "1000",
            "instrumentId": "USD",
            "available": "9000",
            "quantityLastUpdated": "1599694369431"
        },
        {
            "total": "100000",
            "reserved": "0",
            "instrumentId": "FLEX",
            "available": "100000",
            "quantityLastUpdated": "1599694343242"
        }
    ],
    "table": "balance",
    "timestamp": "1599693365059",
    "tradeType": "Linear"
}

Filtered balance update format


{
    "accountId": "3",
    "data": [
        {
            "total": "10000",
            "reserved": "1000",
            "instrumentId": "USD",
            "available": "9000",
            "quantityLastUpdated": "1599694369431"
        }
    ],
    "table": "balance",
    "timestamp": "1599693365059",
    "tradeType": "Linear"
}
Parameters Type Description
accountId STRING Account identifier
total STRING Total spot balance
reserved STRING Balance reserved by orders
instrumentId STRING Base asset i.e. BTC
available STRING Available balance (total - reserved)
quantityLastUpdated STRING UNIX timestamp
table STRING Table identifier
timestamp STRING UNIX timestamp
tradeType STRING Account type

User Position Channel

Request format

{"op": "subscribe", "args": ["position:all"], "tag": 1}
{"op": "subscribe", "args": ["position:BTC-USD-SWAP-LIN"], "tag": 1}

Requires authentication. Get the user's order information.

Channel Name : position:

Update Speed : on position update

Unfiltered position update format


{
    "accountId": "3",
    "data": [
        {
            "entryPrice": "10000.00000000",
            "lastUpdated": "1599693362699",
            "contractValCurrency": "BTC",
            "quantity" : "1.00000000",
            "instrumentId": "BTC-USD-SWAP-LIN"
        }
    ],
    "table": "position",
    "timestamp": "1599693365059"
}

Filtered position update format


{
    "accountId": "3",
    "data": [
        {
            "entryPrice": "10000.00000000",
            "lastUpdated": "1599693362699",
            "contractValCurrency": "BTC",
            "quantity" : "1.00000000",
            "instrumentId": "BTC-USD-SWAP-LIN"
        }
    ],
    "table": "position",
    "timestamp": "1599693365059"
}

Parameters Type Description
accountId STRING Account identifier
entryPrice STRING Average Entry Price (Cost / Size)
lastUpdated STRING UNIX timestamp
contractValCurrency STRING Base Asset
quantity STRING Position Size (+/-)
instrumentId STRING Market Code i.e. BTC-USD-SWAP-LIN
table STRING Table identifier
timestamp STRING UNIX timestamp

User Order Channel

Request format

{"op": "subscribe", "args": ["order:all"], "tag": 1}
{"op": "subscribe", "args": ["order:BTC-USD"], "tag": 1}

Requires authentication. Get the user's order information.

Channel Name : order:<marketCode>

Update Speed : real-time

Order: OrderOpened

Update format for limit order


{
    "table": "order",
    "data": [
        {
            "notice": "OrderOpened",
            "accountId": "<Your account ID>",
            "marketCode": "BTC-USD-SWAP-LIN",
            "orderId" : "123",
            "clientOrderId": "16",
            "price": "9600",
            "quantity": "2" ,
            "orderType": "LIMIT",
            "side": "BUY",
            "timeInForce": "GTC",
            "status": "OPEN",
            "timestamp": "1594943491077"
        }
    ]
}

Update format for stop-limit order


{
    "table": "order",
    "data": [
        {
            "notice": "OrderOpened",
            "accountId": "<Your account ID>",
            "marketCode": "BTC-USD-SWAP-LIN",
            "orderId": "22",
            "clientOrderId": "16",
            "quantity": "2",
            "orderType": "STOP",
            "side": "BUY",
            "stopPrice": "9280",
            "limitPrice": "9300",
            "status": "OPEN",
            "timestamp": "1594943491077"
        }
    ]
}

Parameters Type Description
notice STRING OrderOpened
accountId STRING Account identifier
marketCode STRING Market Code i.e. BTC-USD-SWAP-LIN
orderId STRING Order ID generated by the server
clientOrderId STRING Client order ID submitted
price STRING Price submitted
quantity STRING Quantity submitted
side STRING BUY / SELL
timeInForce STRING Confirming user setting
status STRING Update status
timestamp STRING UNIX timestamp
orderType STRING Define the order type
stopPrice STRING Stop price submitted
limitPrice STRING Limit price submitted

Order: OrderModified

Update format for modify order

{
    "table": "order",
    "data": [
        {
            "notice": "OrderModified",
            "accountId": "<Your Account ID>",
            "marketCode": "BTC-USD-SWAP-LIN",
            "orderId": "123",
            "clientOrderId": "16",
            "price": "9600",
            "quantity": "1",
            "orderType": "LIMIT",
            "side": "BUY",
            "timeInForce": "GTC",
            "status": "OPEN",
            "timestamp": "1594943491077"
        }
    ]
}

Parameters Type Description
notice STRING OrderModified
accountId STRING Account identifier
marketCode STRING Market Code i.e. BTC-USD-SWAP-LIN
orderId STRING Order ID generated by the server
clientOrderId STRING Client order ID submitted
price STRING Price submitted
quantity STRING Quantity submitted
side STRING BUY / SELL
timeInForce STRING Confirming user setting
status STRING Update status
timestamp STRING UNIX timestamp
orderType STRING Define order type

Order: OrderClosed

Update format for canceled partially by IOC


{
    "table": "order",
    "data": [
        {
          "notice": "OrderClosed",
          "accountId": "<Your account ID>",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "73",
          "clientOrderId": "16",
          "price": "9600",
          "quantity": "2",
          "remainQuantity": "1.5",
          "orderType": "LIMIT",
          "side": "BUY",
          "timeInForce": "IOC",
          "status": "CANCELED_PARTIAL_BY_IOC",
          "timestamp": "1594943491077"
        }
    ]
}


Update format for canceled all by IOC


{
    "table": "order",
    "data": [
        {
          "notice": "OrderClosed",
          "accountId": "<Your account ID>",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "133",
          "clientOrderId": "16",
          "price": "8000",
          "quantity": "2",
          "remainQuantity": "2",
          "orderType": "LIMIT",
          "side": "BUY",
          "timeInForce": "IOC",
          "status": "CANCELED_ALL_BY_IOC",
          "timestamp": "1594943491077"
        }
    ]
}


Update format for cancled by FOK


{
    "table": "order",
    "data": [
        {
          "notice": "OrderClosed",
          "accountId": "1",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "73",
          "clientOrderId": "16",
          "price": "9609",
          "quantity": "2",
          "remainQuantity": "2",
          "orderType": "LIMIT",
          "side": "BUY",
          "timeInForce": "FOK",
          "status": "CANCELED_BY_FOK",
          "timestamp": "1594943491077"
        }
    ]
}

Update format for canceled by maker only


{
    "table": "order",
    "data": [
        {
          "notice": "OrderClosed",
          "accountId": "3",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "7",
          "clientOrderId": "16",
          "price": "9600",
          "quantity": "1",
          "remainQuantity": "1",
          "orderType": "LIMIT",
          "side": "BUY",
          "timeInForce": "MAKER_ONLY",
          "status": "CANCELED_BY_MAKER_ONLY",
          "timestamp": "1594943491077"
        }
    ]
}

Update format for limit order canceled by user


{
    "table": "order",
    "data": [
        {
          "notice": "OrderClosed",
          "accountId": "1",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "13",
          "clientOrderId": "16",
          "price": "9060",
          "quantity": "2",
          "remainQuantity": "0",
          "orderType": "LIMIT",
          "side": "BUY",
          "timeInForce": "GTC",
          "status": "CANCELED_BY_USER",
          "timestamp": "1594943491077"
        }
    ]
}

Update format for stop-limit order canceled by user


{
    "table": "order",
    "data": [
        {
          "notice": "OrderClosed",
          "accountId": "9",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "13",
          "clientOrderId": "16",
          "stopPrice": "9100",
          "limitPrice": "9120",
          "quantity": "2",
          "remainQuantity": "1.5",
          "orderType": "STOP",
          "side": "BUY",
          "timeInForce": "GTC",
          "status": "CANCELED_BY_USER",
          "timestamp": "1594943491077"
        }
    ]
}

Parameters Type Required
notice STRING OrderClosed
accountId STRING Account identifier
clientOrderId STRING Client order ID submitted
marketCode STRING Market Code i.e. BTC-USD-SWAP-LIN
orderId STRING Order ID generated by the server
ordertype STRING Define the order type
price STRING Price submitted
quantity STRING Quantity submitted
remainQuantity STRING Remaining quantity
side STRING BUY / SELL
status STRING Update status
timeInForce STRING Confirming user setting
timestamp STRING UNIX timestamp
stopPrice STRING Stop price submitted
limitPrice STRING Limit price submitted

Order: OrderRejected

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderRejected",
          "quantity": "0",
          "clientOrderID": "13",
          "status": "REJECT_QUANTITY_ZERO",
          "timestamp": "1592496454"
        }
    ]
}

Parameters Type Required
notice STRING OrderRejected
quantity STRING Quantity submitted
status STRING REJECT QUANTITY ZERO
timestamp STRING UNIX timestamp
clientOrderId STRING Client order ID submitted

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderRejected",
          "status": "REJECT_UNKNOW_ORDER_ACTION",
          "timestamp": "1592495554"
        }
    ]
}

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderRejected",
          "status": "REJECT_LIMITE_ORDER_WITH_MARKET_PRICE",
          "timestamp": "1592493454"
        }
    ]
}

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderRejected",
          "clientOrderId": "12",
          "orderType": "STOP",
          "side": "BUY",
          "stopPrice": "9630",
          "limitPrice": "9650",
          "status": "STOP_PRICE_LARGER_THAN_LIMIT_PRICE",
          "timestamp": "1592496774"
        }
    ]
}

Parameters Type Required
notice String OrderRejected
accountId String Account identifier
clientOrderId String Client order ID submitted
orderType string STOP
side String BUY / SELL
status String STOP PRICE LARGER THAN LIMIT PRICE
stopPrice String Stop price submitted
limitPrice String Limit price submitted
timestamp String UNIX timestamp

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderRejected",
          "clientOrderId": "12",
          "orderType": "STOP",
          "side": "SELL",
          "stopPrice": "9800",
          "limitPrice": "9900",
          "status": "STOP_PRICE_LESS_THAN_LIMIT_PRICE",
          "timestamp": "1592496574"
        }
    ]
}

Parameters Type Required
notice String OrderRejected
accountId String Account identifier
clientOrderId String Client order ID submitted
orderType string STOP
side String BUY / SELL
status String STOP PRICE LARGER THAN LIMIT PRICE
stopPrice String Stop price submitted
limitPrice String Limit price submitted
timestamp String UNIX timestamp

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderRejected",
          "orderId": "13",
          "status": "REJECT_CANCEL_ORDER_ID_NOT_FOUND",
          "timestamp": "1592494474"
        }
    ]
}

Parameters Type Required
notice STRING OrderReject
orderId STRING Order ID generated by the server
status STRING REJECT CANCEL ORDER ID NOT FOUND
timestamp STRING UNIX timestamp

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderRejected",
          "orderId": "12",
          "status": "REJECT_AMEND_ORDER_ID_NOT_FOUND",
          "timestamp": "1592498890"
        }
    ]
}

Parameters Type Required
notice STRING OrderRejected
orderId STRING Order ID generated by the server
status STRING REJECT AMEND ORDER ID NOT FOUND
timestamp STRING UNIX timestamp

Order: OrderMatched

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderMatched",
          "accountId": "1",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "39",
          "clientOrderId": "16",
          "matchId": "1",
          "price": "9300",
          "quantity": "2",
          "matchPrice": "9300",
          "matchQuantity": "2",
          "orderMatchType": "MAKER",
          "remainQuantity": "0",
          "orderType": "LIMIT",
          "side": "BUY",
          "timeInForce": "GTC",
          "fees": "3.7",
          "feeInstrumentId": "FLEX",
          "status": "FILLED",
          "timestamp": "1592490254"
        }
    ]
}


Parameters Type Required
notice STRING OrderMatched
accountId STRING Account identifier
marketCode STRING Market Code i.e. BTC-USD-SWAP-LIN
orderId STRING Order ID generated by the server
orderId STRING Order ID generated by the server
clientOrderId STRING Client order ID submitted
price STRING Price submitted
quantity STRING Quantity submitted
remainQuantity STRING Remaining quantity
side STRING BUY / SELL
timeInForce STRING Confirming user setting
status STRING FILL
timestamp STRING UNIX timestamp
orderType STRING LIMIT

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderMatched",
          "accountId": "11",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "13",
          "clientOrderId": "16",
          "matchId": "2",
          "price": "9333",
          "quantity": "2",
          "matchPrice": "9333",
          "matchQuantity": "1",
          "orderMatchType": "MAKER",
          "remainQuantity": "1",
          "orderType": "LIMIT",
          "side": "BUY",
          "timeInForce": "GTC",
          "fees": "1.8",
          "feeInstrumentId": "FLEX",
          "status": "PARTIAL_FILL",
          "timestamp": "1592497054"
        }
    ]
}


Parameters Type Required
notice STRING OrderOpened
accountId STRING Account identifier
orderId STRING Order ID generated by the server
fees STRING Fee amount
feeInstrumentId STRING Fee instrument (e.g. USD)
marketCode STRING Market Code i.e. BTC-USD-SWAP-LIN
matchId STRING Match/trade identifier
matchPrice STRING Traded price
matchQuantity STRING Traded quantity
orderId STRING Order ID generated by the server
orderMatchType STRING MAKER/TAKER
orderType STRING LIMIT
price STRING Price submitted
quantity STRING Quantity submitted
remainQuantity STRING Remaining quantity
side STRING BUY / SELL
status STRING PARTIAL_FILL
timeInForce STRING Confirming user setting
timestamp STRING UNIX timestamp

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderMatched",
          "accountId": "7",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "12",
          "clientOrderId": "16",
          "matchId": "1",
          "stopPrice": "9700",
          "limitPrice": "9650",
          "quantity": "3",
          "matchPrice": "9650",
          "matchQuantity": "1",
          "orderMatchType": "MAKER",
          "remainQuantity": "2",
          "orderType": "STOP",
          "side": "BUY",
          "timeInForce": "GTC",
          "fees": "1.9",
          "feeInstrumentId": "FLEX",
          "status": "PARTIAL_FILL",
          "timestamp": "15924979954"
        }
    ]
}

Parameters Type Required
notice STRING OrderOpened
accountId STRING Account identifier
clientOrderId STRING Client order ID submitted
marketCode STRING Fee instrument (e.g. USD)
orderId STRING Order ID generated by the server
matchId STRING Match/trade identifier
stopPrice STRING Stop price submitted
limitPrice STRING Limit price submitted
quantity STRING Quantity submitted
matchPrice STRING Traded price
matchQuantity STRING Traded quantity
orderMatchType STRING MAKER/TAKER
remainQuantity STRING Remaining quantity
side STRING BUY / SELL
timeInForce STRING Confirming user setting
status STRING PARTIAL_FILL
timestamp STRING UNIX timestamp
fees STRING Fee amount
feeInstrumentId STRING Fee instrument (e.g. USD)
orderType STRING STOP

Notification:


{
    "table": "order",
    "data": [
        {
          "notice": "OrderMatched",
          "accountId": "1",
          "marketCode": "BTC-USD-SWAP-LIN",
          "orderId": "123",
          "clientOrderId": "16",
          "matchId": "1",
          "stopPrice": "9700",
          "limitPrice": "9650",
          "quantity": "2",
          "matchPrice": "9650",
          "matchQuantity": "2",
          "orderMatchType": "MAKER",
          "remainQuantity": "0",
          "orderType": "STOP",
          "side": "BUY",
          "timeInForce": "GTC",
          "fees": "3.8",
          "feeInstrumentId": "FLEX",
          "status": "FILLED",
          "timestamp": "15924979954"
        }
    ]
}

Parameters Type Required
notice STRING OrderMatched
accountId STRING Account identifier
marketCode STRING Market Code i.e. BTC-USD-SWAP-LIN
orderId STRING Order ID generated by the server
clientOrderId STRING Client order ID submitted
matchId STRING Match/trade identifier
stopPrice STRING Stop price submitted
limitPrice STRING Limit price submitted
quantity STRING Quantity submitted
matchPrice STRING Traded price
matchQuantity STRING Traded quantity
orderMatchType STRING MAKER/TAKER
remainQuantity SSTRING Remaining quantity
side STRING BUY / SELL
timeInForce STRING Confirming user setting
status STRING FILLED
timestamp STRING UNIX timestamp
fees STRING Fee amount
feeInstrumentId STRING Fee instrument (e.g. USD)
orderType STRING STOP

Subscriptions - Public

Orderbook Depth

Request

{
  "op": "subscribe",
  "args": ["futures/depth:BTC-USD-190628"]
}

Response

{
    "table": "futures/depth",
    "data": [{
        "asks": [
            ["5556.82", "11", "0", "0"],
            ["5556.84", "98", "0", "0"],
            ["5556.92", "1", "0", "0"],
            ["5557.6", "4", "0", "0"],
            ["5557.85", "2", "0", "0"]
        ],
        "bids": [
            ["5556.81", "1", "0", "0"],
            ["5556.8", "2", "0", "0"],
            ["5556.79", "1", "0", "0"],
            ["5556.19", "100", "0", "0"],
            ["5556.08", "2", "0", "0"]
        ],
        "instrumentId": "BTC-USD-190628",
        "timestamp": "2019-05-06T07:19:39.348Z"
    }]
}

Description

futures/depth is channel name ,BTC-USD-190628 is instrumentId

bids and asks value example:

["411.8", "10", "0", "0"] 411.8 is the price; 10 is the quantity.

Parameters Parameters Types Description
bids List Buy side depth
instrumentId String Contract ID,e.g .BTC-USD-170310 ,BTC-USDT-191227
asks List Sell side depth
timestamp String UNIX timestamp

Trade

Request format


{"op": "subscribe", "args": ["trade:BTC-USD-SWAP-LIN"], "tag": 1}

Success response format


{"event": "subscribe", "channel": ["trade:BTC-USD-SWAP-LIN"], "success": true, "tag": "1", "timestamp": "1594299886880"}

Failure response format


{"event": "subscribe", "message": "<errorMessage>", "code": "<code>", "success": false, "tag": "1", "timestamp": "1594299886880"}

Channel update format


{
    "table": "trade",
    "data": [{
        "side": "buy",
        "tradeId": "2778148208082945",
        "price": "5556.91",
        "quantity": "5",
        "marketCode": "BTC-USD-190628",
        "timestamp": "1594299886890"
    }]
}

The trade channel pushes the matched order data.

Channel Name : trade:<marketCode>

Update Speed : real-time

Request Parameters Type Required Description
tag INTEGER NO Iff given and non-zero, it will be echoed in the reply.
Update Parameters Type Description
tradeId STRING Transaction Id
price STRING Matched price
quantity STRING Matched quantity
side STRING Matched side
timestamp STRING Matched timestamp
marketCode STRING Market code i.e BTC-USD

Ticker

Request format


{"op": "subscribe", "args": ["ticker:BTC-USD-200925-LIN"], "tag": 1}

Success response format


{"event": "subscribe", "channel": ["ticker:BTC-USD-200925-LIN"], "success": true, "tag": "1", "timestamp": "1594299886890"}

Failure response format


{"event": "subscribe", "message": "<errorMessage>", "code": "<code>", "success": false, "tag": "1", "timestamp": "1594299886890"}

Channel update format


{
    "table": "ticker",
    "data": [
        {
            "marketCode": "BTC-USD-SWAP-LIN",
            "last": "43.259",
            "markPrice": "11012.80409769",
            "open24h": "49.375",
            "volume24h": "11295421",
            "currencyVolume24h": "1225512",
            "high24h": "49.488",
            "low24h": "41.649",
            "openInterest": "1726003",
            "lastQty": "1",
            "timestamp": "123443563454"
        }
    ]
}

The ticker channel pushes the general information about the contract.

Channel Name : ticker:<marketCode>

Update Speed : 100ms

Request Parameters Type Required Description
tag INTEGER NO Iff given and non-zero, it will be echoed in the reply.
Update Parameters Type Description
marketCode STRING Market code i.e BTC-USD
last STRING Last traded price
markPrice STRING Matched quantity
open24h STRING 24 hour rolling opening price
volume24h STRING 24 hour rolling trading volume in counter currency
currencyVolume24h STRING 24 hour rolling trading volume in base currency
high24h STRING 24 hour highest price
low24h STRING 24 hour lowest price
openInterest STRING Open Interest
lastQty STRING Last traded price amount
timestamp STRING Timestamp

Candles

Request format


{"op": "subscribe", "args": ["candles60s:BTC-USD-SWAP-LIN"], "tag": 1}

Success response format


{"event": "subscribe", "channel": ["candles60s:BTC-USD-SWAP-LIN"], "success": true, "tag": "1", "timestamp": "1594313762698"}

Failure response format


{"event": "subscribe", "message": "<errorMessage>", "code": "<code>", "success": false, "tag": "1", "timestamp": "1594313762698"}

Channel update format


{
    "table": "candle60s",
    "data": [
        {
            "candle": [
                "1594313762698", //timestamp
                "9633.1",        //open
                "9693.9",        //high
                "9238.1",        //low
                "9630.2",        //close
                "45247",         //volume
                "5.3"            //currencyVolume
            ],
            "marketCode": "BTC-USD-SWAP-LIN"
        }
    ]
}

The candles channel pushes the K-line.

Channel Name : candles<granularity>:<marketCode>

Update Speed : 500ms

Granularity : 60s, 180s, 300s, 900s, 1800s, 3600s, 7200s, 14400s, 21600s, 43200s, 86400s

Request Parameters Type Required Description
tag INTEGER NO Iff given and non-zero, it will be echoed in the reply.
Update Parameters Type Description
marketCode STRING Market code i.e BTC-USD
candle STRING Timestamp, open price, highest price, lowest price, close price, trading volume in counter currency, and trading volume in base currency

REST API

TEST site

LIVE site

For clients who do not wish to take advantage of CoinFLEX's native WebSocket API, CoinFLEX offers a RESTful API that implements much of the same functionality.

Authentication

Request

import requests
import hmac
import base64
import hashlib
import datetime
from urllib.parse import urlencode

rest_url = 'https://v2stgapi.coinflex.com'
rest_path = 'v2stgapi.coinflex.com'

api_key = API-KEY
api_secret = API-SECRET

body = urlencode({'key1': 'value1', 'key2': 'value2'})
ts = datetime.datetime.utcnow().isoformat()
nonce = 123

if body:
    path = '/v2/positions?' + body
    msg_string = '{}\n{}\n{}\n{}\n{}\n{}'.format(ts, nonce, 'GET', rest_path, '/v2/positions', body)
else:
    path = '/v2/positions'
    msg_string = '{}\n{}\n{}\n{}\n{}\n'.format(ts, nonce, 'GET', rest_path, '/v2/positions')

sig = base64.b64encode(hmac.new(api_secret.encode('utf-8'), msg_string.encode('utf-8'), hashlib.sha256).digest()).decode('utf-8')

header = {'Content-Type': 'application/json', 'AccessKey': api_key,
          'Timestamp': ts, 'Signature': sig, 'Nonce': str(nonce)}

resp = requests.get(rest_url + path, headers=header)
print(resp.json())

Public market data methods do not require authentication, however private methods require a Signature to be sent in the header of the request. These private REST methods use HMAC SHA256 signatures.

The HMAC SHA256 signature is a keyed HMAC SHA256 operation using a clients API Secret as the key and a message string as the value for the HMAC operation.

The message string is constructed by the following formula:-

msgString = Timestamp + "\n" + Nonce + "\n" + Verb + "\n" + URL + "\n" + Path +"\n" + Body

Component Required Example Description
Timestamp Yes 2020-04-30T15:20:30 YYYY-MM-DDThh:mm:ss
Nonce Yes 123 User generated
Verb Yes 'GET'
Path Yes 'v2stgapi.coinflex.com'
Method Yes '/v2/positions Available REST methods:
  • V2/positions
  • V2/orders
  • V2/balances
  • Body No instrumentID=BTC-USD-SWAP-LIN Optional and dependent on the REST method being called

    The constructed message string should look like:-

    2020-04-30T15:20:30\n 123\n GET\n v2stgapi.coinflex.com\n /v2/positions\n instrumentID=BTC-USD-SWAP-LIN

    Note the newline characters after each component in the message string. If Body is ommitted it's treated as an empty string.

    Finally you must use the HMAC SHA256 operation to get the hash value using the API Secret as the key and the constructed message string as the value for the HMAC operation. Then encode this hash value with BASE-64. This output becomes the signature for the specified authenticated REST API method.

    The signature must then be included in the header of the REST API call like so:

    header = {'Content-Type': 'application/json', 'AccessKey': API-KEY, 'Timestamp': TIME-STAMP, 'Signature': SIGNATURE, 'Nonce': NONCE}

    Methods - Private

    GET /v2/accountinfo

    Request

    GET/v2/accountinfo
    

    Response

    {
        "event": "accountinfo",
        "success": true,
        "message": null,
        "code": "0000",
        "data":[
            {
                "accountId": "123",
                "tradeType": "LINEAR",
                "marginCurrency": "USD",
                "totalBalance": "10000",
                "collateralBalance": "10000",
                "availableBalance": "10000",
                "portfolioVarMargin": "500",
                "riskRatio": "20.0000",
                "timestamp": "1235445"
            } 
        ]
    }
    

    Requires authentication. GET your account info.

    Response Parameter Type Description
    accountId STRING Account ID
    tradeType STRING Account type
    marginCurrency STRING Asset e.g. 'USD'
    totalBalance STRING Total balance denoted in marginCurrency
    collateralBalance STRING Collateral balance with LTV applied
    availableBalance STRING Available balance
    portfolioVarMargin STRING Portfolio margin
    riskRatio STRING collateralBalance / portfolioVarMargin, Orders are rejected/cancelled if the risk ratio drops below 1 and liquidation occurs if the risk ratio drops below 0.5
    timestamp STRING UNIX timestamp

    GET /v2/balances

    Request

    GET/v2/balances
    

    Response

    {
        "event": "balances",
        "accountId": "<Your Account ID>",
        "timestamp": "1593627419000",
        "tradeType": "LINEAR"|"INVERSE",
        "data":[
        {   
            "instrumentId": "BTC",
            "total": "4468.823",              
            "available": "4468.823",        
            "reserved": "0",
            "quantityLastUpdated": "1593627415234"
        },
        ...
        {
            "instrumentId": "EOS",
            "total": "1585.890",              
            "available": "325.890",         
            "reserved": "1260",
            "quantityLastUpdated": "1593627415123"
        }
        ]
    }
    

    Requires authentication. GET coin balances in your account.

    Response Parameter Type Description
    accountId STRING Account ID
    timestamp STRING Timestamp of this response
    tradeType STRING Define this account is trading linear or inverse derivatives
    instrumentId STRING Token symbol, e.g. 'BTC'
    total STRING Total balance
    available STRING Available balance
    reserved STRING Reserved balance (unavailable)
    quantityLastUpdated STRING Timestamp when was balance last updated

    GET /v2/balances/<instrumentId>

    Request

    GET/v2/balances/BTC
    

    RESPONSE

    {
        "event": "balancesById",
        "accountId": "<Your Account ID>",
        "timestamp": "1593627415293",
        "tradeType": "LINEAR"|"INVERSE",
        "data":[
        {   
            "instrumentId": "BTC",
            "total": "4468.823",              
            "available": "4468.823",        
            "reserved": "0",
            "quantityLastUpdated": "1593627415001"
        }
        ]
    }
    

    Requires authentication. GET balance for a specific coin.

    Response Parameters Type Description
    accountId STRING Account ID
    timestamp STRING Timestamp of this response
    tradeType STRING Define this account is trading linear or inverse derivatives
    instrumentId STRING Token symbol, e.g. 'BTC'
    total STRING Total balance
    available STRING Available balance
    reserved STRING Reserved balance (unavailable)
    quantityLastUpdated STRING Timestamp when was balance last updated

    GET /v2/positions

    Request

    GET/v2/positions
    

    RESPONSE

    {
        "event": "positions",
        "accountId":"<Your Account ID>",
        "timestamp":"1593627415000",
        "data": [
            {
                "instrumentId": "BTC-USD-200626-LIN",
                "quantity": "0.94",
                "lastUpdated": "1592486212218",
                "contractValCurrency": "BTC",
                "entryPrice": "7800.00",       
                "positionPnl": "200.3",
                "estLiquidationPx": "6301.1",
                "estLiqPrice": "2342.2"                  
            },
            ...
        ]
    }
    

    Requires authentication. GET all positions for current user.

    Response Parameters Type Description
    accountId STRING Account ID
    timestamp STRING Timestamp of this response
    instrumentId STRING Contract symbol, e.g. 'BTC-USD-200626-LIN'
    lastUpdated STRING Timestamp when position was last updated
    contractValCurrency STRING Contract valuation currency
    entryPrice STRING Average entry price
    positionPnl STRING Postion profit and lost
    estLiquidationPx STRING
    estLiqPrice STRING Estimated liquidation price

    GET /v2/positions/<instrumentId>

    Request

    GET/v2/positions/BTC-USD-200626-LIN
    

    RESPONSE

    {
        "event": "positionsById",
        "accountId":"<Your Account ID>",
        "timestamp":"1593617005438",
        "data": [
            {
                "instrumentId": "BTC-USD-200626-LIN",
                "quantity": "0.94",
                "lastUpdated": "1592486212218",
                "contractValCurrency": "BTC",
                "entryPrice": "7800.00",       
                "positionPnl": "200.3",
                "estLiquidationPx": "6301.1",
                "estLiqPrice": "2342.2"                  
            }
        ]
    }
    

    Requires authentication. GET specific positions for current user.

    Response Parameters Type Description
    accountId STRING Account ID
    timestamp STRING Timestamp of this response
    instrumentId STRING Contract symbol, e.g. 'BTC-USD-200626-LIN'
    lastUpdated STRING Timestamp when position was last updated
    contractValCurrency STRING Contract valuation currency
    entryPrice STRING Average entry price
    positionPnl STRING Postion profit and lost
    estLiquidationPx STRING
    estLiqPrice STRING Estimated liquidation price

    GET /v2/trades/{marketCode}

    Request

    GET/v2/trades/{marketCode}?limit={limit}&startTime={startTime}&endTime{endTime}
    

    RESPONSE

    {
      "event": "trades", 
      "timestamp": "1595635101845", 
      "accountId": "<Your Account ID>", 
      "data": [
        {
        "matchId": "160067484555913077", 
        "matchTimestamp": "1595514663626", 
        "marketCode": "BTC-USD-SWAP-LIN", 
        "matchQuantity": "0.010000000", 
        "matchPrice": "9680.000000000", 
        "total": "96.800000000000000000", 
        "orderMatchType": "TAKER", 
        "fees": "0.009600000", 
        "feeInstrumentId": "FLEX", 
        "orderId": "160067484555913076", 
        "side": "SELL", 
        "clientOrderId": "123"
       },
    ...
    ]
    }
    
    

    Requires authentication. Get most recent trades of current user.

    Request Parameters Type Required Description
    marketCode STRING YES
    limit LONG NO Default 500, max 1000
    startTime LONG NO
    endTime LONG NO
    Response Parameters Type Description
    accountId STRING Account ID
    timestamp STRING Timestamp of this response
    matchId STRING Match ID
    matchTimestamp STRING Order Matched timestamp
    marketCode STRING Market code
    matchQuantity STRING Match quantity
    matchPrice STRING Match price
    total STRING Total price
    side STRING Side of the match
    orderMatchType STRING Define taker or maker
    fees STRING fees
    feeInstrumentId STRING Instrument ID of the fees
    orderId STRING Order ID generated by the server
    clientOrderID STRING Client order ID generated by the user

    GET /v2/orders

    Request

    GET/v2/orders
    

    RESPONSE

    {
        "event": "orders",
        "accountId":"<Your Account ID>",
        "timestamp":"1593617005438",
        "data":[
           {
              "orderId": "160039151345856176",
              "marketCode": "BTC-USD-200626-LIN",
              "clientOrderId": null|"<clientOrderId>",              
              "side": "BUY",
              "orderType": "LIMIT"|"STOP",
              "quantity": "1.00",
              "remainQuantity": "1.00",
              "price": "1.00"|null,               #for limit order, null for stop order
              "stopPrice": "<stopPrice>"|null,    #for stop order, null for limit order 
              "limitPrice": "《limitPrice>"|null,    #for stop order, null for limit order 
              "orderCreated": "1593617008698",
              "lastModified": "1593617008698",      
              "lastTradeTimestamp": "1593617008698",
              "timeInForce": "GTC"
          },
          ...
      ]
    }
    
    

    Requires authentication. Get all open orders of current user.

    Response Parameters Type Description
    accountId STRING Account ID
    timestamp STRING Timestamp of this response
    orderId STRING Order ID which generated by the server
    marketCode STRING Market code
    clientOrderId STRING Client order ID which given by the user
    side STRING Side of the order
    orderType STRING Type of the order
    quantity STRING Quantity submitted
    remainQuantity STRING Remainning quantity
    price STRING Price submitted
    stopPrice STRING Stop price for the stop order
    limitPrice STRING Limit price for the stop limit order
    orderCreated STRING Timestamp when order was created
    lastModified STRING Timestamp when order was last mordified
    lastTradeTimestamp STRING Timestamp when order was last traded
    timeInForce STRING Time in force

    DELETE /v2/cancel/orders

    Request

    DELETE/v2/cancel/orders 
    

    RESPONSE

    {
        "event": "orders",
        "accountId": "<AccountID>",
        "timestamp": "1594412077100",
        "data":[
           {
              "msg": "All open orders for the account have been queued for cancellation"
           }
        ]
    }
    
    

    Requires authentication. Cancel all open orders.

    DELETE /v2/cancel/orders/{marketCode}

    Request

    DELETE/v2/cancel/orders/BTC-USD
    

    RESPONSE

    {
        "event": "orders",
        "accountId": "<AccountID>",
        "marketCode": "BTC-USD",
        "timestamp": "1594412077100",
        "data":[
          {
              "msg": "All open orders for the specified market have been queued for cancellation"
          }
        ]
    }
    

    Requires authentication. Cancel all open orders for a specific market code.

    GET /v2.1/delivery/orders

    Request

    GET/v2.1/delivery/orders
    

    RESPONSE

    {
        "event": "deliverOrders",
        "timestamp": 1596685339910,
        "data": [
            {
                "timestamp": "1595781719394",
                "instrumentId": "BTC-USD-SWAP-LIN",
                "status": "DELIVERED",
                "quantity": null,
                "deliverPrice": "9938.480000000",
                "transferAsset": "USD",
                "transferQty": "993.848000000",
                "instrumentIdDeliver": "BTC",
                "deliverQty": "0.100000000",
                "deliverOrderId": "575770851486007299",
                "clientOrderId": null
            },
            {
                "timestamp": "1595786511155",
                "instrumentId": "BTC-USD-SWAP-LIN",
                "status": "CANCELLED",
                "quantity": null,
                "deliverPrice": "9911.470000000",
                "transferAsset": "USD",
                "transferQty": "0.000000000",
                "instrumentIdDeliver": "BTC",
                "deliverQty": "0.000000000",
                "deliverOrderId": "575786553086246913",
                "clientOrderId": null
            },
        ]
    }
    

    Requires authentication. Get entire delivery history.

    Response Parameters Type Description
    timestamp STRING UNIX Timestamp of the response
    deliverOrderId STRING Order id
    clientOrderId Null Type null
    quantity Null Type null
    instrumentId STRING Perpetual swap market code
    deliverPrice STRING Mark price at delivery
    instrumentIdDeliver STRING Asset being received: long position = coin, short position = USD
    deliverQty STRING Quantity of the received asset
    transferAsset STRING Asset being sent
    transferQty STRING Quantity being sent
    auctionTime STRING UNIX timestamp of the next auction
    status STRING Request status

    POST /v2.1/delivery/orders

    Request

    POST/v2.1/delivery/orders
    
    # Request body
    {
        "instrumentId": "BTC-USD-SWAP-LIN",
        "qtyDeliver": "1"
    }
    

    RESPONSE

    {
        "event": "delivery",
        "timestamp": "1599204123484",
        "accountId": "164",
        "data": [{
            "deliverOrderId": "586985384617312258",
            "accountId": "164",
            "clientOrderId": null,
            "instrumentId": "BTC-USD-SWAP-LIN",
            "deliverPrice": "10000.000000000",
            "deliverPosition": "1.000",
            "deliverType": "NEXT_CYCLE",
            "instrumentIdDeliver": "BTC",
            "deliverQty": "1.000",
            "remainingQty": "1.000",
            "remainingPosition": "1.000",
            "transferAsset": "USD",
            "transferQty": "1",
            "auctionTime": "1599204122693",
            "created": "1599204122693",
            "lastUpdated": "1599204122693",
            "status": "PENDING"
        }]
    }
    

    Requires authentication. Submits a delivery request for a specified market and size.

    Response Parameters Type Description
    timestamp STRING UNIX Timestamp of the response
    accountId STRING Account ID
    deliverOrderId STRING Order id
    clientOrderId Null Type null
    instrumentId STRING Perpetual swap market code
    deliverPrice STRING Mark price at delivery
    deliverPosition STRING Delivered position size
    deliverType STRING ‘NEXT_CYCLE’: Queueing for the upcoming auction
    instrumentIdDeliver STRING Asset being received: long position = coin, short position = USD
    deliverQty STRING Quantity of the received asset
    remainingQty STRING Remaining quantity
    remainingPosition STRING Remaining position
    transferAsset STRING Asset being sent
    transferQty STRING Quantity being sent
    auctionTime STRING UNIX timestamp of the next auction
    created STRING UNIX timestamp
    lastUpdated STRING UNIX timestamp
    status STRING Delivery status

    DELETE /v2.1/delivery/orders/{deliveryOrderId}

    Request

    DELETE/v2.1/delivery/orders/{deliveryOrderId}
    

    SUCCESSFUL RESPONSE

    {
        "event": "delivery",
        "timestamp": "1599204310297",
        "accountId": "164",
        "data": [
           "Cancel of user order was successful"
        ]
    }
    

    FAILED RESPONSE

    {
        "event": "delivery",
        "timestamp": "1599204310297",
        "accountId": "164",
        "data": [
           "Cancel exception please try again"
        ]
    }
    

    Requires authentication. Cancels a pending delivery.

    GET /v2.1/deliver-auction/{instrumentId}

    Request

    GET/v2.1/deliver-auction
    GET/v2.1/deliver-auction/<instrumentId>
    

    RESPONSE

    {
        "event": "deliverAuction",
        "timestamp": "1596620815090",
        "data": [
            {
                "instrumentId": "BTC-USD-SWAP-LIN",
                "auctionTime": "1596620805000",
                "netDeliver": "-5.100000000",
                "estFundingRate": "0.0001"
            },
          ...
        ]
    }
    

    Requires authentication. Get entire delivery history.

    Response Parameters Type Description
    timestamp STRING UNIX Timestamp of the response
    instrumentId STRING Market code
    auctionTime STRING UNIX timestamp of the next auction
    netDeliver STRING Delivery imbalance (negative = more longs than shorts and vice versa)
    estFundingRate STRING Estimated funding rate a positive rate means longs pay shorts

    Methods - Public

    GET /v2/all/markets

    Request

    GET/v2/all/markets`
    

    RESPONSE

    {
        "event": "markets",
        "timestamp": "1593617005438",
        "data": [
            {
                "marketCode": "BTC-USD",
                "name": "BTC/USD Spot",
                "referencePair": "BTC/USD",
                "base": "BTC",
                "counter": "USD",
                "type": "SPOT",
                "tickSize": "0.1",
                "qtyIncrement": "0.001",
                "listingDate": "-2208988800000",
                "endDate": null,
                "marginCurrency": null,
                "contractValCurrency": "BTC",
                "upperPriceBound": "11000.00",
                "lowerPriceBound": "9000.00",
                "marketPrice": "10000.00"
            },
            ...
        ]
    }
    

    Get a list of all available markets on CoinFlex.

    Response Parameters Type Description
    timestamp STRING Timestamp of this response
    marketCode STRING Market Code
    name STRING Name of the contract
    referencePair STRING Reference pair
    base STRING Base asset
    counter STRING Counter asset
    type STRING Type of the contract
    tickSize STRING Tick size of the contract
    qtyIncrement STRING Minimum increamet quantity
    listingDate STRING Listing date of the contract
    endDate STRING Ending date of the contract
    marginCurrency STRING Margining currency
    contractValCurrency STRING Contract valuation currency
    upperPriceBound STRING Upper price bound
    lowerPriceBound STRING Lower price bound
    marketPrice STRING Market price

    GET /v2/all/assets

    Request

    GET/v2/all/assets
    

    RESPONSE

    {
        "event": "assets",
        "timestamp":"1593617008698",
        "data": [
            {
                "instrumentId": "BTC-USD-200626-LIN",
                "name": "BTC/USD 20-06-26 Future (Linear)",
                "base": "BTC",
                "counter": "USD",
                "type": "FUTURE",
                "marginCurrency": "USD",
                "contractValCurrency": "BTC",
                "deliveryDate": null,
                "deliveryInstrument": null
            },
            {
                "instrumentId": "BTC",
                "name": "Bitcoin",
                "base": null,
                "counter": null,
                "type": "SPOT",
                "marginCurrency": null,
                "contractValCurrency": null,
                "deliveryDate": null,
                "deliveryInstrument": null
            }
        ]
    }
    

    Get a list of all assets available on CoinFLEX. These include coins and bookable contracts.

    Response Parameters Type Description
    timestamp STRING Timestamp of this response
    instrumentId STRING Instrument ID
    name STRING Name of the asset
    base STRING Base of the asset
    counter STRING Counter of the asset
    type STRING type of the asset
    marginCurrency STRING Margining currency
    contractValCurrency STRING Contract valuation currency
    deliveryDate STRING Delivery date
    deliveryInstrument STRING Delivery instrument

    GET /v2/publictrades/{marketCode}

    Request

    GET/v2/publictrades/{marketCode}?limit={limit}&startTime={startTime}&endTime{endTime}
    

    RESPONSE

    {
      "event": "publicTrades", 
      "timestamp": "1595636619410", 
      "marketCode": "BTC-USD-SWAP-LIN", 
      "data": [
        {
          "matchId": "160070803925856675", 
          "matchQuantity": "0.100000000", 
          "matchPrice": "9600.000000000", 
          "side": "BUY", 
          "matchTimestamp": "1595585860254"
          },
          ...
          ]
    }
    
    

    Get most recent trades.

    Request Parameters Type Required Description
    marketCode STRING YES
    limit LONG NO Default 100, max 300
    startTime LONG NO
    endTime LONG NO
    Response Parameters Type Description
    timestamp STRING Timestamp of this response
    marketCode STRING
    matchID STRING
    matchQuantity STRING
    matchPrice STRING
    side STRING
    matchTimestamp STRING

    GET /v2/ticker

    Request

    GET/v2/ticker
    

    RESPONSE

    {
      "event":"ticker",
      "timestamp":"123443563454",
      "data" :
      [
          {
                "marketCode": "BTC-USD-SWAP-LIN",
                "last": "43.259", 
                "markPrice": "11012.80409769",  
                "open24h": "49.375",
                "volume24h": "11295421",
                "currencyVolume24h": "1025.7",                       
                "high24h": "49.488",
                "low24h": "41.649",
                "openInterest": "1726003",
                "lastQty": "1"
          },
          ...
      ]
    }
    
    

    Get a list of all of the tickers.

    Response Parameters Type Description
    timestamp STRING Timestamp of this response
    marketCode STRING "BTC-USD-SWAP-LIN",
    last STRING Last traded price
    markPrice STRING Mark price
    open24h STRING Daily opening price
    volume24h STRING 24 hour volume (USD)
    currencyVolume24h STRING 24 hour volume (coin)
    high24h STRING 24 hour high
    low24h STRING 24 hour low
    openInterest STRING Current open interest
    lastQty STRING Last traded quantity