From 05d93cda16ffb9582e2c8e44ba2022a2b67adb4c Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Thu, 27 Jun 2019 01:03:38 +0300 Subject: [PATCH 1/3] fix #1963 --- freqtrade/freqtradebot.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index b6fc005dd..b3e0ef59d 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -478,8 +478,11 @@ class FreqtradeBot(object): return order_amount # use fee from order-dict if possible - if 'fee' in order and order['fee'] and (order['fee'].keys() >= {'currency', 'cost'}): - if trade.pair.startswith(order['fee']['currency']): + if 'fee' in order and order['fee'] is not None and \ + (order['fee'].keys() >= {'currency', 'cost'}): + if order['fee']['currency'] is not None and \ + order['fee']['cost'] is not None and \ + trade.pair.startswith(order['fee']['currency']): new_amount = order_amount - order['fee']['cost'] logger.info("Applying fee on amount for %s (from %s to %s) from Order", trade, order['amount'], new_amount) @@ -496,9 +499,12 @@ class FreqtradeBot(object): fee_abs = 0 for exectrade in trades: amount += exectrade['amount'] - if "fee" in exectrade and (exectrade['fee'].keys() >= {'currency', 'cost'}): + if "fee" in exectrade and exectrade['fee'] is not None and \ + (exectrade['fee'].keys() >= {'currency', 'cost'}): # only applies if fee is in quote currency! - if trade.pair.startswith(exectrade['fee']['currency']): + if exectrade['fee']['currency'] is not None and \ + exectrade['fee']['cost'] is not None and \ + trade.pair.startswith(exectrade['fee']['currency']): fee_abs += exectrade['fee']['cost'] if amount != order_amount: From f04d49886bca1d56b0f149cd6a9c47e0a6a6de76 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 27 Jun 2019 06:29:18 +0200 Subject: [PATCH 2/3] Add test to verify behaviour if currency in fee-dict is None --- freqtrade/tests/test_freqtradebot.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py index 87b344853..89d3bba5f 100644 --- a/freqtrade/tests/test_freqtradebot.py +++ b/freqtrade/tests/test_freqtradebot.py @@ -2886,6 +2886,30 @@ def test_get_real_amount_stake(default_conf, trades_for_order, buy_order_fee, mo assert freqtrade.get_real_amount(trade, buy_order_fee) == amount +def test_get_real_amount_no_currency_in_fee(default_conf, trades_for_order, buy_order_fee, mocker): + + limit_buy_order = deepcopy(buy_order_fee) + limit_buy_order['fee'] = {'cost': 0.004, 'currency': None} + trades_for_order[0]['fee']['currency'] = None + + patch_RPCManager(mocker) + patch_exchange(mocker) + mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order) + amount = sum(x['amount'] for x in trades_for_order) + trade = Trade( + pair='LTC/ETH', + amount=amount, + exchange='binance', + open_rate=0.245441, + open_order_id="123456" + ) + freqtrade = FreqtradeBot(default_conf) + patch_get_signal(freqtrade) + + # Amount does not change + assert freqtrade.get_real_amount(trade, limit_buy_order) == amount + + def test_get_real_amount_BNB(default_conf, trades_for_order, buy_order_fee, mocker): trades_for_order[0]['fee']['currency'] = 'BNB' trades_for_order[0]['fee']['cost'] = 0.00094518 From f8dd0b0cb318434e2479460b7177f11525ae9f70 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 27 Jun 2019 06:32:26 +0200 Subject: [PATCH 3/3] Use parenteses instead of \ seperators --- freqtrade/freqtradebot.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index b3e0ef59d..a62591b15 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -478,11 +478,11 @@ class FreqtradeBot(object): return order_amount # use fee from order-dict if possible - if 'fee' in order and order['fee'] is not None and \ - (order['fee'].keys() >= {'currency', 'cost'}): - if order['fee']['currency'] is not None and \ - order['fee']['cost'] is not None and \ - trade.pair.startswith(order['fee']['currency']): + if ('fee' in order and order['fee'] is not None and + (order['fee'].keys() >= {'currency', 'cost'})): + if (order['fee']['currency'] is not None and + order['fee']['cost'] is not None and + trade.pair.startswith(order['fee']['currency'])): new_amount = order_amount - order['fee']['cost'] logger.info("Applying fee on amount for %s (from %s to %s) from Order", trade, order['amount'], new_amount) @@ -499,12 +499,12 @@ class FreqtradeBot(object): fee_abs = 0 for exectrade in trades: amount += exectrade['amount'] - if "fee" in exectrade and exectrade['fee'] is not None and \ - (exectrade['fee'].keys() >= {'currency', 'cost'}): + if ("fee" in exectrade and exectrade['fee'] is not None and + (exectrade['fee'].keys() >= {'currency', 'cost'})): # only applies if fee is in quote currency! - if exectrade['fee']['currency'] is not None and \ - exectrade['fee']['cost'] is not None and \ - trade.pair.startswith(exectrade['fee']['currency']): + if (exectrade['fee']['currency'] is not None and + exectrade['fee']['cost'] is not None and + trade.pair.startswith(exectrade['fee']['currency'])): fee_abs += exectrade['fee']['cost'] if amount != order_amount: