ImSeaWorld / coincapjs

NodeJS API Wrapper for CoinCap's v2 API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coincapjs

Light weight, easy to use CoinCap api wrapper for NodeJS

NPM

Basic Usage

// npm install coincapjs --save
const CoinCap = require('coincapjs');

CoinCap.getAssets({
    cb: function (err, status, result) {
        if (err) throw err;

        console.log(`Data Length: ${result.dataLen}`);
        console.log(`First Result: ${JSON.parse(result.data[0])}`);
    },
});

Interfaces

Methods

Interface CoinCap.getAssets

Interface CoinCap.getRates

Interface CoinCap.getExchanges

Interface CoinCap.getMarkets

Interface CoinCap.getCandles


Changes

1.0.3 >> 1.0.5

  • Changed around prototypes to match hierarchy.
  • Deprecated collection(Object: params, function: cb)
    • Interfaces now do the same job as collection did.
// OLD
CoinCap.getAssets.collection({}, function (err, status, result) {});
// CURRENT
CoinCap.getAssets({ cb: function (err, status, result) {} });

Examples

TL;DR CoinCap.call

// Call assets directly
CoinCap.call('assets', '{{id}}', { id: 'bitcoin' }, (err, status, res) => {
    if (err) throw err;

    console.log(
        `CoinCap.call('assets', '{{id}}', { id: 'bitcoin' })[ ${status} ]: ${res.dataLen}`,
    );
});

Interface CoinCap.getAssets

// Get asset collection
CoinCap.getAssets({
    cb: function (err, status, res) {
        if (err) {
            throw err;
        }

        console.log(
            `CoinCap.getAssets()[${status}]: ${res.dataLen}\n${res.data[0]}`,
        );
    },
});
// Get asset by id "bitcoin"
CoinCap.getAssets().byId('bitcoin', function (err, status, res) {
    if (err) {
        throw err;
    }

    console.log(
        `CoinCap.getAssets().byId('bitcoin')[${status}]: ${res.dataLen}\n${res.data[0]}`,
    );
});

// interval: m1, m5, m15, m30, h1, h2, h6, h12, d1
CoinCap.getAssets({ interval: 'd1' })
    .byId('bitcoin')
    .history(function (err, status, res) {
        if (err) {
            throw err;
        }

        console.log(
            `CoinCap.getAssets({ interval: 'd1' }).byId('bitcoin')[${status}]: ${res.dataLen}\n${res.data[0]}`,
        );
    });

CoinCap.getAssets()
    .byId('bitcoin')
    .markets(function (err, status, res) {
        if (err) {
            throw err;
        }

        console.log(
            `CoinCap.getAssets().byId('bitcoin').markets[${status}]:`,
            res.dataLen,
        );
    });

Interface CoinCap.getRates

CoinCap.getRates({
    cb: function (err, status, res) {
        if (err) {
            throw err;
        }

        console.log(`CoinCap.getRates[${status}]:`, res.dataLen);
    },
});

CoinCap.getRates().byId('bitcoin', function (err, status, res) {
    if (err) {
        throw err;
    }

    console.log(`CoinCap.getRates().byId('bitcoin')[${status}]:`, res.dataLen);
});

Interface CoinCap.getExchanges

CoinCap.getExchanges().byId('bitcoin', function (err, status, res) {
    if (err) {
        throw err;
    }

    console.log(
        `CoinCap.getExchanges().byId('bitcoin')[${status}]:`,
        res.dataLen,
    );
});

Interface CoinCap.getMarkets

CoinCap.getMarkets({
    exchangeId: 'quoine',
    cb: function (err, status, res) {
        if (err) {
            throw err;
        }

        console.log(
            `CoinCap.getMarkets({ exchangeId: 'quoine' })[${status}]:`,
            res.dataLen,
        );
    },
});

Interface CoinCap.getCandles

CoinCap.getCandles({
    exchange: 'poloniex',
    interval: 'm1',
    baseId: 'ethereum',
    quoteId: 'bitcoin',
    cb: function (err, status, res) {
        if (err) {
            throw err;
        }

        console.log(
            `CoinCap.getCandles({ exchange: 'poloniex', interval: 'm1', baseId: 'ethereum', quoteId: 'bitcoin' })[${status}]:`,
            res.dataLen,
        );
    },
});

Links

CoinCap.io

CoinCap.io API Docs

About

NodeJS API Wrapper for CoinCap's v2 API


Languages

Language:JavaScript 100.0%