tradingview-api-adapter
Version:
API Adapter for real-time market data as quoted prices and symbol ticker details from Tradingview
67 lines • 2.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuoteChannel = void 0;
const QuoteSessionAdapter_1 = require("./adapters/QuoteSessionAdapter");
class QuoteChannel {
constructor(quoteSessionBridge, pairGroups, fields = []) {
this.isChannelActive = false;
this.pairList = new Set();
this.$adapter = new QuoteSessionAdapter_1.QuoteSessionAdapter(quoteSessionBridge, true);
this.pairGroupSerializer(pairGroups);
this.fieldList = new Set(fields);
this.resume();
}
resume() {
if (this.isChannelActive)
return;
this.isChannelActive = true;
this.$adapter.setFields(this.fieldList);
this.$adapter.addPairs(this.pairList);
}
pause() {
if (!this.isChannelActive)
return;
this.isChannelActive = false;
this.$adapter.removePairs(this.pairList);
}
addFields(fields) {
if (typeof fields === 'string') {
this.fieldList.add(fields);
}
else {
fields.forEach(field => this.fieldList.add(field));
}
this.$adapter.setFields(this.fieldList);
}
removeFields(fields) {
if (typeof fields === 'string') {
this.fieldList.delete(fields);
}
else {
fields.forEach(field => this.fieldList.delete(field));
}
this.$adapter.setFields(this.fieldList);
}
setFields(fields) {
this.pause();
this.fieldList = new Set(fields);
this.resume();
}
listen(callback) {
this.$adapter.on('shaped_session_data', callback);
}
pairGroupSerializer(pairGroups) {
if (Array.isArray(pairGroups)) {
this.pairList = new Set(pairGroups);
}
else {
Object.keys(pairGroups).forEach((market) => {
pairGroups[market].forEach(ticker => {
this.pairList.add(`${market.toUpperCase()}:${ticker.toUpperCase()}`);
});
});
}
}
}
exports.QuoteChannel = QuoteChannel;
//# sourceMappingURL=QuoteChannel.js.map