From 6e2290c4f0d142de4e924f7ee78b209d90ec3643 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 2 Mar 2020 20:05:54 +0100 Subject: [PATCH] Allow last to be empty - closes #3005 --- freqtrade/freqtradebot.py | 8 +++----- tests/test_freqtradebot.py | 8 ++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 53493ad4c..04e3dd72f 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -257,12 +257,10 @@ class FreqtradeBot: else: logger.info(f"Using Last {bid_strategy['price_side'].capitalize()} / Last Price") ticker = self.exchange.fetch_ticker(pair) - rate = ticker[bid_strategy['price_side']] - if rate < ticker['last']: - ticker_rate = rate - else: + ticker_rate = ticker[bid_strategy['price_side']] + if ticker['last'] and ticker_rate > ticker['last']: balance = self.config['bid_strategy']['ask_last_balance'] - ticker_rate = rate + balance * (ticker['last'] - rate) + ticker_rate = ticker_rate + balance * (ticker['last'] - ticker_rate) used_rate = ticker_rate self._buy_rate_cache[pair] = used_rate diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 49000382f..a5506017c 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -914,6 +914,10 @@ def test_process_informative_pairs_added(default_conf, ticker, mocker) -> None: ('ask', 20, 19, 10, 0.3, 17), # Between ask and last ('ask', 5, 6, 10, 1.0, 5), # last bigger than ask ('ask', 5, 6, 10, 0.5, 5), # last bigger than ask + ('ask', 10, 20, None, 0.5, 10), # last not available - uses ask + ('ask', 4, 5, None, 0.5, 4), # last not available - uses ask + ('ask', 4, 5, None, 1, 4), # last not available - uses ask + ('ask', 4, 5, None, 0, 4), # last not available - uses ask ('bid', 10, 20, 10, 0.0, 20), # Full bid side ('bid', 10, 20, 10, 1.0, 10), # Full last side ('bid', 10, 20, 10, 0.5, 15), # Between bid and last @@ -921,6 +925,10 @@ def test_process_informative_pairs_added(default_conf, ticker, mocker) -> None: ('bid', 10, 20, 10, 0.3, 17), # Between bid and last ('bid', 4, 5, 10, 1.0, 5), # last bigger than bid ('bid', 4, 5, 10, 0.5, 5), # last bigger than bid + ('bid', 10, 20, None, 0.5, 20), # last not available - uses bid + ('bid', 4, 5, None, 0.5, 5), # last not available - uses bid + ('bid', 4, 5, None, 1, 5), # last not available - uses bid + ('bid', 4, 5, None, 0, 5), # last not available - uses bid ]) def test_get_buy_rate(mocker, default_conf, caplog, side, ask, bid, last, last_ab, expected) -> None: