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 = ; const sim = ; // 0.08 represents volatility coefficient (value from 0 - 1) // Create a map from the simulator properties to the module // propertiesconst simPropMap = ;simPropMap;simPropMap;simPropMap; // 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 nameconst simchart = ; simchart;/*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 = ;var CoinbasePro = ; const coinbase_credentials = key: 'fakekey123fakekey123fakekey123' secret: 'fakesecret123fakesecret123fakesecret123fakesecret123fakesecret123fakesecret123' passphrase: 'fakepassphrase123'; const cbp = 'BTC-USD' 'wss://ws-feed.pro.coinbase.com' coinbase_credentials channels: 'matches' ; // Create the propMap for coinbase's matches channelconst cbpPropMap = ;cbpPropMap;cbpPropMap;cbpPropMap; // Instantiate chart with socket, interval and config objectconst cbpchart = ; cbpchart;cbpchart; /*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 = ;const exchangeChart = const newWebsocket = ...options;exchangeChart; // 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