@@ -96,8 +96,6 @@ class WSv2 extends EventEmitter {
9696 super ( )
9797
9898 this . setMaxListeners ( 1000 )
99- this . _apiKey = opts . apiKey || ''
100- this . _apiSecret = opts . apiSecret || ''
10199 this . _affCode = opts . affCode
102100 this . _agent = opts . agent
103101 this . _url = opts . url || WSv2 . url
@@ -117,7 +115,10 @@ class WSv2 extends EventEmitter {
117115 this . _orderBooks = { }
118116 this . _losslessOrderBooks = { }
119117 this . _candles = { }
120- this . _authArgs = { }
118+ this . _authArgs = {
119+ apiKey : opts . apiKey ,
120+ apiSecret : opts . apiSecret
121+ }
121122
122123 /**
123124 * {
@@ -140,7 +141,7 @@ class WSv2 extends EventEmitter {
140141 this . _enabledFlags = this . _seqAudit ? WSv2 . flags . SEQ_ALL : 0
141142 this . _eventCallbacks = new CbQ ( )
142143 this . _isAuthenticated = false
143- this . _wasEverAuthenticated = false // used for auto-auth on reconnect
144+ this . _authOnReconnect = false // used for auto-auth on reconnect
144145 this . _lastPubSeq = - 1
145146 this . _lastAuthSeq = - 1
146147 this . _isOpen = false
@@ -176,6 +177,8 @@ class WSv2 extends EventEmitter {
176177 * @param {object } args - arguments
177178 * @param {number } [args.calc] - calc value
178179 * @param {number } [args.dms] - dms value, active 4
180+ * @param {number } [args.apiKey] API key
181+ * @param {number } [args.apiSecret] API secret
179182 * @see WSv2#auth
180183 */
181184 updateAuthArgs ( args = { } ) {
@@ -196,19 +199,6 @@ class WSv2 extends EventEmitter {
196199 return this . _authArgs
197200 }
198201
199- /**
200- * Update the internal API credentials, used on subsequent {@link WSv2#auth}
201- * calls
202- *
203- * @param {string } apiKey - API key
204- * @param {string } apiSecret - API secret
205- * @see WSv2#auth
206- */
207- setAPICredentials ( apiKey , apiSecret ) {
208- this . _apiKey = apiKey
209- this . _apiSecret = apiSecret
210- }
211-
212202 /**
213203 * Get the total number of data channels this instance is currently
214204 * subscribed too.
@@ -362,6 +352,7 @@ class WSv2 extends EventEmitter {
362352 * @returns {Promise } p
363353 */
364354 async auth ( calc , dms ) {
355+ this . _authOnReconnect = true
365356 if ( ! this . _isOpen ) {
366357 throw new Error ( 'not open' )
367358 }
@@ -372,7 +363,7 @@ class WSv2 extends EventEmitter {
372363
373364 const authNonce = nonce ( )
374365 const authPayload = `AUTH${ authNonce } ${ authNonce } `
375- const { sig } = genAuthSig ( this . _apiSecret , authPayload )
366+ const { sig } = genAuthSig ( this . _authArgs . apiSecret , authPayload )
376367 const authArgs = { ...this . _authArgs }
377368
378369 if ( _isFinite ( calc ) ) authArgs . calc = calc
@@ -386,7 +377,7 @@ class WSv2 extends EventEmitter {
386377
387378 this . send ( {
388379 event : 'auth' ,
389- apiKey : this . _apiKey ,
380+ apiKey : this . _authArgs . apiKey ,
390381 authSig : sig ,
391382 authPayload,
392383 authNonce,
@@ -408,7 +399,7 @@ class WSv2 extends EventEmitter {
408399 await this . close ( )
409400
410401 return new Promise ( ( resolve ) => {
411- this . once ( this . _wasEverAuthenticated ? 'auth' : 'open' , resolve )
402+ this . once ( this . _authOnReconnect ? 'auth' : 'open' , resolve )
412403 } )
413404 }
414405
@@ -425,7 +416,7 @@ class WSv2 extends EventEmitter {
425416
426417 await this . open ( )
427418
428- if ( this . _wasEverAuthenticated ) {
419+ if ( this . _authOnReconnect ) {
429420 await this . auth ( )
430421 }
431422 }
@@ -1358,7 +1349,6 @@ class WSv2 extends EventEmitter {
13581349
13591350 this . _channelMap [ chanId ] = { channel : 'auth' }
13601351 this . _isAuthenticated = true
1361- this . _wasEverAuthenticated = true
13621352
13631353 this . emit ( 'auth' , data )
13641354 debug ( 'authenticated!' )
0 commit comments