n8n-nodes-fxcm
Version:
n8n node for FXCM trading integration
43 lines (42 loc) • 1.45 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 instrument = this.getNodeParameter('instrument', 0);
const orderType = this.getNodeParameter('orderType', 0);
const amount = this.getNodeParameter('amount', 0);
const price = this.getNodeParameter('price', 0);
const stopLoss = this.getNodeParameter('stopLoss', 0);
const takeProfit = this.getNodeParameter('takeProfit', 0);
try {
const order = await client.placeLimitOrder({
instrument,
isBuy: orderType === 'buy',
amount,
price,
stopLoss,
takeProfit,
});
return [{ json: order }];
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to place limit order: ${error.message}`);
}
else {
throw new Error('Failed to place limit order: Unknown error');
}
}
finally {
client.disconnect();
}
}