Compare floats via isclose instead of ==

This commit is contained in:
Matthias 2019-09-26 07:04:56 +02:00
parent 49f0a72121
commit 8d92f8b362

View File

@ -6,6 +6,7 @@ import copy
import logging import logging
import traceback import traceback
from datetime import datetime from datetime import datetime
from math import isclose
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
import arrow import arrow
@ -510,7 +511,7 @@ class FreqtradeBot:
trade.pair.startswith(exectrade['fee']['currency'])): trade.pair.startswith(exectrade['fee']['currency'])):
fee_abs += exectrade['fee']['cost'] fee_abs += exectrade['fee']['cost']
if amount != order_amount: if not isclose(amount, order_amount, rel_tol=constants.MATH_CLOSE_PREC):
logger.warning(f"Amount {amount} does not match amount {trade.amount}") logger.warning(f"Amount {amount} does not match amount {trade.amount}")
raise OperationalException("Half bought? Amounts don't match") raise OperationalException("Half bought? Amounts don't match")
real_amount = amount - fee_abs real_amount = amount - fee_abs
@ -535,7 +536,7 @@ class FreqtradeBot:
# Try update amount (binance-fix) # Try update amount (binance-fix)
try: try:
new_amount = self.get_real_amount(trade, order) new_amount = self.get_real_amount(trade, order)
if order['amount'] != new_amount: if not isclose(order['amount'], new_amount, rel_tol=constants.MATH_CLOSE_PREC):
order['amount'] = new_amount order['amount'] = new_amount
# Fee was applied, so set to 0 # Fee was applied, so set to 0
trade.fee_open = 0 trade.fee_open = 0