Websocket

Spot offers a websocket feed that provides real time market data, order and fill updates.

To begin receiving feed messages, you must send a subscribe message to the server indicating which channel and products to receive. This message is mandatory.

// Request
// Subscribe to AVAX-USDC Top Of Book market data feed
{
	"op":"subscribe",
  "channel": "topOfBooksSpot",
  "markets": ["AVAX-USDC"] // Leaving out markets subscribes to all markets.
}

// Response
// First will be confirmation about operation success/failure.
{
  "channel": "topOfBooksSpot",
  "type":"subscribed",
  // Reflecting the request back.
	"data": {
			"op":"subscribe",
		  "channel": "topOfBooksSpot",
		  "markets": ["AVAX-USDC"]
		}
}

// Failure would look like follows -  eg. if we supplied wrong market:
{
  "type":"error",
  "msg":"provided market is invalid"
}
//

// Next will be the appropriate feed events.
{
  "channel":"topOfBooksSpot",
  "type":"update",
  "data": {
    "market": "AVAX-USDC",
    "asks": [["21","1"]],
    "bids": [["20","1"]],
    "time": 0001-01-01T00:00:00Z
}

Unsubscribe

To unsubscribe from a channel, or from certain markets, send an unsubscribe message. The structure is the same as subscribe message. You can only unsubscribe from one channel at a time.

// Request
// Unsubscribe from AVAX-USDC Top Of Book market data feed. If we were subscribed to
// multiple markets, we could unsubscribe just from some of them.
{
  "op":"unsubscribe",
  "channel": "topOfBooksSpot",
  "markets": ["AVAX-USDC"] // leaving empty unsubscribes from all subscribed markets (if applicable, depends on a channel).
}

Errors

Sometimes you can get failure back when you try to subscribe to a channel. Some common errors are:

"channel unsupported" - when trying to subscribe to an unsupported channel
"login required"  - some endpoints require login
"already logged in on this connection" - no need to login again
"account already has too many connections" - max allowed connections per accounts are currently exceeded
"too many price subscriptions" - max allowed connections to cross price channel are currently exceeded
"markets argument is not supported" - not every channel supports markets argument
"provided market is invalid"
"provided market has not been subscribed"
"provided account id has not been subscribed"
"timeout_seconds argument is missing"
"timeout_seconds argument is not supported"

// It would be delivered as:

{
  "type":"error",
  "msg":"provided market is invalid"
}

Public Channels

These public channels don’t require authentication.

Top Of Book

Channel for sending changes on the top of book. These updates are real-time and happen whenever there is a change to the top of the book. The time is a timestamp of the last order update in the top of book price levels. Top of book change update might deliver changes in multiple markets at the same time.

// Request
// Subscribe to AVAX-USDC Top Of Book market data feed.
{
	"op":"subscribe",
  "channel": "topOfBooksSpot",
  "markets": ["AVAX-USDC"]
}

// Response
// First will be confirmation about operation success/failure.
{
  "channel": "topOfBooksSpot",
  "type": "subscribed",
  "data": ...
}

// Next will be the appropriate feed events.
{
  "channel": "topOfBooksSpot",
  "type": "update",
  "data": [{
    "market": "AVAX-USDC",
    "asks": [["21","1"]],
    "bids": [["20","1"]],
		"time": "2022-06-16T12:35:11.123456Z"
	}]
}

Depth

Channel for sending book snapshots every 250ms at most 100 levels deep. The update might deliver changes in multiple markets at the same time.