@@ -45,7 +45,9 @@ export default class Binance {
4545 dstreamSingleTest = `wss://dstream.binancefuture.${ this . domain } /ws/` ;
4646 dstreamTest = `wss://dstream.binancefuture.${ this . domain } /stream?streams=` ;
4747 stream = `wss://stream.binance.${ this . domain } :9443/ws/` ;
48+ streamTest = `wss://testnet.binance.vision/ws/` ;
4849 combineStream = `wss://stream.binance.${ this . domain } :9443/stream?streams=` ;
50+ combineStreamTest = `wss://testnet.binance.vision:9443/stream?streams=` ;
4951
5052 verbose = false ;
5153
@@ -241,6 +243,16 @@ export default class Binance {
241243 return this . dapi ;
242244 }
243245
246+ getCombineStreamUrl ( ) {
247+ if ( this . Options . test ) return this . combineStreamTest ;
248+ return this . combineStream ;
249+ }
250+
251+ getStreamUrl ( ) {
252+ if ( this . Options . test ) return this . streamTest ;
253+ return this . stream ;
254+ }
255+
244256 uuid22 ( a ?: any ) {
245257 return a ? ( a ^ Math . random ( ) * 16 >> a / 4 ) . toString ( 16 ) : ( ( [ 1e7 ] as any ) + 1e3 + 4e3 + 8e5 ) . replace ( / [ 0 1 8 ] / g, this . uuid22 ) ;
246258 }
@@ -1156,14 +1168,14 @@ export default class Binance {
11561168 host : this . parseProxy ( socksproxy ) [ 1 ] ,
11571169 port : this . parseProxy ( socksproxy ) [ 2 ]
11581170 } ) ;
1159- ws = new WebSocket ( this . stream + endpoint , { agent : agent } ) ;
1171+ ws = new WebSocket ( this . getStreamUrl ( ) + endpoint , { agent : agent } ) ;
11601172 } else if ( httpsproxy ) {
11611173 const config = url . parse ( httpsproxy ) ;
11621174 const agent = new HttpsProxyAgent ( config ) ;
11631175 if ( this . Options . verbose ) this . Options . log ( 'using proxy server ' + agent ) ;
1164- ws = new WebSocket ( this . stream + endpoint , { agent : agent } ) ;
1176+ ws = new WebSocket ( this . getStreamUrl ( ) + endpoint , { agent : agent } ) ;
11651177 } else {
1166- ws = new WebSocket ( this . stream + endpoint ) ;
1178+ ws = new WebSocket ( this . getStreamUrl ( ) + endpoint ) ;
11671179 }
11681180
11691181 if ( this . Options . verbose ) this . Options . log ( 'Subscribed to ' + endpoint ) ;
@@ -1206,14 +1218,14 @@ export default class Binance {
12061218 host : this . parseProxy ( socksproxy ) [ 1 ] ,
12071219 port : this . parseProxy ( socksproxy ) [ 2 ]
12081220 } ) ;
1209- ws = new WebSocket ( this . combineStream + queryParams , { agent : agent } ) ;
1221+ ws = new WebSocket ( this . getCombineStreamUrl ( ) + queryParams , { agent : agent } ) ;
12101222 } else if ( httpsproxy ) {
12111223 if ( this . Options . verbose ) this . Options . log ( 'using proxy server ' + httpsproxy ) ;
12121224 const config = url . parse ( httpsproxy ) ;
12131225 const agent = new HttpsProxyAgent ( config ) ;
1214- ws = new WebSocket ( this . combineStream + queryParams , { agent : agent } ) ;
1226+ ws = new WebSocket ( this . getCombineStreamUrl ( ) + queryParams , { agent : agent } ) ;
12151227 } else {
1216- ws = new WebSocket ( this . combineStream + queryParams ) ;
1228+ ws = new WebSocket ( this . getCombineStreamUrl ( ) + queryParams ) ;
12171229 }
12181230
12191231 ws . reconnect = this . Options . reconnect ;
0 commit comments