@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
549 lines • 24.6 kB
JavaScript
"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.MomentumIndicators = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const indicatorts = __importStar(require("indicatorts"));
const technicalindicators = __importStar(require("technicalindicators"));
class MomentumIndicators {
constructor() {
this.description = {
displayName: 'Momentum Indicators',
name: 'momentumIndicators',
icon: 'file:icon.svg',
group: ['transform'],
version: 1,
description: 'Calculate momentum indicators using the indicatorts library',
defaults: {
name: 'Momentum Indicators',
},
inputs: ["main"],
outputs: ["main"],
properties: [
{
displayName: 'Indicators',
name: 'indicators',
type: 'multiOptions',
options: [
{
name: 'Awesome Oscillator (AO)',
value: 'awesomeOscillator',
description: 'Measures market momentum using median price',
},
{
name: 'Chaikin Oscillator',
value: 'chaikinOscillator',
description: 'Volume-based oscillator developed by Marc Chaikin',
},
{
name: 'Ichimoku Cloud',
value: 'ichimokuCloud',
description: 'Versatile indicator that defines support/resistance, trend, and momentum',
},
{
name: 'Percentage Price Oscillator (PPO)',
value: 'percentagePriceOscillator',
description: 'Momentum oscillator showing relationship between two EMAs',
},
{
name: 'Percentage Volume Oscillator (PVO)',
value: 'percentageVolumeOscillator',
description: 'Momentum oscillator for volume',
},
{
name: 'Price Rate of Change (ROC)',
value: 'priceRateOfChange',
description: 'Measures the speed and magnitude of price changes',
},
{
name: 'Relative Strength Index (RSI)',
value: 'relativeStrengthIndex',
description: 'Measures speed and magnitude of price changes',
},
{
name: 'Stochastic Oscillator',
value: 'stochasticOscillator',
description: 'Shows location of closing price relative to high-low range',
},
{
name: 'Stochastic RSI',
value: 'stochasticRSI',
description: 'Combines RSI and Stochastic to identify overbought/oversold conditions',
},
{
name: 'TRIX',
value: 'trix',
description: 'Triple Exponential Average - momentum oscillator',
},
{
name: 'Williams %R',
value: 'williamsR',
description: 'Momentum indicator measuring overbought/oversold levels',
},
],
default: ['relativeStrengthIndex'],
noDataExpression: true,
},
{
displayName: 'OHLCV Data',
name: 'ohlcvData',
type: 'string',
default: '={{ $json.ohlcv }}',
description: 'JSON string containing OHLCV data array',
},
{
displayName: 'AO Fast Period',
name: 'aoFast',
type: 'number',
default: 5,
description: 'Fast period for AO calculation',
displayOptions: {
show: {
indicators: ['awesomeOscillator'],
},
},
},
{
displayName: 'AO Slow Period',
name: 'aoSlow',
type: 'number',
default: 34,
description: 'Slow period for AO calculation',
displayOptions: {
show: {
indicators: ['awesomeOscillator'],
},
},
},
{
displayName: 'PPO Fast Period',
name: 'ppoFast',
type: 'number',
default: 12,
description: 'Fast period for PPO calculation',
displayOptions: {
show: {
indicators: ['percentagePriceOscillator'],
},
},
},
{
displayName: 'PPO Signal Period',
name: 'ppoSignal',
type: 'number',
default: 9,
description: 'Signal period for PPO calculation',
displayOptions: {
show: {
indicators: ['percentagePriceOscillator'],
},
},
},
{
displayName: 'PPO Slow Period',
name: 'ppoSlow',
type: 'number',
default: 26,
description: 'Slow period for PPO calculation',
displayOptions: {
show: {
indicators: ['percentagePriceOscillator'],
},
},
},
{
displayName: 'PVO Fast Period',
name: 'pvoFast',
type: 'number',
default: 12,
description: 'Fast period for PVO calculation',
displayOptions: {
show: {
indicators: ['percentageVolumeOscillator'],
},
},
},
{
displayName: 'PVO Signal Period',
name: 'pvoSignal',
type: 'number',
default: 9,
description: 'Signal period for PVO calculation',
displayOptions: {
show: {
indicators: ['percentageVolumeOscillator'],
},
},
},
{
displayName: 'PVO Slow Period',
name: 'pvoSlow',
type: 'number',
default: 26,
description: 'Slow period for PVO calculation',
displayOptions: {
show: {
indicators: ['percentageVolumeOscillator'],
},
},
},
{
displayName: 'ROC Period',
name: 'rocPeriod',
type: 'number',
default: 14,
description: 'Period for ROC calculation',
displayOptions: {
show: {
indicators: ['priceRateOfChange'],
},
},
},
{
displayName: 'RSI Period',
name: 'rsiPeriod',
type: 'number',
default: 14,
description: 'Period for RSI calculation',
displayOptions: {
show: {
indicators: ['relativeStrengthIndex'],
},
},
},
{
displayName: 'Stochastic D Period',
name: 'stochDPeriod',
type: 'number',
default: 3,
description: 'D period for Stochastic calculation',
displayOptions: {
show: {
indicators: ['stochasticOscillator'],
},
},
},
{
displayName: 'Stochastic RSI RSI Period',
name: 'stochRsiRsiPeriod',
type: 'number',
default: 14,
description: 'RSI period for Stochastic RSI calculation',
displayOptions: {
show: {
indicators: ['stochasticRSI'],
},
},
},
{
displayName: 'Stochastic RSI Stochastic Period',
name: 'stochRsiStochPeriod',
type: 'number',
default: 14,
description: 'Stochastic period for Stochastic RSI calculation',
displayOptions: {
show: {
indicators: ['stochasticRSI'],
},
},
},
{
displayName: 'Stochastic RSI K Period',
name: 'stochRsiKPeriod',
type: 'number',
default: 3,
description: 'K period for Stochastic RSI calculation',
displayOptions: {
show: {
indicators: ['stochasticRSI'],
},
},
},
{
displayName: 'Stochastic RSI D Period',
name: 'stochRsiDPeriod',
type: 'number',
default: 3,
description: 'D period for Stochastic RSI calculation',
displayOptions: {
show: {
indicators: ['stochasticRSI'],
},
},
},
{
displayName: 'TRIX Period',
name: 'trixPeriod',
type: 'number',
default: 15,
description: 'Period for TRIX calculation',
displayOptions: {
show: {
indicators: ['trix'],
},
},
},
{
displayName: 'Stochastic K Period',
name: 'stochKPeriod',
type: 'number',
default: 14,
description: 'K period for Stochastic calculation',
displayOptions: {
show: {
indicators: ['stochasticOscillator'],
},
},
},
{
displayName: 'Williams %R Period',
name: 'willrPeriod',
type: 'number',
default: 14,
description: 'Period for Williams %R calculation',
displayOptions: {
show: {
indicators: ['williamsR'],
},
},
},
{
displayName: 'Ichimoku Short Period',
name: 'ichimokuShort',
type: 'number',
default: 9,
description: 'Short period for Ichimoku Cloud calculation',
displayOptions: {
show: {
indicators: ['ichimokuCloud'],
},
},
},
{
displayName: 'Ichimoku Medium Period',
name: 'ichimokuMedium',
type: 'number',
default: 26,
description: 'Medium period for Ichimoku Cloud calculation',
displayOptions: {
show: {
indicators: ['ichimokuCloud'],
},
},
},
{
displayName: 'Ichimoku Long Period',
name: 'ichimokuLong',
type: 'number',
default: 52,
description: 'Long period for Ichimoku Cloud calculation',
displayOptions: {
show: {
indicators: ['ichimokuCloud'],
},
},
},
{
displayName: 'Ichimoku Close Period',
name: 'ichimokuClose',
type: 'number',
default: 3,
description: 'Close period for Ichimoku Cloud calculation',
displayOptions: {
show: {
indicators: ['ichimokuCloud'],
},
},
},
{
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 'awesomeOscillator':
mappedParameters.fast = this.getNodeParameter('aoFast', i, 5);
mappedParameters.slow = this.getNodeParameter('aoSlow', i, 34);
result = indicatorts.awesomeOscillator(highs, lows, mappedParameters);
break;
case 'chaikinOscillator':
mappedParameters.fast = this.getNodeParameter('chaikinFast', i, 3);
mappedParameters.slow = this.getNodeParameter('chaikinSlow', i, 10);
result = indicatorts.chaikinOscillator(highs, lows, closes, volumes, mappedParameters);
break;
case 'ichimokuCloud':
mappedParameters.short = this.getNodeParameter('ichimokuShort', i, 9);
mappedParameters.medium = this.getNodeParameter('ichimokuMedium', i, 26);
mappedParameters.long = this.getNodeParameter('ichimokuLong', i, 52);
mappedParameters.close = this.getNodeParameter('ichimokuClose', i, 3);
result = indicatorts.ichimokuCloud(highs, lows, closes, mappedParameters);
break;
case 'percentagePriceOscillator':
mappedParameters.fast = this.getNodeParameter('ppoFast', i, 12);
mappedParameters.slow = this.getNodeParameter('ppoSlow', i, 26);
mappedParameters.signal = this.getNodeParameter('ppoSignal', i, 9);
result = indicatorts.percentagePriceOscillator(closes, mappedParameters);
break;
case 'percentageVolumeOscillator':
mappedParameters.fast = this.getNodeParameter('pvoFast', i, 12);
mappedParameters.slow = this.getNodeParameter('pvoSlow', i, 26);
mappedParameters.signal = this.getNodeParameter('pvoSignal', i, 9);
result = indicatorts.percentageVolumeOscillator(volumes, mappedParameters);
break;
case 'priceRateOfChange':
mappedParameters.period = this.getNodeParameter('rocPeriod', i, 14);
result = indicatorts.priceRateOfChange(closes, mappedParameters);
break;
case 'relativeStrengthIndex':
mappedParameters.period = this.getNodeParameter('rsiPeriod', i, 14);
result = indicatorts.relativeStrengthIndex(closes, mappedParameters);
break;
case 'stochasticOscillator':
mappedParameters.kPeriod = this.getNodeParameter('stochKPeriod', i, 14);
mappedParameters.dPeriod = this.getNodeParameter('stochDPeriod', i, 3);
result = indicatorts.stochasticOscillator(highs, lows, closes, mappedParameters);
break;
case 'stochasticRSI':
mappedParameters.rsiPeriod = this.getNodeParameter('stochRsiRsiPeriod', i, 14);
mappedParameters.stochasticPeriod = this.getNodeParameter('stochRsiStochPeriod', i, 14);
mappedParameters.kPeriod = this.getNodeParameter('stochRsiKPeriod', i, 3);
mappedParameters.dPeriod = this.getNodeParameter('stochRsiDPeriod', i, 3);
result = technicalindicators.stochasticrsi({
values: closes,
rsiPeriod: mappedParameters.rsiPeriod,
stochasticPeriod: mappedParameters.stochasticPeriod,
kPeriod: mappedParameters.kPeriod,
dPeriod: mappedParameters.dPeriod,
});
break;
case 'trix':
mappedParameters.period = this.getNodeParameter('trixPeriod', i, 15);
result = indicatorts.trix(closes, mappedParameters);
break;
case 'williamsR':
mappedParameters.period = this.getNodeParameter('willrPeriod', i, 14);
result = indicatorts.williamsR(highs, lows, closes, mappedParameters);
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.MomentumIndicators = MomentumIndicators;
//# sourceMappingURL=MomentumIndicators.node.js.map