Skip to content

Commit

Permalink
Change rel_tol to abs_tol to avoid surprises with high priced pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Sep 28, 2019
1 parent 8d92f8b commit 43f2ef2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions freqtrade/freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def get_real_amount(self, trade: Trade, order: Dict) -> float:
trade.pair.startswith(exectrade['fee']['currency'])):
fee_abs += exectrade['fee']['cost']

if not isclose(amount, order_amount, rel_tol=constants.MATH_CLOSE_PREC):
if not isclose(amount, order_amount, abs_tol=constants.MATH_CLOSE_PREC):
logger.warning(f"Amount {amount} does not match amount {trade.amount}")
raise OperationalException("Half bought? Amounts don't match")
real_amount = amount - fee_abs
Expand All @@ -536,7 +536,7 @@ def update_trade_state(self, trade, action_order: dict = None):
# Try update amount (binance-fix)
try:
new_amount = self.get_real_amount(trade, order)
if not isclose(order['amount'], new_amount, rel_tol=constants.MATH_CLOSE_PREC):
if not isclose(order['amount'], new_amount, abs_tol=constants.MATH_CLOSE_PREC):
order['amount'] = new_amount
# Fee was applied, so set to 0
trade.fee_open = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/test_freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3277,7 +3277,7 @@ def test_get_real_amount_wrong_amount_rounding(default_conf, trades_for_order, b

# Amount changes by fee amount.
assert isclose(freqtrade.get_real_amount(trade, limit_buy_order), amount - (amount * 0.001),
rel_tol=MATH_CLOSE_PREC,)
abs_tol=MATH_CLOSE_PREC,)


def test_get_real_amount_invalid(default_conf, trades_for_order, buy_order_fee, mocker):
Expand Down

0 comments on commit 43f2ef2

Please sign in to comment.