n8n-nodes-fxcm
Version:
n8n node for FXCM trading integration
33 lines (32 loc) • 1.16 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 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);
const stopLoss = this.getNodeParameter('stopLoss', 0);
const takeProfit = this.getNodeParameter('takeProfit', 0);
try {
const result = await client.modifyPosition(positionId, stopLoss, takeProfit);
return [{ json: result }];
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to modify position: ${error.message}`);
}
else {
throw new Error('Failed to modify position due to an unknown error');
}
}
finally {
client.disconnect();
}
}