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