From a960691dbb488e0b19470933d25e91717573c6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Farin?= <39909515+JeromeFarin@users.noreply.github.com> Date: Wed, 7 Dec 2022 20:31:42 +0000 Subject: [PATCH] fix: get filter by "LOT_SIZE" --- php-binance-api.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 2b2d330..64524f8 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -410,7 +410,14 @@ public function numberOfDecimals($val = 0.00000001) public function marketQuoteSell(string $symbol, $quantity, array $flags = []) { $flags['isQuoteOrder'] = true; - $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']); + $exchangeInfo = $this->exchangeInfo(); + $filters = $exchangeInfo['symbols'][$symbol]['filters']; + $lotSize = array_filter($filters, function ($filter) { + return $filter['filterType'] === 'LOT_SIZE'; + }); + $lotSize = array_shift($lotSize); + $minQty = $lotSize['minQty']; + $c = $this->numberOfDecimals($minQty); $quantity = $this->floorDecimal($quantity, $c); return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags); @@ -446,7 +453,14 @@ public function marketQuoteSellTest(string $symbol, $quantity, array $flags = [] */ public function marketSell(string $symbol, $quantity, array $flags = []) { - $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']); + $exchangeInfo = $this->exchangeInfo(); + $filters = $exchangeInfo['symbols'][$symbol]['filters']; + $lotSize = array_filter($filters, function ($filter) { + return $filter['filterType'] === 'LOT_SIZE'; + }); + $lotSize = array_shift($lotSize); + $minQty = $lotSize['minQty']; + $c = $this->numberOfDecimals($minQty); $quantity = $this->floorDecimal($quantity, $c); return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags);