Data Feed

Introduction

CoinJar Exchange offers a WebSocket-based API for streaming market data.

Endpoint

The endpoint for CoinJar Exchange Data Feed in production is wss://feed.exchange.coinjar.com/socket/websocket. If you are developing in the sandbox environment, please use wss://feed.exchange.coinjar-sandbox.com/socket/websocket.

Phoenix JS

This API conforms to the Phoenix protocol and we recommend developers to use the official Phoenix JavaScript client, which abstracts away the complexity of handling duplicate subscriptions, reconnects and heartbeats.

Raw WebSocket

It is possible to use CoinJar Exchange Data Feed with raw WebSocket (or any WS library). However, you must send a heartbeat message every 45 seconds, otherwise the connection will be dropped by the server.

To send a heartbeat, push the following message to the socket:

{ "topic": "phoenix", "event": "heartbeat", "payload": {}, "ref": 0 }

To subscribe to a channel, push the following message to the socket:

{ "topic": "CHANNEL_NAME", "event": "phx_join", "payload": {}, "ref": 0 }

To subscribe to a authenticated private channel you will need your api token and push the following message to the socket:

{
  "topic": "CHANNEL_NAME",
  "event": "phx_join",
  "payload": { "token": "MY_SECRET_API_TOKEN" },
  "ref": 0
}

Channels

Ticker

  • Channel: ticker:{pair} - e.g. ticker:BTCAUD

The ticker channel broadcasts every update to the ticker, with more frequent updates around the end of session.

Example

> {"topic": "ticker:BTCAUD", "event": "phx_join","payload": {},"ref": 0}
< {"topic":"ticker:BTCAUD","ref":0,"payload":{"status":"ok","response":{}},"join_ref":null,"event":"phx_reply"}
< {"topic":"ticker:BTCAUD","ref":null,"payload":{"volume":"0.51100000","transition_time":"2018-03-07T05:08:00Z","status":"continuous","session":317580,"prev_close":"13900.00000000","last":"13920.00000000","current_time":"2018-03-07T05:07:19.886682Z","bid":"13910.00000000","ask":"13920.00000000"},"event":"init"}
< {"topic":"ticker:BTCAUD","ref":null,"payload":{"volume":"0.51100000","transition_time":"2018-03-07T05:08:00Z","status":"continuous","session":317580,"prev_close":"13900.00000000","last":"13920.00000000","current_time":"2018-03-07T05:07:20.590072Z","bid":"13910.00000000","ask":"13920.00000000"},"event":"update"}
< {"topic":"ticker:BTCAUD","ref":null,"payload":{"volume":"0.51100000","transition_time":"2018-03-07T05:08:00Z","status":"continuous","session":317580,"prev_close":"13900.00000000","last":"13920.00000000","current_time":"2018-03-07T05:07:20.653583Z","bid":"13910.00000000","ask":"13920.00000000"},"event":"update"}

Book

  • Channel: book:{pair} - e.g. book:BTCAUD

The book channel broadcasts every update to the order book. Multiple updates may be aggregated into a single message. The init event returns the initial Level 2 order book.

Example

> {"topic": "book:BTCAUD", "event": "phx_join","payload": {},"ref": 0}
< {"topic":"book:BTCAUD","ref":0,"payload":{"status":"ok","response":{}},"join_ref":null,"event":"phx_reply"}
< {"topic":"book:BTCAUD","ref":null,"payload":{"bids":[["13900.00000000","0.02900000"],["13890.00000000","0.09000000"],["13880.00000000","0.09400000"],["13870.00000000","0.11500000"],["13860.00000000","0.06000000"],["13850.00000000","0.12000000"],["13840.00000000","0.05800000"],["13830.00000000","0.00800000"],["13440.00000000","0.00100000"]],"asks":[["13910.00000000","0.00600000"],["13920.00000000","0.04200000"],["13930.00000000","0.03900000"],["13940.00000000","0.06300000"],["13950.00000000","0.12900000"],["13960.00000000","0.12400000"],["13970.00000000","0.13200000"],["13980.00000000","0.19000000"],["13990.00000000","0.15400000"],["14000.00000000","0.13900000"],["14010.00000000","0.13400000"],["14020.00000000","0.13200000"],["14030.00000000","0.07500000"]]},"event":"init"}
< {"topic":"book:BTCAUD","ref":null,"payload":{"bids":[],"asks":[["13940.00000000","0.06500000"]]},"event":"update"}
< {"topic":"book:BTCAUD","ref":null,"payload":{"bids":[],"asks":[["13990.00000000","0.16400000"]]},"event":"update"}
< {"topic":"book:BTCAUD","ref":null,"payload":{"bids":[],"asks":[["13910.00000000","0.00500000"]]},"event":"update"}

Trades

  • Channel: trades:{pair} - e.g. trades:BTCAUD

The trades channel broadcasts every new trade. Multiple trades may be aggregated into a single message. The init event returns the last 50 trades.

Example

> {"topic": "trades:BTCAUD", "event": "phx_join","payload": {},"ref": 0}
< {"topic":"trades:BTCAUD","ref":0,"payload":{"status":"ok","response":{}},"join_ref":null,"event":"phx_reply"}
< {"topic":"trades:BTCAUD","ref":null,"payload":{"trades":[{"value":"15.51","timestamp":"2018-10-31T15:59:58.000001Z","tid":131737,"taker_side":"auction","size":"0.00100000","price":"15510.00000000"},{"value":"55.68","timestamp":"2018-03-07T05:24:47.437271Z","tid":1695805,"taker_side":"sell","size":"0.00400000","price":"13920.00000000"},{"value":"13.94","timestamp":"2018-03-07T05:24:39.051446Z","tid":1695804,"taker_side":"buy","size":"0.00100000","price":"13940.00000000"},{"value":"13.93","timestamp":"2018-03-07T05:24:36.211931Z","tid":1695803,"taker_side":"buy","size":"0.00100000","price":"13930.00000000"},{"value":"55.68","timestamp":"2018-03-07T05:24:35.200984Z","tid":1695802,"taker_side":"sell","size":"0.00400000","price":"13920.00000000"},{"value":"13.92","timestamp":"2018-03-07T05:24:33.203475Z","tid":1695801,"taker_side":"sell","size":"0.00100000","price":"13920.00000000"},{"value":"27.86","timestamp":"2018-03-07T05:24:28.818919Z","tid":1695800,"taker_side":"buy","size":"0.00200000","price":"13930.00000000"},{"value":"27.86","timestamp":"2018-03-07T05:24:28.818518Z","tid":1695799,"taker_side":"buy","size":"0.00200000","price":"13930.00000000"},{"value":"55.72","timestamp":"2018-03-07T05:24:24.111650Z","tid":1695797,"taker_side":"buy","size":"0.00400000","price":"13930.00000000"},{"value":"27.84","timestamp":"2018-03-07T05:24:17.659544Z","tid":1695795,"taker_side":"sell","size":"0.00200000","price":"13920.00000000"},{"value":"27.92","timestamp":"2018-03-07T05:24:13.991808Z","tid":1695794,"taker_side":"sell","size":"0.00200000","price":"13960.00000000"},{"value":"55.84","timestamp":"2018-03-07T05:24:13.724818Z","tid":1695793,"taker_side":"sell","size":"0.00400000","price":"13960.00000000"},{"value":"41.82","timestamp":"2018-03-07T05:24:12.660579Z","tid":1695792,"taker_side":"sell","size":"0.00300000","price":"13940.00000000"},{"value":"27.88","timestamp":"2018-03-07T05:24:12.370860Z","tid":1695791,"taker_side":"sell","size":"0.00200000","price":"13940.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:24:12.370493Z","tid":1695790,"taker_side":"sell","size":"0.00100000","price":"13950.00000000"},{"value":"55.80","timestamp":"2018-03-07T05:24:10.838528Z","tid":1695789,"taker_side":"buy","size":"0.00400000","price":"13950.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:24:10.141425Z","tid":1695788,"taker_side":"buy","size":"0.00100000","price":"13950.00000000"},{"value":"13.92","timestamp":"2018-03-07T05:24:09.540143Z","tid":1695787,"taker_side":"sell","size":"0.00100000","price":"13920.00000000"},{"value":"55.68","timestamp":"2018-03-07T05:24:09.539512Z","tid":1695786,"taker_side":"sell","size":"0.00400000","price":"13920.00000000"},{"value":"27.86","timestamp":"2018-03-07T05:24:08.988853Z","tid":1695785,"taker_side":"buy","size":"0.00200000","price":"13930.00000000"},{"value":"27.86","timestamp":"2018-03-07T05:24:08.859489Z","tid":1695784,"taker_side":"sell","size":"0.00200000","price":"13930.00000000"},{"value":"55.76","timestamp":"2018-03-07T05:24:07.382497Z","tid":1695783,"taker_side":"sell","size":"0.00400000","price":"13940.00000000"},{"value":"13.93","timestamp":"2018-03-07T05:24:05.538235Z","tid":1695782,"taker_side":"sell","size":"0.00100000","price":"13930.00000000"},{"value":"41.79","timestamp":"2018-03-07T05:24:05.537697Z","tid":1695781,"taker_side":"sell","size":"0.00300000","price":"13930.00000000"},{"value":"69.65","timestamp":"2018-03-07T05:24:04.835314Z","tid":1695780,"taker_side":"sell","size":"0.00500000","price":"13930.00000000"},{"value":"55.72","timestamp":"2018-03-07T05:24:04.383323Z","tid":1695779,"taker_side":"sell","size":"0.00400000","price":"13930.00000000"},{"value":"41.85","timestamp":"2018-03-07T05:23:59.145253Z","tid":1695775,"taker_side":"sell","size":"0.00300000","price":"13950.00000000"},{"value":"41.82","timestamp":"2018-03-07T05:23:57.689887Z","tid":1695774,"taker_side":"buy","size":"0.00300000","price":"13940.00000000"},{"value":"69.65","timestamp":"2018-03-07T05:23:57.459715Z","tid":1695773,"taker_side":"sell","size":"0.00500000","price":"13930.00000000"},{"value":"27.86","timestamp":"2018-03-07T05:23:57.459246Z","tid":1695772,"taker_side":"sell","size":"0.00200000","price":"13930.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:23:38.442253Z","tid":1695770,"taker_side":"sell","size":"0.00100000","price":"13950.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:23:37.707822Z","tid":1695769,"taker_side":"sell","size":"0.00100000","price":"13950.00000000"},{"value":"13.96","timestamp":"2018-03-07T05:22:52.926000Z","tid":1695768,"taker_side":"sell","size":"0.00100000","price":"13960.00000000"},{"value":"13.96","timestamp":"2018-03-07T05:22:52.910737Z","tid":1695767,"taker_side":"buy","size":"0.00100000","price":"13960.00000000"},{"value":"27.92","timestamp":"2018-03-07T05:22:52.910316Z","tid":1695766,"taker_side":"buy","size":"0.00200000","price":"13960.00000000"},{"value":"13.93","timestamp":"2018-03-07T05:22:52.798435Z","tid":1695765,"taker_side":"sell","size":"0.00100000","price":"13930.00000000"},{"value":"41.82","timestamp":"2018-03-07T05:22:52.797956Z","tid":1695764,"taker_side":"sell","size":"0.00300000","price":"13940.00000000"},{"value":"13.96","timestamp":"2018-03-07T05:22:52.589386Z","tid":1695763,"taker_side":"buy","size":"0.00100000","price":"13960.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:22:52.588828Z","tid":1695762,"taker_side":"buy","size":"0.00100000","price":"13950.00000000"},{"value":"13.94","timestamp":"2018-03-07T05:22:36.435873Z","tid":1695761,"taker_side":"sell","size":"0.00100000","price":"13940.00000000"},{"value":"27.88","timestamp":"2018-03-07T05:22:36.264997Z","tid":1695760,"taker_side":"sell","size":"0.00200000","price":"13940.00000000"},{"value":"27.92","timestamp":"2018-03-07T05:22:34.119121Z","tid":1695759,"taker_side":"buy","size":"0.00200000","price":"13960.00000000"},{"value":"27.88","timestamp":"2018-03-07T05:22:32.217855Z","tid":1695758,"taker_side":"sell","size":"0.00200000","price":"13940.00000000"},{"value":"27.88","timestamp":"2018-03-07T05:22:31.677659Z","tid":1695757,"taker_side":"sell","size":"0.00200000","price":"13940.00000000"},{"value":"27.90","timestamp":"2018-03-07T05:22:31.677307Z","tid":1695756,"taker_side":"sell","size":"0.00200000","price":"13950.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:22:31.447211Z","tid":1695755,"taker_side":"sell","size":"0.00100000","price":"13950.00000000"},{"value":"27.90","timestamp":"2018-03-07T05:22:31.319633Z","tid":1695754,"taker_side":"sell","size":"0.00200000","price":"13950.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:22:31.179571Z","tid":1695753,"taker_side":"sell","size":"0.00100000","price":"13950.00000000"},{"value":"13.95","timestamp":"2018-03-07T05:22:31.115029Z","tid":1695752,"taker_side":"sell","size":"0.00100000","price":"13950.00000000"},{"value":"27.90","timestamp":"2018-03-07T05:22:30.703467Z","tid":1695751,"taker_side":"sell","size":"0.00200000","price":"13950.00000000"}]},"event":"init"}
< {"topic":"trades:BTCAUD","ref":null,"payload":{"trades":[{"timestamp":"2018-03-07T05:24:50.935274Z","tid":1695809,"taker_side":"buy","size":"0.00100000","price":"13930.00000000"}]},"event":"new"}
< {"topic":"trades:BTCAUD","ref":null,"payload":{"trades":[{"timestamp":"2018-03-07T05:24:53.418513Z","tid":1695812,"taker_side":"sell","size":"0.00200000","price":"13920.00000000"},{"timestamp":"2018-03-07T05:24:53.419098Z","tid":1695813,"taker_side":"sell","size":"0.00100000","price":"13910.00000000"},{"timestamp":"2018-03-07T05:24:53.419470Z","tid":1695814,"taker_side":"sell","size":"0.00100000","price":"13910.00000000"}]},"event":"new"}
< {"topic":"trades:BTCAUD","ref":null,"payload":{"trades":[{"timestamp":"2018-03-07T05:24:54.305906Z","tid":1695815,"taker_side":"sell","size":"0.00400000","price":"13910.00000000"}]},"event":"new"}

Private

The private channel broadcasts updates of your account, orders and fills, these updates come from the same channel however using different events. See the above Raw WebSocket section on how to join this channel.

It is up to the users to route these events to different handlers as subscribing to the private channel gives the user all of the below events.

  • Channel: private

Order Event

  • Event: private:order

Order events are broadcasted when there are updates to any of your orders, these include: booked orders, fills, partial fills and cancellations.

Example of event payload


< {"topic":"private", "event": "private:order","ref":null,"payload":{
    "order":{
      "type": "LMT",
      "timestamp": "2018-08-28T05:28:13.615499Z",
      "time_in_force": "GTC",
      "status": "booked",
      "size": "0.01000000",
      "side": "buy",
      "ref": "",
      "product_id": "BTCAUD",
      "price": "9380.00000000",
      "oid": 280126227,
      "filled": "0.00000000",
      "client_number": "STG100000033"
    }
  }}

Fill Event

  • Event: private:fill

Fills events will be broadcasted only when fills occur for your open orders, multiple partial fills will trigger multiple fill events.

Example of event payload


< {"topic":"private", "event": "private:fill","ref":null,"payload":{
    "fill":{
      "value": "93.82",
      "timestamp": "2018-08-28T05:16:37.405702Z",
      "tid": 9130900,
      "size": "0.01000000",
      "side": "buy",
      "product_id": "BTCAUD",
      "price": "9382.00000000",
      "oid": 280117631,
      "liquidity": "taker"
    }
  }}

Account Event

  • Event: private:account

Account event is broadcasted for any account which the balance has changed.

Example of event payload


< {"topic":"private", "event": "private:account","ref":null,"payload":{
    "account":{
      "type": "cash",
      "number": "STG100000033AUD",
      "hold": "93.80",
      "balance": "10339.59",
      "available": "10245.79",
      "asset_code": "AUD"
    }
  }}