|
5 | 5 | /** |
6 | 6 | * @param {import('./session').QuoteSessionBridge} quoteSession |
7 | 7 | */ |
| 8 | + |
8 | 9 | module.exports = (quoteSession) => class QuoteMarket { |
9 | 10 | #symbolListeners = quoteSession.symbolListeners; |
10 | 11 |
|
11 | 12 | #symbol; |
| 13 | + |
12 | 14 | #session; |
13 | 15 |
|
| 16 | + #symbolKey; |
| 17 | + |
14 | 18 | #symbolListenerID = 0; |
15 | 19 |
|
16 | 20 | #lastData = {}; |
@@ -44,17 +48,19 @@ module.exports = (quoteSession) => class QuoteMarket { |
44 | 48 | constructor(symbol, session = 'regular') { |
45 | 49 | this.#symbol = symbol; |
46 | 50 | this.#session = session; |
| 51 | + this.#symbolKey = `=${JSON.stringify({ session, symbol })}` |
47 | 52 |
|
48 | | - if (!this.#symbolListeners[symbol]) { |
49 | | - this.#symbolListeners[symbol] = []; |
| 53 | + if (!this.#symbolListeners[this.#symbolKey]) { |
| 54 | + this.#symbolListeners[this.#symbolKey] = []; |
50 | 55 | quoteSession.send('quote_add_symbols', [ |
51 | 56 | quoteSession.sessionID, |
52 | | - `=${JSON.stringify({ session, symbol })}` |
| 57 | + this.#symbolKey, |
53 | 58 | ]); |
54 | 59 | } |
55 | | - this.#symbolListenerID = this.#symbolListeners[symbol].length; |
56 | 60 |
|
57 | | - this.#symbolListeners[symbol][this.#symbolListenerID] = (packet) => { |
| 61 | + this.#symbolListenerID = this.#symbolListeners[this.#symbolKey].length; |
| 62 | + |
| 63 | + this.#symbolListeners[this.#symbolKey][this.#symbolListenerID] = (packet) => { |
58 | 64 | if (global.TW_DEBUG) console.log('§90§30§105 MARKET §0 DATA', packet); |
59 | 65 |
|
60 | 66 | if (packet.type === 'qsd' && packet.data[1].s === 'ok') { |
@@ -115,12 +121,12 @@ module.exports = (quoteSession) => class QuoteMarket { |
115 | 121 |
|
116 | 122 | /** Close this listener */ |
117 | 123 | close() { |
118 | | - if (this.#symbolListeners[this.#symbol].length <= 1) { |
| 124 | + if (this.#symbolListeners[this.#symbolKey].length <= 1) { |
119 | 125 | quoteSession.send('quote_remove_symbols', [ |
120 | 126 | quoteSession.sessionID, |
121 | | - this.#symbol, |
| 127 | + this.#symbolKey, |
122 | 128 | ]); |
123 | 129 | } |
124 | | - delete this.#symbolListeners[this.#symbol][this.#symbolListenerID]; |
| 130 | + delete this.#symbolListeners[this.#symbolKey][this.#symbolListenerID]; |
125 | 131 | } |
126 | 132 | }; |
0 commit comments