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

crypto-aggregator

v1.1.0

Published

Aggregates cryptocurrency prices from various exchanges. Prices from different exchanges are weighted by their volume. The result is the Volume-Weighted-Average-Market-Pair-Price (VWAMPP) for each cryptocurrency.

Downloads

18

Readme

crypto-aggregator

Continuously scans exchanges and calculates the volume-weighted average market pair price (VWAMPP) of each cryptocurrency.

NPM NPM Downloads

  • [x] Based on ccxt
  • [x] Supports more than 120 bitcoin/altcoin exchanges
  • [x] Evaluates all pairs in the given exchanges and averages the price of each coin
  • [x] Filters out outliers
  • [x] Accepts API key from https://openexchangerates.org/ to convert between foreign exchanges
  • [x] Accepts callbacks for each time the price is updated

What is volume-weighted average market pair price (VWAMPP)?

For more details on how VWAMPP is calculated and why it is used, see this article.

Installation

npm install crypto-aggregator --save

Screenshot

examples/demo.js Output example

Usage

Simple

In its simplest form, it can run as:

let options = {
  // Forex conversions
  getForexData_oxr: true, // Mocked values will be uses if set to false
  osx_app_id: "YOUR_OSX_APP_ID" // openexchangerates.org app id
};

var ca = require("../index.js")(options);
ca.start(options);

Other options and default values

Below are other options and their default values:

options: {
    loopForEver: true,
    maxNumberOfIterations: 10, // ignored if loopForEver == true

    printBanner: true,

    getCoinGeckoPrices: true, // Get CoinGecko prices as a reference to compare our prices (optional)

    // Forex conversions
    getForexData_oxr: false,  // Mocked values will be uses if set to false
    osx_app_id: "YOUR_OSX_APP_ID", // openexchangerates.org app id

    // control
    enable: true, // Used for start/stop

    // Outlier detection
    bypassOutliers: true, // Ignores outliers
    outlierStandardDeviationDistanceFromMean: 3, // distance from mean for an outlier in sigma

    aggregatePriceInterval_ms: 5000,  // Aggregate price rate
    coingGeckoUpdateInterval_ms: 100 * 1000,  // CoinGecko Refresh rate
    statusBarTextInterval_ms: 1000, // Status bar update refersh rate

    aggregatePricesCallBack: null, // Called whenever the partial WVAP is calculated
    iterationCallBack: null, // Calculated whenever all exchanges and pairs were queired at the end of one iteration
    discoveredOneTickerCallBack:null,  // Called whenever found a new pair on an exchange


    bPrintStatus: true, //Print the status bar
    printAllPrices: true, // Print a summary table in the log file
    coinsInStatusBar: ["BTC", "ETH"], // Coins to be shown in the summary status bar

    ccxtExchangeRateLimitDivider:1,  // Divides CCXT's recommended rateLimit time if filling adventerous!

    // Exchanges to query from
    trustedExchanges: [
      "huobipro",
      "kraken",
      "binance",
      "bittrex",
      "bitmex",
      "bitstamp",
      "coinbasepro",
      "gemini",
      "itbit",
      "bitflyer",
      "poloniex",
      "independentreserve",

      "liquid",
      "upbit"
    ],

    // Exchanges to exclude even if they are in trustedExchanges
    excludeExchanges: [
      "_1btcxe",
      "allcoin",
      "theocean",
      "xbtce",
      "cointiger",
      "bibox",
      "coolcoin",
      "uex",
      "dsx",
      "flowbtc",
      "bcex"
    ]
  }

Data Structure and Callbacks

For simplicity, all discovered data and VWAMPP price for all cryptocurrencies is kept in memory. Callback functions are provided which can be used to write data in your own database.

The in-memory values are as follows:

VWAMPP Prices

The VWAMPP price for all cryptos are in pricesInUSD. Example:

let options = {
  // Forex conversions
  getForexData_oxr: false, // Mocked values will be uses if set to false
  osx_app_id: "YOUR_OSX_APP_ID" // openexchangerates.org app id
};

var ca = require("../index.js")(options);
ca.start(options);

// Print the calculated VWAMPP price of BTC after 5 minutes:
setTimeout(() => {
  let pricesInUSD = ca.pricesInUSD;
  let log = ca.log;

  log.info(`BTC price is: `, pricesInUSD["BTC"]);
}, 5 * 60 * 1000);

Market Pairs

Makrket pairs are kept inside an object called tickers. They are organized under a tree of:

let cryptoName = "BTC"; // String
let exchangeName = "binance"; // String
let index = 0; // String
tickers[cryptoName][exchangeName]["pairs"][index].ticker;
tickers[cryptoName][exchangeName]["pairs"][index].market;

where market and ticker are taken directly from ccxt output of fetchTicker and fetchMarkets functions.

Example:

let options = {
  // Forex conversions
  getForexData_oxr: true, // Mocked values will be uses if set to false
  osx_app_id: "YOUR_OSX_APP_ID" // openexchangerates.org app id
};

var ca = require("../index.js")(options);
ca.start(options);

// Print discovered tickers after 5 minutes:
setTimeout(() => {
  let tickers = ca.tickers;
  let log = ca.log;

  log.info(`tickers=`, JSON.stringify(tickers));
}, 5 * 60 * 1000);

// Output:
// INFO: tickers = {
//     'BTC' : {
//       'binance': {
//         pairs: [{ticker: {...}, market: {symbol: 'BTC/USDT', ...}},
//                 {ticker: {...}, market: {symbol: 'BTC/BNB', ...}}
//                 ]
//       },
//       'kraken': {
//         pairs: [{ticker: {...}, market: {symbol: 'ETH/BTC', ...}},
//                 {ticker: {...}, market: {symbol: 'BTC/USDT', ...}},
//               ]
//       }
//     }
//  ...
//   }

Logger

The logger used in this package is available separately in log-with-statusbar npm package

License

Free to use under ICS. Backlinks and credit are greatly appreciated!

Issue and Pull Requests

Issues, contributions, and pull requests are welcome!