Merge pull request #683 from xmatthias/fix_get_real_amount
Fix get real amount
This commit is contained in:
commit
d985405fe7
@ -397,7 +397,7 @@ class FreqtradeBot(object):
|
||||
return order_amount
|
||||
|
||||
# use fee from order-dict if possible
|
||||
if 'fee' in order and order['fee']:
|
||||
if 'fee' in order and order['fee'] and (order['fee'].keys() >= {'currency', 'cost'}):
|
||||
if 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",
|
||||
@ -414,7 +414,7 @@ class FreqtradeBot(object):
|
||||
fee_abs = 0
|
||||
for exectrade in trades:
|
||||
amount += exectrade['amount']
|
||||
if "fee" in exectrade:
|
||||
if "fee" in exectrade and (exectrade['fee'].keys() >= {'currency', 'cost'}):
|
||||
# only applies if fee is in quote currency!
|
||||
if trade.pair.startswith(exectrade['fee']['currency']):
|
||||
fee_abs += exectrade['fee']['cost']
|
||||
|
@ -1443,7 +1443,7 @@ def test_get_real_amount_fromorder(default_conf, trades_for_order, buy_order_fee
|
||||
patch_RPCManager(mocker)
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
|
||||
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=trades_for_order)
|
||||
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=[trades_for_order])
|
||||
amount = float(sum(x['amount'] for x in trades_for_order))
|
||||
trade = Trade(
|
||||
pair='LTC/ETH',
|
||||
@ -1458,3 +1458,53 @@ def test_get_real_amount_fromorder(default_conf, trades_for_order, buy_order_fee
|
||||
assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
|
||||
'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.996) from Order',
|
||||
caplog.record_tuples)
|
||||
|
||||
|
||||
def test_get_real_amount_invalid_order(default_conf, trades_for_order, buy_order_fee, mocker):
|
||||
"""
|
||||
Test get_real_amount with split trades (multiple trades for this order)
|
||||
"""
|
||||
limit_buy_order = deepcopy(buy_order_fee)
|
||||
limit_buy_order['fee'] = {'cost': 0.004}
|
||||
|
||||
patch_get_signal(mocker)
|
||||
patch_RPCManager(mocker)
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
|
||||
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=[])
|
||||
amount = float(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, create_engine('sqlite://'))
|
||||
# Amount does not change
|
||||
assert freqtrade.get_real_amount(trade, limit_buy_order) == amount
|
||||
|
||||
|
||||
def test_get_real_amount_invalid(default_conf, trades_for_order, buy_order_fee, mocker):
|
||||
"""
|
||||
Test get_real_amount - fees in Stake currency
|
||||
"""
|
||||
# Remove "Currency" from fee dict
|
||||
trades_for_order[0]['fee'] = {'cost': 0.008}
|
||||
|
||||
patch_get_signal(mocker)
|
||||
patch_RPCManager(mocker)
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
|
||||
mocker.patch('freqtrade.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, create_engine('sqlite://'))
|
||||
# Amount does not change
|
||||
assert freqtrade.get_real_amount(trade, buy_order_fee) == amount
|
||||
|
Loading…
Reference in New Issue
Block a user