Giter Site home page Giter Site logo

cw-sdk-node's Introduction

Cryptowatch NodeJS SDK

The Cryptowatch NodeJS SDK enables you to stream, trade, and access data using the Cryptowatch WebSocket and REST APIs. Trading over WebSockets is in beta, and not available to the public yet.

API documentation:

Install

npm i cw-sdk-node

Usage

StreamClient

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();

More details can be found in our StreamClient Documentation

RESTClient

To use your REST api data allowance, you will need to pass your cryptowat.ch API key to the RESTClient constructor.

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

const client = new RESTClient({
  creds: {
    apiKey: "" // your cw api key
  }
});

// All requests return promises that return the formatted API data.
client.getExchanges().then((response) =>{
    let exchanges = response.result;
});

More details can be found in our RESTClient Documentation

Testing

Tests are written using jest. Run tests with:

make test

License

BSD-2-Clause

cw-sdk-node's People

Contributors

dbosley avatar dependabot[bot] avatar durek1337 avatar miguelcobain avatar tahoedesigner avatar vicagbasi avatar vvozibic avatar wellsjo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.