From f69e8458f4f4105d5d5600b360c178ad886e5025 Mon Sep 17 00:00:00 2001 From: Matthias Voppichler Date: Sun, 15 Apr 2018 23:11:01 +0200 Subject: [PATCH] Add tests for update_real_amount --- freqtrade/tests/test_freqtradebot.py | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py index c9413cbe7..85aa64e89 100644 --- a/freqtrade/tests/test_freqtradebot.py +++ b/freqtrade/tests/test_freqtradebot.py @@ -1374,3 +1374,53 @@ def test_get_real_amount_multi(default_conf, trades_for_order2, mocker): freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) # Amount is reduced by "fee" assert freqtrade.get_real_amount(trade) == amount - (amount * 0.001) + + +def test_maybe_update_real_amount(default_conf, trades_for_order, mocker): + """ + Test get_real_amount with split trades (multiple trades for this order) + """ + + 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 = 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 is reduced by "fee" + assert freqtrade.maybe_update_real_amount(trade) is True + assert trade.amount == amount - (amount * 0.001) + + +def test_maybe_update_real_amount_stake(default_conf, trades_for_order, mocker): + """ + Test get_real_amount with split trades (multiple trades for this order) + """ + trades_for_order[0]['fee']['currency'] = 'ETH' + + 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 = 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 is reduced by "fee" + assert freqtrade.maybe_update_real_amount(trade) is True + assert trade.amount == amount