Skip to content

Ripplemerich777/cw-sdk-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cryptowatch NodeJS SDK

The Cryptowatch NodeJS SDK enables you to stream and trade using the Cryptowatch WebSocket API. Trading is in beta and not available to the public yet.

Install

npm i cw-sdk-node

Usage

The following code connects to the stream api and listens for market and pair data for btc:usd.

const { StreamClient } = require("cw-sdk-node");

const client = new StreamClient({
  creds: {
    apiKey: "", // your cw api key
    secretKey: "" // your cw secret key
  },
  subscriptions: [
    "markets:87:trades", // kraken btc:usd
    "pairs:9:performance", // btc/usd pair
    "markets:1:trades"
  ],
  logLevel: "debug"
});

// Handlers for market and pair data
client.onMarketUpdate(marketData => {
  console.log(marketData);
});
client.onPairUpdate(pairData => {
  console.log(pairData);
});

// Error handling
client.onError(err => {
  console.error(err);
});

// You can also listen on state changes
client.onStateChange(newState => {
  console.log("connection state changed:", newState);
});

client.onConnect(() => {
  console.info("streaming data for the next 15 seconds...");
  setTimeout(() => {
    client.disconnect();
  }, 15 * 1000);
});

client.onDisconnect(() => {
  console.log("done");
});

// Connect to stream
client.connect();

Testing

Tests are written using jest. Run tests with:

make test

License

BSD-2-Clause