Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

candlestick-convert

5.1.3 • Public • Published

candlestick-convert

Coverage Status DeepScan grade npm

This package allow you to batch OHLCV candlesticks or creating them from trade(tick) data sets.

Supported formats:

  • OHLCV (CCXT format) [[time,open,high,low,close,volume]]
  • OHLCV JSON [{time: number,open: number, high: number, low: number close: number, volume: number}]
  • Trade JSON [{price: number, quantity: number, time:number}]

Features:

  • Typescript support!
  • CCXT support
  • No Dependencies
  • Performance single loop used
  • Skip missing candles

Important!:

  • Intervals only supported as second integers (1 minute = 60 , 2 minute = 120...)
  • Only positive integer multiplication allowed between base interval and the new interval. e.g. 60->120, 60->180

Install:

npm install candlestick-convert

Available functions:

import {batchCandleArray, batchCandleJSON, batchTickToCandle, ticksToTickChart} from "candlestick-convert";

batchCandleArray(candledata: OHLCV[], 60, 300) // return OHLCV[]
batchCandleJSON(candledata: IOHLCV [], 60, 300) // return IOHLCV[]
batchTicksToCandle(tradedata: TradeTick[], 60) // return IOHLCV[]
ticksToTickChart(tradedata: TradeTick[], 5) // return IOHLCV[]

Types

export type IOHLCV = {
  time: number;
  open: number;
  high: number;
  low: number;
  close: number;
  volume: number;
}

export type OHLCV = [
  number,
  number,
  number,
  number,
  number,
  number,
]

export type TradeTick = {
  price: number;
  quantity: number;
  time: number;
}

Examples

CCXT OHLCV:

import {batchCandleJSON} from "candlestick-convert";

const link_btc_1m = [
  {
    time: 1563625680000,
    open: 0.00024824,
    high: 0.00024851,
    low: 0.00024798,
    close: 0.00024831,
    volume: 2264
  },
  {
    time: 1563625740000,
    open: 0.00024817,
    high: 0.00024832,
    low: 0.00024795,
    close: 0.00024828,
    volume: 3145
  }];

const baseFrame = 60; // 60 seconds
const newFrame = 120; // 120 seconds

// Convert to 2m Candles

const link_btc_2m = batchCandleJSON(link_btc_1m, baseFrame, newFrame);

Tick Chart:

import {ticksToTickChart, TradeTick} from "candlestick-convert";

const adabnb_trades = [
  {
    time: "1564502620356",
    side: "sell",
    quantity: "4458",
    price: "0.00224",
    tradeId: "1221272"
  },
  {
    time: "1564503133949",
    side: "sell",
    quantity: "3480",
    price: "0.002242",
    tradeId: "1221273"
  },
  {
    time: "1564503134553",
    side: "buy",
    quantity: "51",
    price: "0.002248",
    tradeId: "1221274"
  }];


const filtered_adabnb_trades: TradeTick[] = adabnb_trades.map((trade: any) => ({
  time: trade.time,
  quantity: trade.quantity,
  price: trade.price
}));

const batchSize = 2; // Every TickCandle consist 2 trade
const tickChart = ticksToTickChart(filtered_adabnb_trades, batchSize);

Install

npm i candlestick-convert

DownloadsWeekly Downloads

5

Version

5.1.3

License

ISC

Unpacked Size

23 kB

Total Files

7

Last publish

Collaborators

  • avatar