Skip to content

Commit

Permalink
fix quote orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Aug 3, 2020
1 parent 04c4e0a commit 5deebbd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions binance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(".")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5deebbd

Please sign in to comment.