@@ -44,6 +44,7 @@ class BinanceBase extends BasicClient {
4444 restThrottleMs = 1000 ,
4545 l2updateSpeed = "" ,
4646 l2snapshotSpeed = "" ,
47+ batchTickers = true ,
4748 } = { } ) {
4849 super ( wssPath , name , undefined , watcherMs ) ;
4950 this . _restL2SnapshotPath = restL2SnapshotPath ;
@@ -57,6 +58,7 @@ class BinanceBase extends BasicClient {
5758 this . hasCandles = true ;
5859 this . hasLevel2Snapshots = true ;
5960 this . hasLevel2Updates = true ;
61+ this . batchTickers = batchTickers ;
6062
6163 this . _messageId = 0 ;
6264 this . _tickersActive = false ;
@@ -80,25 +82,27 @@ class BinanceBase extends BasicClient {
8082 super . _onClosing ( ) ;
8183 }
8284
83- _sendSubTicker ( ) {
85+ _sendSubTicker ( remote_id ) {
8486 if ( this . _tickersActive ) return ;
8587 this . _tickersActive = true ;
88+ const params = this . batchTickers ? [ '!ticker@arr' ] : [ `${ remote_id . toLowerCase ( ) } @ticker` ] ;
8689 this . _wss . send (
8790 JSON . stringify ( {
8891 method : "SUBSCRIBE" ,
89- params : [ "!ticker@arr" ] ,
92+ params : params ,
9093 id : ++ this . _messageId ,
9194 } )
9295 ) ;
9396 }
9497
95- _sendUnsubTicker ( ) {
98+ _sendUnsubTicker ( remote_id ) {
9699 if ( this . _tickerSubs . size > 1 ) return ;
97100 this . _tickersActive = false ;
101+ const params = this . batchTickers ? [ '!ticker@arr' ] : [ `${ remote_id . toLowerCase ( ) } @ticker` ] ;
98102 this . _wss . send (
99103 JSON . stringify ( {
100104 method : "UNSUBSCRIBE" ,
101- params : [ "!ticker@arr" ] ,
105+ params : params ,
102106 id : ++ this . _messageId ,
103107 } )
104108 ) ;
@@ -204,7 +208,7 @@ class BinanceBase extends BasicClient {
204208 return ;
205209 }
206210
207- // ticker
211+ // batch tickers
208212 if ( msg . stream === "!ticker@arr" ) {
209213 for ( let raw of msg . data ) {
210214 let remote_id = raw . s ;
@@ -217,6 +221,17 @@ class BinanceBase extends BasicClient {
217221 return ;
218222 }
219223
224+ // single ticker
225+ if ( msg . stream . toLowerCase ( ) . endsWith ( "ticker" ) ) {
226+ let remote_id = msg . data . s ;
227+ let market = this . _tickerSubs . get ( remote_id ) ;
228+ if ( ! market ) return ;
229+
230+ let ticker = this . _constructTicker ( msg . data , market ) ;
231+ this . emit ( "ticker" , ticker , market ) ;
232+ return ;
233+ }
234+
220235 // trades
221236 if ( msg . stream . toLowerCase ( ) . endsWith ( "trade" ) ) {
222237 let remote_id = msg . data . s ;
0 commit comments