UNPKG

@dendaio/n8n-nodes-collection

Version:

🚀 Comprehensive n8n node collection for financial analysis and automation. Features 55+ technical indicators (RSI, MACD, Bollinger Bands), 32+ candlestick patterns (Doji, Hammer, Engulfing), automated trading strategies, RSS feed processing, and OAuth2 v

359 lines • 16.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.VolumeIndicators = void 0; const n8n_workflow_1 = require("n8n-workflow"); const indicatorts = __importStar(require("indicatorts")); const technicalindicators = __importStar(require("technicalindicators")); class VolumeIndicators { constructor() { this.description = { displayName: 'Volume Indicators', name: 'volumeIndicators', icon: 'file:icon.svg', group: ['transform'], version: 1, description: 'Calculate volume indicators using the indicatorts library', defaults: { name: 'Volume Indicators', }, inputs: ["main"], outputs: ["main"], properties: [ { displayName: 'Indicators', name: 'indicators', type: 'multiOptions', options: [ { name: 'Accumulation Distribution (AD)', value: 'accumulationDistribution', description: 'Measures buying and selling pressure using volume and price', }, { name: 'Chaikin Money Flow (CMF)', value: 'chaikinMoneyFlow', description: 'Measures money flow volume over a specific period', }, { name: 'Ease of Movement (EMV)', value: 'easeOfMovement', description: 'Measures how easily prices move based on volume', }, { name: 'Force Index (FI)', value: 'forceIndex', description: 'Measures the power behind price movements using volume', }, { name: 'Money Flow Index (MFI)', value: 'moneyFlowIndex', description: 'Volume-weighted RSI that measures buying and selling pressure', }, { name: 'Negative Volume Index (NVI)', value: 'negativeVolumeIndex', description: 'Focuses on periods when volume decreases', }, { name: 'On Balance Volume (OBV)', value: 'onBalanceVolume', description: 'Measures buying and selling pressure using volume flow', }, { name: 'Volume Price Trend (VPT)', value: 'volumePriceTrend', description: 'Cumulative volume indicator that shows price trend', }, { name: 'Volume Profile (VP)', value: 'volumeProfile', description: 'Shows volume distribution across price levels', }, { name: 'Volume Weighted Average Price (VWAP)', value: 'volumeWeightedAveragePrice', description: 'Average price weighted by volume', }, ], default: ['onBalanceVolume'], noDataExpression: true, }, { displayName: 'OHLCV Data', name: 'ohlcvData', type: 'string', default: '={{ $json.ohlcv }}', description: 'JSON string containing OHLCV data array', }, { displayName: 'CMF Period', name: 'cmfPeriod', type: 'number', default: 20, description: 'Period for CMF calculation', displayOptions: { show: { indicators: ['chaikinMoneyFlow'], }, }, }, { displayName: 'EMV Period', name: 'emvPeriod', type: 'number', default: 14, description: 'Period for EMV calculation', displayOptions: { show: { indicators: ['easeOfMovement'], }, }, }, { displayName: 'Force Index Period', name: 'fiPeriod', type: 'number', default: 13, description: 'Period for Force Index calculation', displayOptions: { show: { indicators: ['forceIndex'], }, }, }, { displayName: 'MFI Period', name: 'mfiPeriod', type: 'number', default: 14, description: 'Period for MFI calculation', displayOptions: { show: { indicators: ['moneyFlowIndex'], }, }, }, { displayName: 'NVI Period', name: 'nviPeriod', type: 'number', default: 1, description: 'Period for NVI calculation', displayOptions: { show: { indicators: ['negativeVolumeIndex'], }, }, }, { displayName: 'NVI Start Value', name: 'nviStart', type: 'number', default: 1000, description: 'Starting value for NVI calculation', displayOptions: { show: { indicators: ['negativeVolumeIndex'], }, }, }, { displayName: 'VWAP Period', name: 'vwapPeriod', type: 'number', default: 14, description: 'Period for VWAP calculation', displayOptions: { show: { indicators: ['volumeWeightedAveragePrice'], }, }, }, { displayName: 'Volume Profile Number of Bars', name: 'vpNoOfBars', type: 'number', default: 10, description: 'Number of price bars for Volume Profile calculation', displayOptions: { show: { indicators: ['volumeProfile'], }, }, }, { displayName: 'Options', name: 'options', type: 'collection', placeholder: 'Add Option', default: {}, options: [ { displayName: 'Return Type', name: 'returnType', type: 'options', options: [ { name: 'Values Only', value: 'values', description: 'Return only the calculated values', }, { name: 'With Metadata', value: 'metadata', description: 'Return values with additional metadata', }, ], default: 'values', }, ], }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const indicators = this.getNodeParameter('indicators', i); const ohlcvDataString = this.getNodeParameter('ohlcvData', i); const options = this.getNodeParameter('options', i, {}); let ohlcvData; try { ohlcvData = JSON.parse(ohlcvDataString); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to parse OHLCV data: ${error instanceof Error ? error.message : 'Unknown error'}`); } if (!Array.isArray(ohlcvData) || ohlcvData.length === 0) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'OHLCV data must be a non-empty array'); } const highs = ohlcvData.map((candle) => candle[1]); const lows = ohlcvData.map((candle) => candle[2]); const closes = ohlcvData.map((candle) => candle[3]); const volumes = ohlcvData.map((candle) => candle[4] || 0); const indicatorPromises = indicators.map(async (indicator) => { const mappedParameters = {}; let result; switch (indicator) { case 'accumulationDistribution': result = indicatorts.accumulationDistribution(highs, lows, closes, volumes); break; case 'chaikinMoneyFlow': mappedParameters.period = this.getNodeParameter('cmfPeriod', i, 20); result = indicatorts.chaikinMoneyFlow(highs, lows, closes, volumes, mappedParameters); break; case 'easeOfMovement': mappedParameters.period = this.getNodeParameter('emvPeriod', i, 14); result = indicatorts.easeOfMovement(highs, lows, volumes, mappedParameters); break; case 'forceIndex': mappedParameters.period = this.getNodeParameter('fiPeriod', i, 13); result = indicatorts.forceIndex(closes, volumes, mappedParameters); break; case 'moneyFlowIndex': mappedParameters.period = this.getNodeParameter('mfiPeriod', i, 14); result = indicatorts.moneyFlowIndex(highs, lows, closes, volumes, mappedParameters); break; case 'negativeVolumeIndex': mappedParameters.period = this.getNodeParameter('nviPeriod', i, 1); mappedParameters.start = this.getNodeParameter('nviStart', i, 1000); result = indicatorts.negativeVolumeIndex(closes, volumes, mappedParameters); break; case 'onBalanceVolume': result = indicatorts.onBalanceVolume(closes, volumes); break; case 'volumePriceTrend': result = indicatorts.volumePriceTrend(closes, volumes); break; case 'volumeWeightedAveragePrice': mappedParameters.period = this.getNodeParameter('vwapPeriod', i, 14); result = indicatorts.volumeWeightedAveragePrice(closes, volumes, mappedParameters); break; case 'volumeProfile': mappedParameters.noOfBars = this.getNodeParameter('vpNoOfBars', i, 10); const opens = ohlcvData.map((candle) => candle[0]); result = technicalindicators.volumeprofile({ open: opens, high: highs, low: lows, close: closes, volume: volumes, noOfBars: mappedParameters.noOfBars, }); break; default: throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unsupported indicator: ${indicator}`); } return { indicator, parameters: mappedParameters, result, }; }); const indicatorResults = await Promise.all(indicatorPromises); const outputData = { indicators: indicatorResults, }; if (options.returnType === 'metadata') { outputData.metadata = { inputLength: ohlcvData.length, indicatorsCount: indicators.length, calculationTimestamp: new Date().toISOString(), }; } returnData.push({ json: outputData, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error instanceof Error ? error.message : 'Unknown error occurred', }, }); continue; } throw error; } } return [returnData]; } } exports.VolumeIndicators = VolumeIndicators; //# sourceMappingURL=VolumeIndicators.node.js.map