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

candlejs

v0.2.1

Published

Candlestick Chart & Time Series

Downloads

3

Readme

candlejs candlejs

Candlestick Charting for Time Series

candlejs is used for charting real-time market data such as stock or future prices. It's light weight and high performance with no dependency on other packages. It's optimal for intra-day trading scenarios.

License npm npm

Example

Installations

Fork & Development

git clone https://github.com/rp8/candlejs.git
cd candlejs
npm install

Use Only

npm install candlejs --save

Dev & Test

  1. npm run build
  2. open test/candle.html in Chrome to test simple simulator & chart
  3. open test/candle.html in Chrome to test more with tick data from files and simulator
  4. npm run test

Usages

var cjs = require('candle');

TickSeries - Tick time series

var ticks = new cjs.TickSeries('AAPL');
ticks.on('changed', () => {
  ...
};
ticks.add(time, price, volume);
ticks.trimOldData(1000, 10000);
ticks.clear();
for var tick in ticks.data {
  ...
}

Bars - Bar time series of intervals such as daily, hourly, 5 min, etc

var dailyBars = new cjs.Bars('AAPL', 24*3600*1000);
dailyBars.add(time, open, high, low, close, volume);
dailyBars.addTick(tick);
dailyBars.addTicks(ticks);
dailyBars.on('changed', () => {
  ...
});
...
dailyBars.clear();

Simulator - Simulating price time series

var s = new cjs.Simulator(0.10, 100.00, 100);
s.onData((err, data) => {
  ...
});
s.start();
s.stop();

CandleChart

var chart = new cjs.CandleChart({candleWidth: 4});
var bars = new cjs.Bars('AAPL', 24*3600*1000);
chart.addSeries(bars);
chart.outputTo(canvas);
chart.render();
chart.setDisplayRange(openTime, closeTime);
...
chart will update with the streaming data coming from bars.

LineReader - Reading data from a local file

var lr = new cjs.LineReader();
var bars = new cjs.Bars('AAPL', 24*3600*1000);
bars.sort(function(a, b) {
  return a[0] - b[0];
});

var bars0 = [];
lr.on('end', function() {
  for (i = 0; i < bars0.length; i++) {
    var b = bars0[i];
    bars.add(b[0], b[1], b[2], b[3], b[4], b[5]);
  }
});

lr.on('line', function (line, next) {
  if (line.indexOf('Date') === -1) {
    var bar = line.split(',');
    bars0.push([
      new Date(bar[0]).getTime(),
      parseFloat(bar[1]), 
      parseFloat(bar[2]), 
      parseFloat(bar[3]), 
      parseFloat(bar[4]), 
      parseFloat(bar[5])
    ]);
  } 
  next();
});

lr.read($('file').files[0]);

HTML

<html>
<head>
  <script type="text/javascript" src="../dist/candle.min.js"></script>
</head>
<body>
  <button id="start">Start</button>
  <button id="stop">Stop</button>
  <hr>
  <canvas id="chart" width="800" height="300"></canvas>

  <script type="text/javascript">
    function $(name) {
      return document.getElementById(name);
    };

    var cjs = require('candle');

    var chart = new cjs.CandleChart({candleWidth: 4});
    chart.outputTo($('chart'));

    var bars = new cjs.Bars('TSL', 3600*24*1000);
    chart.addSeries(bars);

    var s = new cjs.Simulator(0.10, 99, 10);
    var openTime;
    s.onData((err, data) => {
      openTime += bars.interval/20;
      bars.addTick([openTime, data[1], data[2]]);
      chart.render();
    });

    $('start').addEventListener('click', function() {
      console.log('simulated price started...');
      bars.clear();
      openTime = new Date().getTime();
      s.start();
    });

    $('stop').addEventListener('click', function() {
      console.log('simulated price stopped...');
      s.stop();
    });

  </script>

</body>
</html>

FAQ

Issues

Changelog

1/20/2019:

  1. added fixed to fix number of digits, default to 2 var Simulator = function (vol, value, delay, fixed) {...}
  2. added new mthod to draw horizontal lines CandleChart.prototype.addYLine = function(color, text, price) {..}

License

candlejs is licensed under the MIT License © 2015-2019 Ronggen Pan