UNPKG

n8n-nodes-fxcm

Version:
39 lines (38 loc) 1.25 kB
"use strict"; 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 fxcmCredentials = { apiToken: credentials.apiToken, apiUrl: credentials.apiUrl, accountType: credentials.accountType, tradingStationId: credentials.tradingStationId, }; const client = new FxcmClient_1.FxcmClient(fxcmCredentials); const instrument = this.getNodeParameter('instrument', 0); try { const prices = await client.getPrices(instrument); return [{ json: { instrument, bid: prices.bid, ask: prices.ask, timestamp: prices.timestamp, spread: prices.ask - prices.bid, }, }]; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get current price: ${error.message}`); } else { throw new Error('Failed to get current price: Unknown error'); } } finally { client.disconnect(); } }