• Yes, requires OpenSSL
  • No, only Blocking mode
  • Yes, Requires Win8.+

CEX.IO WebSocket API

 sgcWebSockets API Cex components

From sgcWebSockets 4.1.10 CEX.IO WebSocket API is supported. CEX is a cryptocurrency exchange and former Bitcoin cloud mining provider.

WebSocket API allows getting real-time notifications without sending extra requests, making it a faster way to obtain data from the exchange

Cex component has a property called Cex where you can fill API Keys provided by Cex to get access to your account data.

 

Message encoding

All messages are encoded in JSON format.

Prices are presented as strings to avoid rounding errors at JSON parsing on client side

Compression of WebSocket frames is not supported by server.

Time is presented as integer UNIX timestamp in seconds.

 

Authentication

To get access to CEX.IO WebSocket data, you should be authorized.

 

Log in to CEX.IO account.

Go to https://cex.io/trade/profile#/api page.

Select type of required permissions.

Click "Generate Key" button and save your secret key, as it will become inaccessible after activation.

Activate your key.

 

Connectivity

 

If a connected Socket is inactive for 15 seconds, CEX.IO server will send a PING message.

Only server can be an Initiator of PING request.

Server sends ping only to authenticated user.

The user has to respond with a PONG message. Otherwise, the WebSocket will be DISCONNECTED. This is handled automatically by library.

For authenticated user, in case there is no notification or ping from server within 15 seconds, it would be safer to send a request like 'ticker' or 'get-balance' and receive response, in order to ensure connectivity and authentication.

 

 

Public Channels

These channels don't require to Authenticate before. Responses from server are received by OnCexMessage event. 

 

SubscribeTickers: Ticker feed with only price of transaction made on all pairs (deprecated)

 

{

    "e": "tick",

    "data": {

        "symbol1": "BTC",

        "symbol2": "USD",

        "price": "428.0123"

    }

}

 

SubscribeChart: OHLCV chart feeds with Open, High, Low, Close, Volume numbers (deprecated)

 

{

    'e': 'ohlcv24',

    'pair': 'BTC:USD',

    'data': [

        '418.2936',

        '420.277',

        '412.09',

        '416.9778',

        '201451078368'

    ]

}

 

Subscribe Pair: Market Depth feed (deprecated)

 

{

    'e': 'md_groupped', 

    'data': {

        'pair': 'BTC:USD',

        'id': 11296131,

        'sell': {

            '427.5000': 1000000,

            '480.0000': 263544334,

            ...

        },

        'buy': {

            '385.0000': 3630000,

            '390.0000': 1452458642,

            ... 400+ pairs togather with 'sell' pairs

        }

    }

}

 

Subscribe Pair: Order Book feed (deprecated)

 

{

    'e': 'md', 

    'data': {

        'pair': 'BTC:USD',

        'buy_total': 63221099,

        'sell_total': 112430315118,

        'id': 11296131,

        'sell': [

            [426.45, 10000000],

            [426.5, 66088429300],

            [427, 1000000],

            ... 50 pairs overaall

        ],

        'buy': [

            [423.3, 4130702],

            [423.2701, 10641168],

            [423.2671, 1000000],

            ... 50 pairs overaall

        ]

    }

}

 

Private Channels

To access this channels, first call Authenticate method. Responses from server are received by OnCexMessage event. 

 

GetTicker

 

{

    "e": "ticker",

    "data": {

        "timestamp": "1471427037",

        "low": "290",

        "high": "290",

        "last": "290",

        "volume": "0.02062068",

        "volume30d": "14.38062068",

        "bid": 240,

        "ask": 290,

        "pair": [

            "BTC",

            "USD"

        ]

    },

    "oid": "1471427036908_1_ticker",

    "ok": "ok"

}

 

GetBalance

 

{

    "e": "get-balance",

    "data": {

           "balance": {

            'LTC': '10.00000000', 

            'USD': '1024.00',

            'RUB': '35087.98', 

            'EUR': '217.53', 

            'GHS': '10.00000000',

            'BTC': '9.00000000'

        },

           "obalance": {

              'BTC': '0.12000000',

              'USD': "512.00",

           },

       },

       "time": 1435927928597

    "oid": "1435927928274_2_get-balance",

    "ok": "ok"

}

 

SubscribeOrderBook

 

{

"e": "order-book-subscibe",

"data": {

   "timestamp": 1435927929,

   "bids": [

      [

         241.947,

         155.91626

      ],

      [

         241,

         981.1255

      ],

   ],

   "asks": [

      [

         241.95,

         15.4613

      ],

      [

         241.99,

         17.3303

      ],

   ],

   "pair": "BTC:USD",

   "id": 67809

},

"oid": "1435927928274_5_order-book-subscribe",

"ok": "ok"

}

 

UnSubscribeOrderBook

 

{

"e": "order-book-unsubscribe",

"data": {

   "pair": "BTC:USD"

},

"oid": "1435927928274_4_order-book-unsubscribe",

"ok": "ok"

}

 

 

GetOpenOrders

 

{

"e": "open-orders",

"data": [

   {

      "id": "2477098",

      "time": "1435927928618",

      "type": "buy",

      "price": "241.9477",

      "amount": "0.02000000",

      "pending": "0.02000000"

   },

   {

      "id": "2477101",

      "time": "1435927928634",

      "type": "sell",

      "price": "241.9493",

      "amount": "0.02000000",

      "pending": "0.02000000"

   }

],

"oid": "1435927928274_9_open-orders",

"ok": "ok"

}

 

 

PlaceOrder

 

{

"e": "place-order",

"data": {

   "complete": false,

   "id": "2477098",

   "time": 1435927928618,

   "pending": "0.02000000",

   "amount": "0.02000000",

   "type": "buy",

   "price": "241.9477"

},

"oid": "1435927928274_7_place-order",

"ok": "ok"

}

 

 

CancelReplaceOrder

 

{

"e": "cancel-replace-order",

"data": {

   "complete": false,

   "id": "2689009",

   "time": 1443464955904,

   "pending": "0.04000000",

   "amount": "0.04000000",

   "type": "buy",

   "price": "243.25"

},

"oid": "1443464955209_16_cancel-replace-order",

"ok": "ok"

}

 

GetOrderRequest

 

In CEX.IO system, orders can be present in trade engine or in archive database. There can be time periods (~2 seconds or more), when order is done/canceled, but still not moved to archive database. That means, you cannot see it using calls: archived-orders/open-orders. This call allows to get order information in any case. Responses can have different format depending on orders location.

 

{

"e": "get-order",

"data": {

   "user": "XXX",

   "type": "buy",

   "symbol1": "BTC",

   "symbol2": "USD",

   "amount": "0.02000000",

   "remains": "0.02000000",

   "price": "50.75",

   "time": 1450214742160,

   "tradingFeeStrategy": "fixedFee",

   "tradingFeeBuy": "5",

   "tradingFeeSell": "5",

   "tradingFeeUserVolumeAmount": "nil",

   "a:USD:c": "1.08",

   "a:USD:s": "1.08",

   "a:USD:d": "0.00",

   "status": "a",

   "orderId": "5582060"

},

"oid": "1450214742135_10_get-order",

"ok": "ok"

}

 

CancelOrderRequest

 

{

"e": "cancel-order",

"data": {

   "order_id": "2477098"

   "time": 1443468122895

},

"oid": "1435927928274_12_cancel-order",

"ok": "ok"

}

 

GetArchivedOrders

 

{

"e": "archived-orders",

"data": [

   {

       "type": "buy",

       "symbol1": "BTC",

       "symbol2": "USD",

       "amount": 0,

       "amount2": 5000,

       "remains": 0,

       "time": "2015-04-17T10:46:27.971Z",

       "tradingFeeBuy": "2",

       "tradingFeeSell": "2",

       "ta:USD": "49.00",

       "fa:USD": "0.98",

       "orderId": "2340298",

       "status": "d",

       "a:BTC:cds": "0.18151851",

       "a:USD:cds": "50.00",

       "f:USD:cds": "0.98"

   },

   {

       "type": "buy",

       "symbol1": "BTC",

       "symbol2": "USD",

       "amount": 0,

       "amount2": 10000,

       "remains": 0,

       "time": "2015-04-08T15:46:04.651Z",

       "tradingFeeBuy": "2.99",

       "tradingFeeSell": "2.99",

       "ta:USD": "97.08",

       "fa:USD": "2.91",

       "orderId": "2265315",

       "status": "d",

       "a:BTC:cds": "0.39869578",

       "a:USD:cds": "100.00",

       "f:USD:cds": "2.91"

    }

],

"oid": "1435927928274    15_archived-orders",

"ok": "ok"

}

 

OpenPosition

 

{

    "e": "open-position",

    "oid": "1435927928274_7_open-position",

    "data": {   

        'amount': '1',

        'symbol': 'BTC',

        "pair": [

            "BTC",

            "USD"

        ],

        'leverage': '2',

        'ptype': 'long',

        'anySlippage': 'true',

        'eoprice': '650.3232',

        'stopLossPrice': '600.3232'

    }

}

 

GetPosition

 

{

  "e": "get_position",

  "ok": "ok",

  "data": {

    "user": "ud100036721",

    "pair": "BTC:USD",

    "amount": "1.00000000",

    "symbol": "BTC",

    "msymbol": "USD",

    "omamount": "1528.77",

    "lsymbol": "USD",

    "lamount": "3057.53",

    "slamount": "3380.11",

    "leverage": "3",

    "stopLossPrice": "3380.1031",

    "dfl": "3380.10310000",

    "flPrice": "3057.53333333",

    "otime": 1513002370342,

    "psymbol": "BTC",

    "ptype": "long",

    "ofee": "10",

    "pfee": "10",

    "cfee": "10",

    "tfeeAmount": "152.88",

    "rinterval": "14400000",

    "okind": "Manual",

    "a:BTC:c": "1.00000000",

    "a:BTC:s": "1.00000000",

    "oorder": "89101551",

    "pamount": "1.00000000",

    "lremains": "3057.53",

    "slremains": "3380.11",

    "oprice": "4586.3000",

    "status": "a",

    "id": "125531",

    "a:USD:cds": "4739.18"

  }

}

 

GetOpenPositions

 

{

    'e': 'open_positions',

    "oid": "1435927928256_7_open-positions",

    'ok': 'ok',

    'data': [

        {

            'user': 'ud100036721',

            'id': '104102',

            'otime': 1475602208467,

            'symbol': 'BTC',

            'amount': '1.00000000',

            'leverage': '2',

            'ptype': 'long',

            'psymbol': 'BTC',

            'msymbol': 'USD',

            'lsymbol': 'USD',

            'pair': 'BTC:USD',

            'oprice': '607.5000'

            'stopLossPrice': '520.3232',

            'ofee': '1',

            'pfee': '3',

            'cfee': '4',

            'tfeeAmount': '3.04',

            'pamount': '1.00000000',

            'omamount': '303.75',

            'lamount': '303.75',

            'oorder': '34106774',            

            'rinterval': '14400000',

            'dfl': '520.32320000',

            'slamount': '520.33',

            'slremains': '520.33',

            'lremains': '303.75',

            'flPrice': '303.75000000',

            'a:BTC:c': '1.00000000',

            'a:BTC:s': '1.00000000',

            'a:USD:cds': '610.54',

        },

        ...

    ]

}

 

ClosePosition

 

{   

    'e': 'close_position',

    "oid": "1435927928364_7_close-position",

    'ok': 'ok',

    'data': {

        'id': 104034,

        'ctime': 1475484981063,

        'ptype': 'long',

        'msymbol': 'USD'

        'pair': {

            'symbol1': 'BTC',

            'symbol2': 'USD'

        }

        'price': '607.1700',

        'profit': '-12.48',

    }

}