This repository was archived by the owner on Apr 12, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 3
Websocket API
Connor Giles edited this page Jul 15, 2017 · 5 revisions
When your application requires real time access to data, using the Websocket API is recommended.
Websocket support is implemented for all exchanges listed with a ✅ next to them.
const xchange = require('xchange-js') const client = new xchange.Gdax.WebsocketClient(); client.on('open', () => { // From here you can subscribe to various streams }); client.on('error', (err) => { // All errors will be passed through this event }); client.on('close', (data) => { // Event on close of socket });// Called after connection is open client.subscribe('BTCUSD'); // returns created Market of pair client.subscribe('ETHBTC'); // Can subscribe to as many pairs as you want client.on('change', (market) => { // Access updated market book for the pair that triggered the change console.log(market.book.state()); });Allows you to only recieve change events when the orderbook changes below a depth
// Called after connection is open let market = client.subscribe('BTCUSD'); // returns created Market of pair market.book.subscribe(5); // subscribes to book changes within top 5 layers market.on('change', (book) => { // Access updated book state of depth 5 console.log(book); });