Crypto Exchange Websocket Examples Using CCXWS

ShrimpyApp
Coinmonks
5 min readNov 22, 2019

--

Tutorials for connecting to every major exchange.

Developing applications that rely on cryptocurrency exchange data is complicated. Every exchange provides a different API which is unique and confusing in its own way.

That’s why we’ve put together a series of tutorials that help developers like you start managing exchanges with ease.

Cryptocurrency traders and developers are constantly looking for the fastest way to access crypto exchange trade and order book data so they can make quicker decisions and better capture opportunities as they happen.

To provide this speed, many developers are turning to websocket APIs. websocket streams provide the latest pricing information as it changes on the exchange. Without requiring developers to constantly poll for new data, exchanges will instantly send the latest trade or order book data whenever there has been a change.

The result is the fastest way to access market data from exchanges. Subscribing to each trading pair is generally a one-time event. After this, the exchange will automatically send updated trade or order book data so you can make real-time decisions on how and when to execute trades.

In this article, we will provide multiple examples for ways you can access live exchange data through websockets for every major crypto exchange.

The examples in this tutorial will cover how to use both the CCXWS JavaScript Library and the Shrimpy Node.js Library.

CCXWS

CCXWS is an open-source library provided by the same developers which brought you CCXT.

Install

Before we can write any code, we need to install the CCXWS package using npm.

Example

The following example will connect to two different websocket streams. One trading stream from Binance and one level 2 order book stream from KuCoin.

After connecting to each of these websocket streams, you will immediately begin receiving updates. Each update must be handled using custom logic that will process, organize, and store the data.

Shrimpy

Before beginning with our Node.js example, start by signing up for a Shrimpy Universal Crypto Trading APIs account.

After signing up, select the “Create Api Key” button to generate your Master API Keys. After generating your keys and storing them in a secure location, make sure you have enabled the “Data” permissions on the API keys.

Note: You will need to select a subscription plan before you can begin accessing websocket data. For this tutorial, we recommend subscribing to the “Personal” plan which will provide you with nearly unlimited access to our websockets along with trading, portfolio, and exchange account management endpoints.

Example

Similar to our last example with CCXT, this example will subscribe to two different websocket streams. One websocket stream for the Coinbase Pro trade channel and a second subscription for the Kraken order book channel.

Note: These examples don’t explain how to maintain an order book websocket locally as a client when receiving each update. Additional work will be required to maintain the state of the order books. This will need to be developed based on your requirements for the order book.

Shrimpy supports a Python client in addition to Node.js. You can find that client here.

Conclusion

CCXWS provides a convenient way to subscribe to websockets for each individual exchange. However, CCXWS doesn’t aggregate the websocket streams across exchanges for universal access through the APIs.

Maintaining each websocket can be significant work, so the Shrimpy Websocket APIs are designed to simplify the way you manage all of your exchange websocket connections.

Try out the Shrimpy Trading & Data APIs today. It’s the easiest way to get started collecting data across every major exchange. Collect historical market data, access real-time websockets, execute advanced trading strategies, and manage an unlimited number of users.

Don’t forget to follow us on Twitter and Facebook for updates, and ask any questions to our amazing, active community on Telegram.

The Shrimpy Team

Additional Reading

Get Best Software Deals Directly In Your Inbox

--

--

ShrimpyApp
Coinmonks

Shrimpy is a crypto exchange trading bot for portfolio management, indexing the market, rebalancing, and strategy backtesting. Join now at shrimpy.io.