@@ -119,7 +119,11 @@ module.exports = function() {
119119 if ( reconnect && options . reconnect ) {
120120 if ( this . endpoint && this . endpoint . length == 60 ) console . log ( "Account data WebSocket reconnecting.." ) ;
121121 else console . log ( "WebSocket reconnecting: " + this . endpoint ) ;
122- reconnect ( ) ;
122+ try {
123+ reconnect ( ) ;
124+ } catch ( error ) {
125+ console . log ( "WebSocket reconnect error: " + error . message ) ;
126+ }
123127 } else console . log ( "WebSocket connection closed! " + this . endpoint ) ;
124128 } ) ;
125129 ws . on ( 'message' , function ( data ) {
@@ -370,8 +374,8 @@ module.exports = function() {
370374 if ( callback ) return callback . call ( this , data , symbol ) ;
371375 } ) ;
372376 } ,
373- depth : function ( symbol , callback ) {
374- publicRequest ( base + "v1/depth" , { symbol :symbol } , function ( data ) {
377+ depth : function ( symbol , callback , depth = 100 ) {
378+ publicRequest ( base + "v1/depth" , { symbol :symbol , depth : depth } , function ( data ) {
375379 return callback . call ( this , depthData ( data ) , symbol ) ;
376380 } ) ;
377381 } ,
@@ -388,10 +392,14 @@ module.exports = function() {
388392 } ) ;
389393 } ,
390394 prevDay : function ( symbol , callback ) {
391- publicRequest ( base + "v1/ticker/24hr" , { symbol :symbol } , function ( data ) {
395+ let input = symbol ? { symbol :symbol } : { } ;
396+ publicRequest ( base + "v1/ticker/24hr" , input , function ( data ) {
392397 if ( callback ) return callback . call ( this , data , symbol ) ;
393398 } ) ;
394399 } ,
400+ exchangeInfo : function ( callback ) {
401+ publicRequest ( base + "v1/exchangeInfo" , { } , callback ) ;
402+ } ,
395403 withdraw : function ( asset , address , amount , addressTag = false , callback = false ) {
396404 let params = { asset, address, amount} ;
397405 if ( addressTag ) params . addressTag = addressTag ;
@@ -408,6 +416,9 @@ module.exports = function() {
408416 depositAddress : function ( asset , callback ) {
409417 signedRequest ( wapi + "v3/depositAddress.html" , { asset :asset } , callback ) ;
410418 } ,
419+ accountStatus : function ( callback ) {
420+ signedRequest ( wapi + "v3/accountStatus.html" , { } , callback ) ;
421+ } ,
411422 account : function ( callback ) {
412423 signedRequest ( base + "v3/account" , { } , callback ) ;
413424 } ,
@@ -421,6 +432,12 @@ module.exports = function() {
421432 if ( callback ) return callback . call ( this , data , symbol ) ;
422433 } ) ;
423434 } ,
435+ recentTrades : function ( symbol , callback , limit = 500 ) {
436+ signedRequest ( base + "v1/trades" , { symbol :symbol , limit :limit } , callback ) ;
437+ } ,
438+ historicalTrades : function ( symbol , callback , limit = 500 ) {
439+ signedRequest ( base + "v1/historicalTrades" , { symbol :symbol , limit :limit } , callback ) ;
440+ } ,
424441 // convert chart data to highstock array [timestamp,open,high,low,close]
425442 highstock : function ( chart , include_volume = false ) {
426443 let array = [ ] ;
@@ -476,8 +493,12 @@ module.exports = function() {
476493 apiRequest ( base + "v1/userDataStream" , function ( response ) {
477494 options . listenKey = response . listenKey ;
478495 setInterval ( function ( ) { // keepalive
479- apiRequest ( base + "v1/userDataStream?listenKey=" + options . listenKey , false , "PUT" ) ;
480- } , 30000 ) ;
496+ try {
497+ apiRequest ( base + "v1/userDataStream?listenKey=" + options . listenKey , false , "PUT" ) ;
498+ } catch ( error ) {
499+ //error.message
500+ }
501+ } , 60 * 30 * 1000 ) ; // 30 minute keepalive
481502 options . balance_callback = callback ;
482503 options . execution_callback = execution_callback ;
483504 subscribe ( options . listenKey , userDataHandler , reconnect ) ;
@@ -501,7 +522,7 @@ module.exports = function() {
501522 subscribe ( symbol . toLowerCase ( ) + "@depth" , callback ) ;
502523 }
503524 } ,
504- depthCache : function depthCacheFunction ( symbols , callback ) {
525+ depthCache : function depthCacheFunction ( symbols , callbac , limit = 100 ) {
505526 for ( let symbol of symbols ) {
506527 if ( typeof info [ symbol ] == "undefined" ) info [ symbol ] = { } ;
507528 info [ symbol ] . firstUpdateId = 0 ;
@@ -518,7 +539,7 @@ module.exports = function() {
518539 depthHandler ( depth ) ;
519540 if ( callback ) callback ( symbol , depthCache [ symbol ] ) ;
520541 } , reconnect ) ;
521- publicRequest ( base + "v1/depth" , { symbol :symbol } , function ( json ) {
542+ publicRequest ( base + "v1/depth" , { symbol :symbol , limit : limit } , function ( json ) {
522543 info [ symbol ] . firstUpdateId = json . lastUpdateId ;
523544 depthCache [ symbol ] = depthData ( json ) ;
524545 for ( let depth of messageQueue [ symbol ] ) {
@@ -580,3 +601,4 @@ module.exports = function() {
580601 }
581602 } ;
582603} ( ) ;
604+ //https://github.com/binance-exchange/binance-official-api-docs
0 commit comments