@@ -123,7 +123,17 @@ let api = function Binance() {
123123 'X-MBX-APIKEY' : key || ''
124124 }
125125 } )
126-
126+ const reqObjPOST = ( url , data = { } , method = 'POST' , key ) => ( {
127+ url : url ,
128+ form : data ,
129+ method : method ,
130+ timeout : Binance . options . recvWindow ,
131+ headers : {
132+ 'User-Agent' : userAgent ,
133+ 'Content-type' : contentType ,
134+ 'X-MBX-APIKEY' : key || ''
135+ }
136+ } )
127137 /**
128138 * Create a http request to the public API
129139 * @param {string } url - The http endpoint
@@ -198,14 +208,23 @@ let api = function Binance() {
198208 return a ;
199209 } , [ ] ) . join ( '&' ) ;
200210 let signature = crypto . createHmac ( 'sha256' , Binance . options . APISECRET ) . update ( query ) . digest ( 'hex' ) ; // set the HMAC hash header
201-
202- let opt = reqObj (
203- url + '?' + query + '&signature=' + signature ,
204- data ,
205- method ,
206- Binance . options . APIKEY
207- ) ;
208- proxyRequest ( opt , callback ) ;
211+ if ( method === 'POST' ) {
212+ let opt = reqObjPOST (
213+ url + '?signature=' + signature ,
214+ data ,
215+ method ,
216+ Binance . options . APIKEY
217+ ) ;
218+ proxyRequest ( opt , callback ) ;
219+ } else {
220+ let opt = reqObj (
221+ url + '?' + query + '&signature=' + signature ,
222+ data ,
223+ method ,
224+ Binance . options . APIKEY
225+ ) ;
226+ proxyRequest ( opt , callback ) ;
227+ }
209228 } ;
210229
211230 /**
@@ -313,14 +332,14 @@ let api = function Binance() {
313332 */
314333 const handleSocketClose = function ( reconnect , code , reason ) {
315334 delete Binance . subscriptions [ this . endpoint ] ;
316- if ( Binance . subscriptions && Object . keys ( Binance . subscriptions ) . length === 0 ) {
335+ if ( Binance . subscriptions && Object . keys ( Binance . subscriptions ) . length === 0 ) {
317336 clearInterval ( Binance . socketHeartbeatInterval ) ;
318337 }
319338 Binance . options . log ( 'WebSocket closed: ' + this . endpoint +
320339 ( code ? ' (' + code + ')' : '' ) +
321340 ( reason ? ' ' + reason : '' ) ) ;
322- if ( Binance . options . reconnect && this . reconnect && reconnect ) {
323- if ( this . endpoint && parseInt ( this . endpoint . length , 10 ) === 60 ) Binance . options . log ( 'Account data WebSocket reconnecting...' ) ;
341+ if ( Binance . options . reconnect && this . reconnect && reconnect ) {
342+ if ( this . endpoint && parseInt ( this . endpoint . length , 10 ) === 60 ) Binance . options . log ( 'Account data WebSocket reconnecting...' ) ;
324343 else Binance . options . log ( 'WebSocket reconnecting: ' + this . endpoint + '...' ) ;
325344 try {
326345 reconnect ( ) ;
@@ -807,7 +826,7 @@ let api = function Binance() {
807826 * @param {float } float - get the price precision point
808827 * @return {int } - number of place
809828 */
810- getPrecision : function ( float ) { //
829+ getPrecision : function ( float ) {
811830 return float . toString ( ) . split ( '.' ) [ 1 ] . length || 0 ;
812831 } ,
813832
@@ -818,8 +837,12 @@ let api = function Binance() {
818837 * @return {float } - number
819838 */
820839 roundStep : function ( qty , stepSize ) {
821- const precision = stepSize . toString ( ) . split ( '.' ) [ 1 ] . length || 0 ;
822- return ( ( Math . floor ( qty / stepSize ) | 0 ) * stepSize ) . toFixed ( precision ) ;
840+ // Integers do not require rounding
841+ if ( Number . isInteger ( qty ) ) return qty ;
842+ const qtyString = qty . toFixed ( 16 ) ;
843+ const desiredDecimals = Math . max ( stepSize . indexOf ( '1' ) - 1 , 0 ) ;
844+ const decimalIndex = qtyString . indexOf ( '.' ) ;
845+ return parseFloat ( qtyString . slice ( 0 , decimalIndex + desiredDecimals + 1 ) ) ;
823846 } ,
824847
825848 /**
@@ -831,7 +854,7 @@ let api = function Binance() {
831854 roundTicks : function ( price , tickSize ) {
832855 const formatter = new Intl . NumberFormat ( 'en-US' , { style : 'decimal' , minimumFractionDigits : 0 , maximumFractionDigits : 8 } ) ;
833856 const precision = formatter . format ( tickSize ) . split ( '.' ) [ 1 ] . length || 0 ;
834- if ( typeof price === 'string' ) price = parseFloat ( price ) ;
857+ if ( typeof price === 'string' ) price = parseFloat ( price ) ;
835858 return price . toFixed ( precision ) ;
836859 } ,
837860
@@ -1127,7 +1150,7 @@ let api = function Binance() {
11271150 } ,
11281151
11291152 /**
1130- * Cancels an order
1153+ * Gets the status of an order
11311154 * @param {string } symbol - the symbol to check
11321155 * @param {string } orderid - the orderid to check
11331156 * @param {function } callback - the callback function
@@ -1188,7 +1211,7 @@ let api = function Binance() {
11881211 if ( callback ) return callback . call ( this , error , data , symbol ) ;
11891212 } ) ;
11901213 } ,
1191-
1214+
11921215 /**
11931216 * Gets the depth information for a given symbol
11941217 * @param {string } symbol - the symbol
@@ -1238,19 +1261,6 @@ let api = function Binance() {
12381261 } ) ;
12391262 } ,
12401263
1241- /**
1242- * Gets the depth information for a given symbol
1243- * @param {string } symbol - the symbol
1244- * @param {function } callback - the callback function
1245- * @param {int } limit - limit the number of returned orders
1246- * @return {undefined }
1247- */
1248- depth : function ( symbol , callback , limit = 100 ) {
1249- publicRequest ( base + 'v1/depth' , { symbol : symbol , limit : limit } , function ( error , data ) {
1250- return callback . call ( this , error , depthData ( data ) , symbol ) ;
1251- } ) ;
1252- } ,
1253-
12541264 /**
12551265 * Gets the prices of a given symbol(s)
12561266 * @param {string } symbol - the symbol
@@ -1427,7 +1437,7 @@ let api = function Binance() {
14271437 * @return {undefined }
14281438 */
14291439 tradeFee : function ( callback , symbol = false ) {
1430- let params = symbol ? { symbol :symbol } : { } ;
1440+ let params = symbol ? { symbol : symbol } : { } ;
14311441 signedRequest ( wapi + 'v3/tradeFee.html' , params , callback ) ;
14321442 } ,
14331443
@@ -1844,7 +1854,7 @@ let api = function Binance() {
18441854 * @param {int } stagger - ms between each depth cache
18451855 * @return {Promise } the websocket endpoint
18461856 */
1847- depthCacheStaggered : function ( symbols , callback , limit = 100 , stagger = 200 ) {
1857+ depthCacheStaggered : function ( symbols , callback , limit = 100 , stagger = 200 ) {
18481858 if ( ! Array . isArray ( symbols ) ) symbols = [ symbols ] ;
18491859 let chain = null ;
18501860
0 commit comments