WebSocket API

Overview

The following documentation covers the Cryptowatch WebSocket API for streaming market data. The API provides a standardized way to access market data for 26 major crypto exchanges. You need a Pro Plan to access the WebSocket API.

We recommend using one of the SDKs since they properly handle authentication, connection logic, and provide many useful abstractions from our messaging layer. We have libraries written for Golang and Node.js:

Generate an API key pair here →

Account Upgrade

Our WebSocket API is exclusive for Pro subscribers. Upgrade your account to Pro here in order to access the API. Have questions before you upgrade? Please reach out to our support team.

Messaging

All messages sent over the WebSocket API are encoded using Protocol Buffers. Our protobuf definitions are publicly available here:

Strings Vs Floats

All price, ID, and subscription data are represented as strings. This is to prevent loss of significant digits from using float, as well as to provide a consistent and simple API.

Deprecation Warning

Most protobuf message fields that use float are deprecated in favor of a string replacement. It is recommended you use the latest version of our client libraries which properly handle this deprecation.

Connecting

Connect to the API at the following url.

ServiceHost
Streamingwss://stream.cryptowat.ch

Authentication

Each connection to the WebSocket API must be authenticated with an API key and secret key. After establishing a connection, the client sends an APIAuthenticationMessage containing their public key, a nonce, and a token which is an HMAC-SHA-512 created with the corresponding secret key. An example implementation of generating the token in Go can be found here.

Subscriptions

Subscriptions (ClientSubscription) are the primary contract between the client and WebSocket server, and determine what you are streaming. For streaming, subscriptions are data resources that receive live updates.

A ClientSubscription is always followed by a SubscriptionResult, which contains a list of the successful subscriptions, as well as any failed subscriptions if applicable. Similarly, unsubscribing (ClientUnsubscribeMessage) is always followed by a UnsubscriptionResult. When a subscription fails, it usually means the client does not have access, or the subscription key is invalid.


Streaming

To stream data, clients should connect to wss://stream.cryptowat.ch and provide a list of ClientSubscriptions (StreamSubscription) as part of the as part of the APIAuthenticationMessage. The client will receive live updates for each subscription until it unsubscribes or the connection is closed.

The client can subscribe and unsubscribe to feeds dynamically with ClientSubscribeMessage and ClientUnsubscribeMessage respectively.

a StreamSubscription contains one property resource, which is a string formatted as a colon-separated scope, ID, and subject. For example, the resource exchanges:4:trades is a feed of all trades in the scope exchanges where the ID is 4 (Kraken) and the subject is trades. A client that subscribes to exchanges:4:trades will receive all trade updates for the Kraken exchange.

The following table shows the available subscription prefixes, and where to find the resource IDs using the REST API.

Example PrefixDescriptionResource IDs Endpoint
markets:86Market 86 (Kraken BTC/EUR)api.cryptowat.ch/markets
exchanges:4All markets for exchange 4 (Kraken)api.cryptowat.ch/exchanges
pairs:232All markets for pair 232 (BTC/EUR)api.cryptowat.ch/pairs
assets:60All markets for asset 60 (BTC)api.cryptowat.ch/assets

Public Trades

TradesUpdate is sent for every trade on a given market.

SubscriptionDescriptionFrequency
markets:68:tradesA feed of trades for a single marketreal-time
markets:*:tradesA feed of trades for all marketsreal-time
exchanges:4:tradesA feed of all trades on a given exchangereal-time
pairs:232:tradesA feed of all trades for a given pairreal-time
assets:60:tradesA feed of all trades for a given assetreal-time

See our example code for consuming trade feeds:

24-Hour Market Summary

A SummaryUpdate includes last price, high, low, # trades, volume (base and quote), and price change (percentage and absolute).

SubscriptionDescriptionFrequency
markets:68:summaryMarket summary updates for market 68real-time
markets:*:summaryMarket summary updates for all marketsreal-time
markets:*:summary-low-volumeMarket summary updates for all markets (throttled)2m
exchanges:4:summaryMarket summary updates for all markets in exchange 4real-time
pairs:232:summaryMarket summary updates for all markets with pair 232real-time
assets:60:summaryMarket summary updates for all markets with asset 60real-time

Candlestick Data (OHLC)

An OHLC subscription receives IntervalsUpdate, which contains the latest candlestick data for each interval period. See REST API OHLC data for a reference on interval periods.

SubscriptionDescriptionFrequency
markets:68:ohlcOHLC updates for market 68real-time
markets:*:ohlcOHLC updates for all marketsreal-time
exchanges:4:ohlcOHLC updates for all markets in exchange 4real-time
pairs:232:ohlcOHLC updates for all markets with pair 232real-time
assets:60:ohlcOHLC updates for all markets with asset 60real-time

Order Books

Order book data is separated into three streams for snapshots, deltas, and spread. Order book snapshots are broadcast once per minute, while the deltas are real-time. To maintain a real-time order book, apply deltas to the most recent snapshot. Both deltas and snapshots contain a sequence number, so you can determine if the data is recieved in the correct order.

Snapshots

OrderBookUpdate contains a snapshot of the order book to the highest degree of accuracy available from the exchange.

SubscriptionDescriptionFrequency
markets:68:book:snapshotsOrder book snapshots for market 681m
exchanges:4:book:snapshotsOrder book snapshots for all markets in exchange 41m
pairs:232:book:snapshotsOrder book snapshots for all markets with pair 2321m
assets:60:book:snapshotsOrder book snapshots for all markets with asset 601m

Deltas

OrderBookDeltaUpdate is sent in real-time as updates to the order book occur. These deltas are meant to be applied to a snapshot to keep a real-time order book.

SubscriptionDescriptionFrequency
markets:68:book:deltasOrder book delta updates for market 68real-time
exchanges:4:book:deltasOrder book delta updates for all markets in exchange 4real-time
pairs:9:book:deltasOrder book delta updates for all markets with pair 9real-time
assets:60:book:deltasOrder book delta updates for all markets with asset 60real-time

Spread

OrderBookSpreadUpdate is sent when the order book spread (best bid & ask) changes.

SubscriptionDescriptionFrequency
markets:68:book:spreadOrder book spread updates for a given marketreal-time
markets:*:book:spreadOrder book spread updates for all marketsreal-time
exchanges:4:book:spreadOrder book spread updates for a given exchangereal-time
pairs:232:book:spreadOrder book spread updates for a given pairreal-time
assets:60:book:spreadOrder book spread updates for a given assetreal-time
cw:
u
cw: