jaggedsoft / php-binance-api

PHP Binance API is an asynchronous PHP library for the Binance API designed to be easy to use. https://github.com/binance-exchange/php-binance-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FIXED minQty filter

Dvrcksoft opened this issue · comments

Example for function marketSell
Before:

public function marketSell(string $symbol, $quantity, array $flags = [])
{
    $c = $this->numberOfDecimals($this->exchangeInfo()['symbols'][$symbol]['filters'][2]['minQty']);
    $quantity = $this->floorDecimal($quantity, $c);

    return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags);
}

After:

public function marketSell(string $symbol, $quantity, array $flags = [])
{
// Get exchange information and filters for a specific symbol
$exchangeInfo = $this->exchangeInfo();
$symbolFilters = $exchangeInfo['symbols'][$symbol]['filters'];

    $minQty = null;
    // Look for the LOT_SIZE filter and get the minQty from there
    foreach ($symbolFilters as $filter) {
        if ($filter['filterType'] === 'LOT_SIZE' && isset($filter['minQty'])) {
            $minQty = $filter['minQty'];
            break;
        }
    }

    // If minQty is not found, record an error and return false
    if ($minQty === null) {
        error_log("Not found minQty for LOT_SIZE filter for $symbol pair");
        return false;
    }

    // Determine the number of decimal places for minQty and round the number of decimal places
    $c = $this->numberOfDecimals($minQty);
    $quantity = $this->floorDecimal($quantity, $c);

    // Create Order
    return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags);
}