SkillAgentSearch skills...

Ccxws

WebSocket client for 38 cryptocurrency exchanges

Install / Use

/learn @altangent/Ccxws

README

CryptoCurrency eXchange WebSockets

CI Coverage

A JavaScript library for connecting to realtime public APIs on all cryptocurrency exchanges.

CCXWS provides a standardized eventing interface for connection to public APIs. Currently CCXWS support ticker, trade and orderbook events.

The CCXWS socket client performs automatic reconnection when there are disconnections. It also has silent reconnection logic to assist when no data has been seen by the client but the socket remains open.

CCXWS uses similar market structures to those generated by the CCXT library. This allows interoperability between the RESTful interfaces provided by CCXT and the realtime interfaces provided by CCXWS.

Check out the FAQS for more inforamtion on common issues you may encounter.

Check out the CONTRIBUTING guide for how to get involved.

Getting Started

Install ccxws

npm install ccxws

Create a new client for an exchange. Subscribe to the events that you want to listen to by supplying a market.

import { BinanceClient } from "ccxws";
const binance = new BinanceClient();

// market could be from CCXT or genearted by the user
const market = {
  id: "BTCUSDT", // remote_id used by the exchange
  base: "BTC", // standardized base symbol for Bitcoin
  quote: "USDT", // standardized quote symbol for Tether
};

// handle trade events
binance.on("trade", trade => console.log(trade));

// handle level2 orderbook snapshots
binance.on("l2snapshot", snapshot => console.log(snapshot));

// subscribe to trades
binance.subscribeTrades(market);

// subscribe to level2 orderbook snapshots
binance.subscribeLevel2Snapshots(market);

Exchanges

| Exchange | API | Class | Ticker | Trades | Candles | OB-L2 Snapshot | OB-L2 Updates | OB-L3 Snapshot | OB-L3 Updates | | ---------------------- | --- | ------------------------- | -------- | -------- | -------- | -------------- | ------------- | -------------- | ------------- | | Bibox | 1 | BiboxClient | ✓ | ✓ | ✓ | ✓ | | - | - | | Binance | 1 | BinanceClient | ✓ | ✓ | ✓ | ✓ | ✓** | - | - | | Binance Futures Coin-M | 1 | BinanceFuturesCoinmClient | ✓ | ✓ | ✓ | ✓ | ✓** | - | - | | Binance Futures USDT-M | 1 | BinanceFuturesUsdtmClient | ✓ | ✓ | ✓ | ✓ | ✓** | - | - | | Binance US | 1 | BinanceUsClient | ✓ | ✓ | ✓ | ✓ | ✓** | - | - | | Bitfinex | 2 | BitfinexClient | ✓ | ✓ | - | - | ✓* | - | ✓* | | bitFlyer | 1 | BitflyerClient | ✓ | ✓ | - | - | ✓** | - | - | | Bithumb | 1 | BithumbClient | ✓ | ✓ | - | - | ✓** | - | - | | BitMEX | 1 | BitmexClient | ✓ | ✓ | ✓ | - | ✓* | - | - | | Bitstamp | 2 | BitstampClient | - | ✓ | - | ✓ | ✓** | - | - | | Bittrex | 3 | BittrexClient | ✓ | ✓ | ✓ | - | ✓* | - | - | | Cex.io | 1 | CexClient | ✓ | ✓ | ✓ | ✓ | | - | - | | Coinbase Pro | 1 | CoinbaseProClient | ✓ | ✓ | - | - | ✓* | - | ✓ | | Coinex | 1 | CoinexClient | ✓ | ✓ | ✓ | - | ✓* | - | - | | Deribit | 2 | DeribitClient | ✓ | ✓ | ✓ | - | ✓* | - | - | | Digifinex | 1 | DigifinexClient | ✓ | ✓ | - | - | ✓* | - | - | | ErisX | 3.4 | ErisXClient | - | ✓ | - | - | - | - | ✓* | | FTX | 1 | FtxClient | ✓ | ✓ | - | - | ✓* | - | - | | FTX US | 1 | FtxUsClient | ✓ | ✓ | - | - | ✓* | - | - | | Gate.io | 3 | GateioClient | ✓ | ✓ | - | - | ✓* | - | - | | Gemini | 1 | GeminiClient | - | ✓ | - | - | ✓* | - | - | | HitBTC | 2 | HitBtcClient | ✓ | ✓ | ✓ | - | ✓* | - | - | | Huobi Global | 1 | HuobiClient | ✓ | ✓ | ✓ | ✓ | - | - | - | | Huobi Global Futures | 1 | HuobiFuturesClient | ✓ | ✓ | ✓ | ✓ | ✓* | - | - | | Huobi Global Swaps | 1 | HuobiSwapsClient | ✓ | ✓ | ✓ | ✓ | ✓* | - | - | | Huobi Japan | 1 | HuobiJapanClient | ✓ | ✓ | ✓ | ✓ | - | - | - | | Huobi Korea | 1 | HuobiKoreaClient | ✓ | ✓ | ✓ | ✓ | - | - | - | | KuCoin | 2 | KucoinClient | ✓ | ✓ | ✓ | - | ✓** | - | ✓* | | Kraken | 0 | KrakenClient | ✓ | ✓ | ✓ | - | ✓* | - | - | | LedgerX | 1 | LedgerXClient | - | ✓ | - | - | - | - | ✓* | | Liquid | 2 | LiquidClient | ✓ | ✓ | - | - | ✓ | - | - | | OKEx | 3 | OkexClient | ✓ | ✓ | ✓ | ✓ | ✓* | - | - | | Poloniex | 2 | PoloniexClient | ✓ | ✓ | - | - | ✓* | - | - | | Upbit | 1 | UpbitClient | ✓ | ✓ | - | ✓ | - | - | - | | ZB | 1 | ZbClient | ✓ | ✓ | - | ✓ | - | - | - |

Notes:

  • ✓* broadcasts a snapshot event at startup
  • ✓** broadcasts a snapshot by using the REST API

Definitions

Trades - A maker/taker match has been made. Broadcast as an aggregated event.

Orderbook level 2 - has aggregated price points for bids/asks that include the price and total volume at that point. Some exchange may include the number of orders making up the volume at that price point.

Orderbook level 3 - this is the most granual order book information. It has raw order information for bids/asks that can be used to build aggregated volume information for the price points.

API

Market

Markets are used as input to many of the client functions. Markets can be generated and stored by you the developer or loaded from the CCXT library.

These properties are required by CCXWS.

  • id: string - the identifier used by the remote exchange
  • base: string - the normalized base symbol for the market
  • quote: string - the normalized quote symbol for the market
  • type: string - the type of market: spot, futures, option, swap

Client

A websocket client that connects to a specific exchange. There is an implementation of this class for each exchange that governs the specific rules for managing the realtime connections to the exchange. You must instantiate the specific exchanges client to conncet to the exchange.

const binance = new ccxws.Binance();
const coinbase = new ccxws.CoinbasePro();

Clients can be instantiated with an options object that has several properties properties:

  • wssPath: string - allows customization of the web socket path. When this is configured, additional rules surrounding connection may be ignored.
  • watcherMs: number - allows customization of the reconnection watcher. This value is the duration of time that must pass without a message for a reconnection is peroformed. This value can be customized depending on the type and liquidity of markets that you are subscribing to.
  • apiKey: string - any API key needed for the exchange
  • apiSecret: string - any

Related Skills

View on GitHub
GitHub Stars640
CategoryDevelopment
Updated13d ago
Forks178

Languages

TypeScript

Security Score

100/100

Audited on Mar 17, 2026

No findings