From 5deebbd0867235ed288b732986cfff5dd288b94b Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Mon, 3 Aug 2020 11:18:15 +0200 Subject: [PATCH] fix quote orders --- binance/client.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/binance/client.py b/binance/client.py index a45c966..b0ab09f 100644 --- a/binance/client.py +++ b/binance/client.py @@ -83,7 +83,7 @@ def assert_symbol_exists(self, symbol): def truncate(self, f, n): return math.floor(f * 10 ** n) / 10 ** n - def refine_amount(self, symbol, amount: Union[str, decimal.Decimal]): + def refine_amount(self, symbol, amount: Union[str, decimal.Decimal], quote=False): if type(amount) == str: # to save time for developers amount = decimal.Decimal(amount) if self.loaded: @@ -93,7 +93,9 @@ def refine_amount(self, symbol, amount: Union[str, decimal.Decimal]): amount = ( ( f"%.{precision}f" - % self.truncate(amount - amount % step_size, precision) + % self.truncate( + amount if quote else (amount - amount % step_size), precision + ) ) .rstrip("0") .rstrip(".") @@ -319,7 +321,7 @@ async def create_order( raise ValueError("This order type requires a time_in_force.") if quote_order_quantity: - params["quoteOrderQty"] = self.refine_amount(symbol, quote_order_quantity) + params["quoteOrderQty"] = self.refine_amount(symbol, quote_order_quantity, True) if quantity: params["quantity"] = self.refine_amount(symbol, quantity) elif not quote_order_quantity: