UNPKG

n8n-nodes-fxcm

Version:
40 lines (39 loc) 1.36 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); const orderType = this.getNodeParameter('orderType', 0); const amount = this.getNodeParameter('amount', 0); const stopLoss = this.getNodeParameter('stopLoss', 0); const takeProfit = this.getNodeParameter('takeProfit', 0); try { const order = await client.placeMarketOrder({ instrument, isBuy: orderType === 'buy', amount, stopLoss, takeProfit, }); return [{ json: order, }]; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to place market order: ${error.message}`); } else { throw new Error('Failed to place market order: Unknown error'); } } }