Skip to content

Commit 6348a8c

Browse files
authored
needs to do #symbolKey
1 parent ef7a4e1 commit 6348a8c

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/quote/market.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
/**
66
* @param {import('./session').QuoteSessionBridge} quoteSession
77
*/
8+
89
module.exports = (quoteSession) => class QuoteMarket {
910
#symbolListeners = quoteSession.symbolListeners;
1011

1112
#symbol;
13+
1214
#session;
1315

16+
#symbolKey;
17+
1418
#symbolListenerID = 0;
1519

1620
#lastData = {};
@@ -44,17 +48,19 @@ module.exports = (quoteSession) => class QuoteMarket {
4448
constructor(symbol, session = 'regular') {
4549
this.#symbol = symbol;
4650
this.#session = session;
51+
this.#symbolKey = `=${JSON.stringify({ session, symbol })}`
4752

48-
if (!this.#symbolListeners[symbol]) {
49-
this.#symbolListeners[symbol] = [];
53+
if (!this.#symbolListeners[this.#symbolKey]) {
54+
this.#symbolListeners[this.#symbolKey] = [];
5055
quoteSession.send('quote_add_symbols', [
5156
quoteSession.sessionID,
52-
`=${JSON.stringify({ session, symbol })}`
57+
this.#symbolKey,
5358
]);
5459
}
55-
this.#symbolListenerID = this.#symbolListeners[symbol].length;
5660

57-
this.#symbolListeners[symbol][this.#symbolListenerID] = (packet) => {
61+
this.#symbolListenerID = this.#symbolListeners[this.#symbolKey].length;
62+
63+
this.#symbolListeners[this.#symbolKey][this.#symbolListenerID] = (packet) => {
5864
if (global.TW_DEBUG) console.log('§90§30§105 MARKET §0 DATA', packet);
5965

6066
if (packet.type === 'qsd' && packet.data[1].s === 'ok') {
@@ -115,12 +121,12 @@ module.exports = (quoteSession) => class QuoteMarket {
115121

116122
/** Close this listener */
117123
close() {
118-
if (this.#symbolListeners[this.#symbol].length <= 1) {
124+
if (this.#symbolListeners[this.#symbolKey].length <= 1) {
119125
quoteSession.send('quote_remove_symbols', [
120126
quoteSession.sessionID,
121-
this.#symbol,
127+
this.#symbolKey,
122128
]);
123129
}
124-
delete this.#symbolListeners[this.#symbol][this.#symbolListenerID];
130+
delete this.#symbolListeners[this.#symbolKey][this.#symbolListenerID];
125131
}
126132
};

0 commit comments

Comments
 (0)