@@ -50,7 +50,9 @@ class API
5050 private $ btc_total = 0.00 ;
5151
5252 // /< value of available onOrder assets
53-
53+
54+ protected $ exchangeInfo = NULL ;
55+
5456 /**
5557 * Constructor for the class,
5658 * send as many argument as you want.
@@ -336,6 +338,9 @@ public function marketBuyTest(string $symbol, $quantity, array $flags = [])
336338 */
337339 public function marketSell (string $ symbol , $ quantity , array $ flags = [])
338340 {
341+ $ c = $ this ->numberOfDecimals ($ this ->exchangeInfo ()['symbols ' ][$ symbol ]['filters ' ][2 ]['minQty ' ]);
342+ $ quantity = $ this ->floorDecimal ($ quantity , $ c );
343+
339344 return $ this ->order ("SELL " , $ symbol , $ quantity , 0 , "MARKET " , $ flags );
340345 }
341346
@@ -501,7 +506,20 @@ public function time()
501506 */
502507 public function exchangeInfo ()
503508 {
504- return $ this ->httpRequest ("v1/exchangeInfo " );
509+ if (!$ this ->exchangeInfo ){
510+
511+ $ arr = $ this ->httpRequest ("v1/exchangeInfo " );
512+
513+ $ this ->exchangeInfo = $ arr ;
514+ $ this ->exchangeInfo ['symbols ' ] = null ;
515+
516+ foreach ($ arr ['symbols ' ] as $ key => $ value ){
517+ $ this ->exchangeInfo ['symbols ' ][$ value ['symbol ' ]] = $ value ;
518+ }
519+
520+ }
521+
522+ return $ this ->exchangeInfo ;
505523 }
506524
507525 public function assetDetail ()
@@ -2283,4 +2301,10 @@ private function downloadCurlCaBundle()
22832301 fwrite ($ fp , $ result );
22842302 fclose ($ fp );
22852303 }
2304+
2305+ private function floorDecimal ($ n , $ decimals =2 )
2306+ {
2307+ return floor ($ n * pow (10 , $ decimals )) / pow (10 , $ decimals );
2308+ }
2309+
22862310}
0 commit comments