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
MIT License
605 stars 497 forks source link

FIXED minQty filter #501

Open Dvrcksoft opened 9 months ago

Dvrcksoft commented 9 months ago

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);
}