UNPKG

pricehistory

Version:
36 lines (35 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const simpul_1 = require("simpul"); function setCandleVolume(option, curr, candle, series, volumeRate) { var _a; const volume = option.volume && curr[option.volume]; if (typeof volume === "number" && volume > 0) { candle.volume = volume; } if (typeof volumeRate === "number" && typeof candle.priceRangeDiff === "number") { const estimate = Math.round(volumeRate * candle.priceRangeDiff); if (typeof candle.volume !== "number") { candle.volume = estimate; candle.volumeFilled = true; } else { candle.volumeEstimate = estimate; candle.volumeDiff = simpul_1.math.change.percent(candle.volume, estimate); } } if (option.obv !== true || typeof candle.priceOpen !== "number" || typeof candle.priceClose !== "number" || typeof candle.volume !== "number") return; candle.obv = ((_a = series[series.length - 2]) === null || _a === void 0 ? void 0 : _a.obv) || 0; if (candle.priceClose > candle.priceOpen) { candle.obv += candle.volume; } else if (candle.priceClose < candle.priceOpen) { candle.obv -= candle.volume; } } exports.default = setCandleVolume;