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 🙏

© 2026 – Pkg Stats / Ryan Hefner

candlestick-models

v0.0.6

Published

A financial asset event-based candlestick chart modeler

Readme

Candlestick Models

An adaptable, event-driven market candlestick modeler. Ideal for generating candlestick models from any automated exchange that serves a websocket-based price stream.


This package generates candlestick models at any interval down to 1 second. The api provides a set of adapters that allow the consumer to plug into any automated financial exchange that offers a price websocket. Examples of use could be to wire up to a cryptocurrency market or a stock market exchange to generate computer-readable candlesticks that could, in turn, be used for algorithmic trading or analysis.

List of features

  • Usage of simple string-based interval specifier (ie '1s', '2m', '4h', etc)
  • Adapters to create a plugin interface with exchange price streams
  • Simple factory function instantiation
  • A price stream simulator that can be used to test adapter
  • ES5 implementation means use in older versions of Node
  • Websocket recycle utility to refresh supplied websocket with new websocket to prevent connection failures

Code Demo

Simulator Usage

const { Chart, Simulator } = require('candlestick-models');

const sim = Simulator(0.08); // 0.08 represents volatility coefficient (value from 0 - 1)

// Create a map from the simulator properties to the module 
// properties
const simPropMap = new Map();
simPropMap.set('price', 'price');
simPropMap.set('size', 'size');
simPropMap.set('symbol', 'symbol');

// Instantiate a chart from the module and pass in socket, 
// interval and config object including the propMap, a filter 
// function to filter only socket messages that pertain to 
// the price changes needed for the candles and either a 
// listener event name or a listener method name
const simchart = Chart(sim, '5s', {
  propMap: simPropMap,
  filterFn(message) { return message.type === 'last' },
  messageFn(message) { console.log(message) } // Will be executed on every message from the socket
  listenerEventName: 'quote'
});

simchart.on('close', console.log);
/*
Candlestick {
  symbol: 'TEST',
  high: 23.12,
  low: 23.09,
  last: 23.12,
  color: 1,
  open: 23.10,
  close: 23.11,
  volume: 200 }
Candlestick {
  symbol: 'TEST',
  high: 23.14,
  low: 23.11,
  last: 23.14,
  color: 1,
  open: 23.11,
  close: 23.14,
  volume: 200 }
*/

Exchange Usage (Coinbase)

const { Chart } = require('candlestick-models');
var CoinbasePro = require('coinbase-pro');

const coinbase_credentials = {
  key: 'fakekey123fakekey123fakekey123',
  secret: 'fakesecret123fakesecret123fakesecret123fakesecret123fakesecret123fakesecret123',
  passphrase: 'fakepassphrase123'
};

const cbp = new CoinbasePro.WebsocketClient(
  ['BTC-USD'],
  'wss://ws-feed.pro.coinbase.com',
  coinbase_credentials,
  { channels: ['matches'] }
);

// Create the propMap for coinbase's matches channel
const cbpPropMap = new Map();
cbpPropMap.set('price', 'price');
cbpPropMap.set('size', 'size');
cbpPropMap.set('symbol', 'product_id');

// Instantiate chart with socket, interval and config object
const cbpchart = Chart(cbp, '1m', {
  propMap: cbpPropMap,
  filterFn(message) { return message.type === 'match' },
  listenerEventName: 'message',
  errorEventName: 'error'
});

cbpchart.on('close', console.log);
cbpchart.on('error', (error) => throw new Error(error));

/*
Candlestick {
  timestamp: 'Mon Jul 29 2019 20:31:00 GMT-0500',
  symbol: 'BTC-USD',
  high: 7858,
  low: 7853.44,
  last: 7858,
  color: 1,
  open: 7854.43,
  close: 7858,
  volume: 1.2756039000000001 }
Candlestick {
  timestamp: 'Mon Jul 29 2019 20:32:00 GMT-0500',
  symbol: 'BTC-USD',
  high: 7858,
  low: 7854.24,
  last: 7858,
  color: 1,
  open: 7858,
  close: 7858,
  volume: 1.66471794 }
*/

Websocket recycling

const { Chart } = require('candlestick-models');
const exchangeChart = Chart({...config})
const newWebsocket = new ExchangeWebsocket({...options});
exchangeChart.recycleWebsocket(newWebsocket); // This will replace old websocket with fresh new websocket

Download & Installation

$ npm i candlestick-models 

Contributing

Send me PRs. I like contribution.

Authors or Acknowledgments

  • Matthew Herron

License

This project is licensed under the MIT License