@sharplygroup/xtb-api-js
Version:
A module for interacting with the XTB API
112 lines • 3.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarketDataOperations = void 0;
class MarketDataOperations {
wsManager;
constructor(wsManager) {
this.wsManager = wsManager;
}
/**
* Returns calendar with market events.
* @returns {Promise<any>} // TODO: Create ICalendarResponse interface
*/
async getCalendar() {
const response = await this.wsManager.sendCommand({
command: "getCalendar",
arguments: {},
});
if (!response.status || !response.returnData) {
throw new Error(response.errorDescr || "Failed to get calendar");
}
return {
status: response.status,
returnData: response.returnData,
};
}
/**
* Returns chart info, from start date to the current time.
* @param {any} info - CHART_LAST_INFO_RECORD
* @returns {Promise<IChartResponse>}
*/
async getChartLastRequest(info) {
const response = (await this.wsManager.sendCommand({
command: "getChartLastRequest",
arguments: {
info: info,
},
}));
if (!response.status || !response.returnData) {
throw new Error(response.errorDescr || "Failed to get chart last request");
}
return {
status: response.status,
returnData: response.returnData,
};
}
/**
* Returns chart info with data between given start and end dates.
* @param {any} info - CHART_RANGE_INFO_RECORD
* @returns {Promise<IChartResponse>}
*/
async getChartRangeRequest(info) {
const response = (await this.wsManager.sendCommand({
command: "getChartRangeRequest",
arguments: {
info: info,
},
}));
if (!response.status || !response.returnData) {
throw new Error(response.errorDescr || "Failed to get chart range request");
}
return {
status: response.status,
returnData: response.returnData,
};
}
/**
* Returns array of current quotations for given symbols, only quotations that changed from given timestamp are returned.
* @param {number} level - price level
* @param {string[]} symbols - Array of symbol names (Strings)
* @param {number} timestamp - The time from which the most recent tick should be looked for.
* @returns {Promise<ITickPricesResponse>}
*/
async getTickPrices(level, symbols, timestamp) {
const response = (await this.wsManager.sendCommand({
command: "getTickPrices",
arguments: {
level: level,
symbols: symbols,
timestamp: timestamp,
},
}));
if (!response.status || !response.returnData) {
throw new Error(response.errorDescr || "Failed to get tick prices");
}
return {
status: response.status,
returnData: response.returnData,
};
}
/**
* Returns quotes and trading times.
* @param {string[]} symbols - Array of symbol names (Strings)
* @returns {Promise<ITradingHoursResponse>}
*/
async getTradingHours(symbols) {
const response = (await this.wsManager.sendCommand({
command: "getTradingHours",
arguments: {
symbols: symbols,
},
}));
if (!response.status || !response.returnData) {
throw new Error(response.errorDescr || "Failed to get trading hours");
}
return {
status: response.status,
returnData: response.returnData,
};
}
}
exports.MarketDataOperations = MarketDataOperations;
//# sourceMappingURL=MarketDataOperations.js.map