UNPKG

n8n-nodes-fxcm

Version:
31 lines (30 loc) 1 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 positionId = this.getNodeParameter('positionId', 0); try { const result = await client.closePosition(positionId); return [{ json: result }]; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to close position: ${error.message}`); } else { throw new Error('Failed to close position: Unknown error'); } } finally { client.disconnect(); } }