UNPKG

@sharplygroup/xtb-api-js

Version:

A module for interacting with the XTB API

83 lines 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CalculationOperations = void 0; class CalculationOperations { wsManager; constructor(wsManager) { this.wsManager = wsManager; } /** * Returns calculation of commission and rate of exchange. * @param {string} symbol - symbol * @param {number} volume - volume * @returns {Promise<ICommissionResponse>} */ async getCommissionDef(symbol, volume) { const response = (await this.wsManager.sendCommand({ command: "getCommissionDef", arguments: { symbol: symbol, volume: volume, }, })); if (!response.status || !response.returnData) { throw new Error(response.errorDescr || "Failed to get commission definition"); } return { status: response.status, returnData: response.returnData, }; } /** * Returns expected margin for given instrument and volume. * @param {string} symbol - symbol * @param {number} volume - volume * @returns {Promise<IMarginTradeResponse>} */ async getMarginTrade(symbol, volume) { const response = (await this.wsManager.sendCommand({ command: "getMarginTrade", arguments: { symbol: symbol, volume: volume, }, })); if (!response.status || !response.returnData) { throw new Error(response.errorDescr || "Failed to get margin trade"); } return { status: response.status, returnData: response.returnData, }; } /** * Calculates estimated profit for given deal data. * @param {number} closePrice - theoretical close price of order * @param {number} cmd - Operation code * @param {number} openPrice - theoretical open price of order * @param {string} symbol - symbol * @param {number} volume - volume * @returns {Promise<IProfitCalculationResponse>} */ async getProfitCalculation(closePrice, cmd, openPrice, symbol, volume) { const response = (await this.wsManager.sendCommand({ command: "getProfitCalculation", arguments: { closePrice: closePrice, cmd: cmd, openPrice: openPrice, symbol: symbol, volume: volume, }, })); if (!response.status || !response.returnData) { throw new Error(response.errorDescr || "Failed to get profit calculation"); } return { status: response.status, returnData: response.returnData, }; } } exports.CalculationOperations = CalculationOperations; //# sourceMappingURL=CalculationOperations.js.map