UNPKG

tradingview-api-adapter

Version:

API Adapter for real-time market data as quoted prices and symbol ticker details from Tradingview

54 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Quote = void 0; const QuoteSessionAdapter_1 = require("./adapters/QuoteSessionAdapter"); class Quote { constructor(quoteSessionBridge, ticker, market, fields = []) { this.isChannelActive = false; this.$adapter = new QuoteSessionAdapter_1.QuoteSessionAdapter(quoteSessionBridge); this.fieldList = new Set(fields); this.pair = `${market}:${ticker}`; // this.pair = `${ticker}:${market}`; example for debugging error throw this.resume(); } resume() { if (this.isChannelActive) return; this.isChannelActive = true; this.$adapter.setFields(this.fieldList); this.$adapter.addPairs(this.pair); } pause() { if (!this.isChannelActive) return; this.isChannelActive = false; this.$adapter.removePairs(this.pair); } 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); } } exports.Quote = Quote; //# sourceMappingURL=Quote.js.map