@@ -656,14 +656,19 @@ export default class Binance {
656656 */
657657 async signedRequest ( url : string , data : Dict = { } , method : HttpMethod = 'GET' , noDataInSignature = false ) {
658658 this . requireApiSecret ( 'signedRequest' ) ;
659+ const isListenKeyEndpoint = url . includes ( 'v3/userDataStream' ) ;
659660
660- data . timestamp = new Date ( ) . getTime ( ) ;
661- if ( this . timeOffset ) data . timestamp += this . timeOffset ;
662-
663- if ( ! data . recvWindow ) data . recvWindow = this . Options . recvWindow ;
664661 const query = method === 'POST' && noDataInSignature ? '' : this . makeQueryString ( data ) ;
665662
666- const signature = this . generateSignature ( query ) ;
663+ let signature = undefined ;
664+ if ( ! noDataInSignature && ! isListenKeyEndpoint ) {
665+ data . timestamp = new Date ( ) . getTime ( ) ;
666+
667+ if ( this . timeOffset ) data . timestamp += this . timeOffset ;
668+
669+ if ( ! data . recvWindow ) data . recvWindow = this . Options . recvWindow ;
670+ signature = this . generateSignature ( query ) ;
671+ }
667672
668673 if ( method === 'POST' ) {
669674 const opt = this . reqObjPOST (
@@ -672,12 +677,17 @@ export default class Binance {
672677 method ,
673678 this . APIKEY
674679 ) ;
675- opt . form . signature = signature ;
680+ if ( signature ) {
681+ opt . form . signature = signature ;
682+ }
676683 const reqPost = await this . proxyRequest ( opt ) ;
677684 return reqPost ;
678685 } else {
686+ let encodedUrl = url ;
687+ if ( query ) encodedUrl += '?' + query ;
688+ if ( signature ) encodedUrl += '&signature=' + signature ;
679689 const opt = this . reqObj (
680- url + '?' + query + '&signature=' + signature ,
690+ encodedUrl ,
681691 data ,
682692 method ,
683693 this . APIKEY
@@ -3917,6 +3927,22 @@ export default class Binance {
39173927 return res ;
39183928 }
39193929
3930+ async spotGetDataStream ( params : Dict = { } ) {
3931+ return await this . privateSpotRequest ( 'v3/userDataStream' , params , 'POST' , true ) ;
3932+ }
3933+
3934+ async spotKeepDataStream ( listenKey : string | undefined = undefined , params : Dict = { } ) {
3935+ listenKey = listenKey || this . Options . listenKey ;
3936+ if ( ! listenKey ) throw new Error ( 'A listenKey is required, either as an argument or in this.Options.listenKey' ) ;
3937+ return await this . privateSpotRequest ( 'v3/userDataStream' , { listenKey, ...params } , 'PUT' ) ;
3938+ }
3939+
3940+ async spotCloseDataStream ( listenKey : string | undefined = undefined , params : Dict = { } ) {
3941+ listenKey = listenKey || this . Options . listenKey ;
3942+ if ( ! listenKey ) throw new Error ( 'A listenKey is required, either as an argument or in this.Options.listenKey' ) ;
3943+ return await this . privateSpotRequest ( 'v3/userDataStream' , { listenKey, ...params } , 'DELETE' ) ;
3944+ }
3945+
39203946 // /**
39213947 // * Queries the public api
39223948 // * @param {string } url - the public api endpoint
0 commit comments