npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coinograph

v1.0.2

Published

Coinograph Javascript API

Downloads

8

Readme

coinograph

npm standard

coinograph JavaScript API

Install

npm install --save coinograph

Usage

Note: coinograph depends on fetch() being defined globally.

// Example
global.fetch = require("node-fetch");
const Coinograph = require("coinograph");

In order to authenticate, you need to sign up to get a free access token.

To connect to coinograph and start fetching data you need to instantiate the Coinograph class and pass your access token. By default, coinograph expects all time in epoch timestamp (in seconds). To use native Date instance, set dateToTimestamp to true (optional).

const token = 'YOUR_ACCESS_TOKEN'
const coinograph = new Coinograph({ token: token, dateToTimestamp: true });

Methods

exchanges()

List all the available exchanges.

coinList()

  • No parameters
  • Returns (Array of Objects)...
    • name (String) Computer-friendly exchange name
    • display_name (String) Human-friendly exchange name
const exchanges = await coinograph.exchanges();

await console.log(exchanges);

// [
//   {
//     "name": "bitfinex",
//     "display_name": "Bitfinex"
//   },
//   {
//     "name": "bitstamp",
//     "display_name": "Bitstamp"
//   },
//   {
//     "name": "poloniex",
//     "display_name": "Poloniex"
//   },
//   {
//     "name": "gdax",
//     "display_name": "GDAX"
//   },
//   {
//     "name": "binance",
//     "display_name": "Binance"
//   }
// ]

exchangeDetail()

Fetch the details for an exchange including the list of supported pairs.

exchangeDetail(exchange)

  • exchange (String) Lower-case exchange name. See exchanges() method.
const exchange = 'gdax'
const exchangeDetail = await coinograph.exchangeDetail(exchange)

await console.log(exchangeDetail)

// {
//   "name": "gdax",
//   "display_name": "GDAX",
//   "symbols": [
//     {
//       "name": "gdax:ethbtc",
//       "base": "ETH",
//       "quote": "BTC"
//     },
//     {
//       "name": "gdax:bchusd",
//       "base": "BCH",
//       "quote": "USD"
//     },
//     {
//       "name": "gdax:bcheur",
//       "base": "BCH",
//       "quote": "EUR"
//     }
//   ]
// }

ticker()

Return the latest ticker for a symbol.

ticker(symbol)

  • symbol (String) Symbol to fetch. Formatted as exchange:baseCurrency + quoteCurrency. Use exchangeDetail() method to fetch available symbols.
const symbol = 'gdax:btceur'
const ticker = await coinograph.ticker(symbol)

await console.log(ticker)

// {
//   "price": 7080.19,
//   "ask": 7080.19,
//   "bid": 7080.18
// }

orderbook()

Get the latest order book for a symbol.

ticker(symbol)

  • symbol (String) Symbol to fetch. Formatted as exchange:baseCurrency + quoteCurrency. Use exchangeDetail() method to fetch available symbols.
const symbol = 'gdax:btceur'
const orderbook = await coinograph.ticker(symbol)

await console.log(orderbook)

// {
//   "bids": [
//     {
//       "price": 100,
//       "amount": 2.101
//     }
//   ],
//   "asks": [
//     {
//       "price": 92,
//       "amount": 1.101
//     }
//   ]
// }

candles()

Historical OHLCV data for a give symbol.

candles(symbol, step, end, start)

  • symbol (String) Symbol to fetch. Formatted as exchange:baseCurrency + quoteCurrency. Use exchangeDetail() method to fetch available symbols.
  • step (Int) Interval in seconds. Defines the candle resolution (1m = 60).
  • end (Timestamp | Date) Start date in seconds (default). To use native Date instance, set dateToTimestamp to true upon instantiation of the Coinograph class. See Usage.
  • start (Timestamp | Date) Start date in seconds (default). To use native Date instance, set dateToTimestamp to true upon instantiation of the Coinograph class. See Usage.
const symbol = 'binance:btcusdt'
const step = 14400
const end = new Date()
const start = new Date('2018-07-01')
// const end = 1521823080
// const start = 1521471600

const candles = await coinograph.candles(symbol, step, end, start)
await console.log(candles)

// [
//   {
//     "open": 13784,
//     "close": 13808,
//     "high": 13808,
//     "low": 13784,
//     "volume": 17.13545717
//   },
//   {
//     "open": 10402,
//     "close": 10418,
//     "high": 10446,
//     "low": 10396,
//     "volume": 99.4153358
//   },
//   {
//     "open": 11422,
//     "close": 11443,
//     "high": 11443,
//     "low": 11410,
//     "volume": 198.10640075
//   }
// ]

trades()

Return latest/historical trades for a given symbol.

trades(symbol, start, limit)

  • symbol (String) Symbol to fetch. Formatted as exchange:baseCurrency + quoteCurrency. Use exchangeDetail() method to fetch available symbols.
  • start (Timestamp | Date) Start date in seconds (default). To use native Date instance, set dateToTimestamp to true upon instantiation of the Coinograph class. See Usage.
  • limit (Int) Number of trades to fetch. Default 100 (max 300).
const symbol = 'bitfinex:btcusd'
const start = new Date('2018-03-02T16:22:24+00:00')
// const start = 1520007744
const limit = 2

const trades = await coinograph.trades(symbol, start, limit)
await console.log(trades)

// [
//   {
//     "tid": 205073183,
//     "time": 1520007744,
//     "price": 10805,
//     "type": 1,
//     "amount": 0.00078152
//   },
//   {
//     "tid": 205073184,
//     "time": 1520007744,
//     "price": 10805,
//     "type": 1,
//     "amount": 0.00239579
//   }
// ]

License

MIT