@@ -110,8 +110,11 @@ module.exports = function() {
110
110
//console.log("subscribe("+endpoint+")");
111
111
} ) ;
112
112
ws . on ( 'close' , function ( ) {
113
- console . log ( "WebSocket connection closed" ) ;
114
- if ( reconnect ) reconnect ( ) ;
113
+ if ( reconnect ) {
114
+ console . log ( "WebSocket reconnecting: " + endpoint ) ;
115
+ reconnect ( ) ;
116
+ }
117
+ console . log ( "WebSocket connection closed! " + endpoint ) ;
115
118
} ) ;
116
119
117
120
ws . on ( 'message' , function ( data ) {
@@ -260,13 +263,22 @@ module.exports = function() {
260
263
}
261
264
return output ;
262
265
} ,
266
+ array : function ( obj ) {
267
+ return Object . keys ( obj ) . map ( function ( key ) {
268
+ return [ Number ( key ) , obj [ key ] ] ;
269
+ } ) ;
270
+ } ,
263
271
sortBids : function ( symbol , max = Infinity , baseValue = false ) {
264
272
let object = { } , count = 0 , cache ;
265
273
if ( typeof symbol == "object" ) cache = symbol ;
266
274
else cache = getDepthCache ( symbol ) . bids ;
267
275
let sorted = Object . keys ( cache ) . sort ( function ( a , b ) { return parseFloat ( b ) - parseFloat ( a ) } ) ;
276
+ let cumulative = 0 ;
268
277
for ( let price of sorted ) {
269
- if ( ! baseValue ) object [ price ] = cache [ price ] ;
278
+ if ( baseValue == "cumulative" ) {
279
+ cumulative += cache [ price ] ;
280
+ object [ price ] = cumulative . toFixed ( 8 ) ;
281
+ } else if ( ! baseValue ) object [ price ] = cache [ price ] ;
270
282
else object [ price ] = parseFloat ( ( cache [ price ] * parseFloat ( price ) ) . toFixed ( 8 ) ) ;
271
283
if ( ++ count > max ) break ;
272
284
}
@@ -277,8 +289,12 @@ module.exports = function() {
277
289
if ( typeof symbol == "object" ) cache = symbol ;
278
290
else cache = getDepthCache ( sparseFloatymbol ) . asks ;
279
291
let sorted = Object . keys ( cache ) . sort ( function ( a , b ) { return parseFloat ( a ) - parseFloat ( b ) } ) ;
292
+ let cumulative = 0 ;
280
293
for ( let price of sorted ) {
281
- if ( ! baseValue ) object [ price ] = cache [ price ] ;
294
+ if ( baseValue == "cumulative" ) {
295
+ cumulative += cache [ price ] ;
296
+ object [ price ] = cumulative . toFixed ( 8 ) ;
297
+ } else if ( ! baseValue ) object [ price ] = cache [ price ] ;
282
298
else object [ price ] = parseFloat ( ( cache [ price ] * parseFloat ( price ) ) . toFixed ( 8 ) ) ;
283
299
if ( ++ count > max ) break ;
284
300
}
@@ -329,7 +345,7 @@ module.exports = function() {
329
345
} ,
330
346
depth : function ( symbol , callback ) {
331
347
publicRequest ( base + "v1/depth" , { symbol :symbol } , function ( data ) {
332
- return callback ( depthData ( data ) ) ;
348
+ return callback . call ( this , depthData ( data ) , symbol ) ;
333
349
} ) ;
334
350
} ,
335
351
prices : function ( callback ) {
0 commit comments