n8n-nodes-fxcm
Version:
n8n node for FXCM trading integration
39 lines (38 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.execute = execute;
const FxcmClient_1 = require("../../Fxcm/FxcmClient");
async function execute() {
const credentials = await this.getCredentials('fxcmApi');
const client = new FxcmClient_1.FxcmClient(credentials);
const instrument = this.getNodeParameter('instrument', 0);
const startDate = this.getNodeParameter('startDate', 0);
const endDate = this.getNodeParameter('endDate', 0);
const timeframe = this.getNodeParameter('timeframe', 0);
try {
const historicalData = await client.getHistoricalData(instrument, new Date(startDate), new Date(endDate), timeframe);
// Transform historical data to OHLC format
const formattedData = historicalData.map((candle) => ({
timestamp: candle.timestamp,
open: candle.open,
high: candle.high,
low: candle.low,
close: candle.close,
volume: candle.volume,
instrument,
timeframe,
}));
return [{ json: { data: formattedData } }];
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to get historical data: ${error.message}`);
}
else {
throw new Error('Failed to get historical data: Unknown error');
}
}
finally {
client.disconnect();
}
}