From e6732e01e1be47bfaa95c7c0fbc5bd229966f6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20LONLAS?= Date: Thu, 15 Mar 2018 15:48:22 -0700 Subject: [PATCH] Use ticker_interval defined in Strategy() instead of a mix between strategy and config file (#540) --- freqtrade/analyze.py | 7 ++ freqtrade/freqtradebot.py | 35 ++++---- freqtrade/strategy/strategy.py | 2 +- freqtrade/tests/rpc/test_rpc.py | 18 ++-- freqtrade/tests/rpc/test_rpc_telegram.py | 28 ++++--- freqtrade/tests/test_freqtradebot.py | 100 ++++++++++++----------- 6 files changed, 98 insertions(+), 92 deletions(-) diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index c86e2dc85..401d99479 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -77,6 +77,13 @@ class Analyze(object): """ return self.strategy.populate_sell_trend(dataframe=dataframe) + def get_ticker_interval(self) -> int: + """ + Return ticker interval to use + :return: Ticker interval value to use + """ + return self.strategy.ticker_interval + def analyze_ticker(self, ticker_history: List[Dict]) -> DataFrame: """ Parses the given ticker history and returns a populated DataFrame diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index d4c457aef..b18d6540b 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -125,17 +125,9 @@ class FreqtradeBot(object): Constants.DYNAMIC_WHITELIST ) - interval = int( - self.config.get( - 'ticker_interval', - Constants.TICKER_INTERVAL - ) - ) - self._throttle(func=self._process, min_secs=min_secs, - nb_assets=nb_assets, - interval=interval) + nb_assets=nb_assets) return new_state def _throttle(self, func: Callable[..., Any], min_secs: float, *args, **kwargs) -> Any: @@ -154,7 +146,7 @@ class FreqtradeBot(object): time.sleep(duration) return result - def _process(self, interval: int, nb_assets: Optional[int] = 0) -> bool: + def _process(self, nb_assets: Optional[int] = 0) -> bool: """ Queries the persistence layer for open trades and handles them, otherwise a new trade is created. @@ -179,11 +171,11 @@ class FreqtradeBot(object): # First process current opened trades for trade in trades: - state_changed |= self.process_maybe_execute_sell(trade, interval) + state_changed |= self.process_maybe_execute_sell(trade) # Then looking for buy opportunities if len(trades) < self.config['max_open_trades']: - state_changed = self.process_maybe_execute_buy(interval) + state_changed = self.process_maybe_execute_buy() if 'unfilledtimeout' in self.config: # Check and handle any timed out open orders @@ -263,9 +255,7 @@ class FreqtradeBot(object): balance = self.config['bid_strategy']['ask_last_balance'] return ticker['ask'] + balance * (ticker['last'] - ticker['ask']) - # TODO: Remove the two parameters and use the value already in conf['stake_amount'] and - # int(conf['ticker_interval']) - def create_trade(self, stake_amount: float, interval: int) -> bool: + def create_trade(self) -> bool: """ Checks the implemented trading indicator(s) for a randomly picked pair, if one pair triggers the buy_signal a new trade record gets created @@ -273,6 +263,9 @@ class FreqtradeBot(object): :param interval: Ticker interval used for Analyze :return: True if a trade object has been created and persisted, False otherwise """ + stake_amount = self.config['stake_amount'] + interval = self.analyze.get_ticker_interval() + self.logger.info( 'Checking buy signals to create a new trade with stake_amount: %f ...', stake_amount @@ -343,14 +336,14 @@ class FreqtradeBot(object): Trade.session.flush() return True - def process_maybe_execute_buy(self, interval: int) -> bool: + def process_maybe_execute_buy(self) -> bool: """ Tries to execute a buy trade in a safe way :return: True if executed """ try: # Create entity and execute trade - if self.create_trade(float(self.config['stake_amount']), interval): + if self.create_trade(): return True self.logger.info('Found no buy signals for whitelisted currencies. Trying again..') @@ -359,7 +352,7 @@ class FreqtradeBot(object): self.logger.warning('Unable to create trade: %s', exception) return False - def process_maybe_execute_sell(self, trade: Trade, interval: int) -> bool: + def process_maybe_execute_sell(self, trade: Trade) -> bool: """ Tries to execute a sell trade :return: True if executed @@ -372,10 +365,10 @@ class FreqtradeBot(object): if trade.is_open and trade.open_order_id is None: # Check if we can sell our current pair - return self.handle_trade(trade, interval) + return self.handle_trade(trade) return False - def handle_trade(self, trade: Trade, interval: int) -> bool: + def handle_trade(self, trade: Trade) -> bool: """ Sells the current pair if the threshold is reached and updates the trade record. :return: True if trade has been sold, False otherwise @@ -389,7 +382,7 @@ class FreqtradeBot(object): (buy, sell) = (False, False) if self.config.get('experimental', {}).get('use_sell_signal'): - (buy, sell) = self.analyze.get_signal(trade.pair, interval) + (buy, sell) = self.analyze.get_signal(trade.pair, self.analyze.get_ticker_interval()) if self.analyze.should_sell(trade, current_rate, datetime.utcnow(), buy, sell): self.execute_sell(trade, current_rate) diff --git a/freqtrade/strategy/strategy.py b/freqtrade/strategy/strategy.py index 607b6223f..ed1dee10e 100644 --- a/freqtrade/strategy/strategy.py +++ b/freqtrade/strategy/strategy.py @@ -64,7 +64,7 @@ class Strategy(object): # Optimal stoploss designed for the strategy self.stoploss = float(self.custom_strategy.stoploss) - self.ticker_interval = self.custom_strategy.ticker_interval + self.ticker_interval = int(self.custom_strategy.ticker_interval) def _load_strategy(self, strategy_name: str) -> None: """ diff --git a/freqtrade/tests/rpc/test_rpc.py b/freqtrade/tests/rpc/test_rpc.py index e9d77b1f5..764de1cb2 100644 --- a/freqtrade/tests/rpc/test_rpc.py +++ b/freqtrade/tests/rpc/test_rpc.py @@ -51,7 +51,7 @@ def test_rpc_trade_status(default_conf, ticker, mocker) -> None: assert error assert 'no active trade' in result - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() (error, result) = rpc.rpc_trade_status() assert not error trade = result[0] @@ -99,7 +99,7 @@ def test_rpc_status_table(default_conf, ticker, mocker) -> None: assert error assert '*Status:* `no active order`' in result - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() (error, result) = rpc.rpc_status_table() assert 'just now' in result['Since'].all() assert 'BTC_ETH' in result['Pair'].all() @@ -127,7 +127,7 @@ def test_rpc_daily_profit(default_conf, update, ticker, limit_buy_order, limit_s rpc = RPC(freqtradebot) # Create some test data - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() trade = Trade.query.first() assert trade @@ -188,7 +188,7 @@ def test_rpc_trade_statistics( assert stats.find('no closed trade') >= 0 # Create some test data - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() trade = Trade.query.first() # Simulate fulfilled LIMIT_BUY order for trade trade.update(limit_buy_order) @@ -247,7 +247,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, ticker_sell_u rpc = RPC(freqtradebot) # Create some test data - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() trade = Trade.query.first() # Simulate fulfilled LIMIT_BUY order for trade trade.update(limit_buy_order) @@ -427,7 +427,7 @@ def test_rpc_forcesell(default_conf, ticker, mocker) -> None: assert not error assert res == '' - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() (error, res) = rpc.rpc_forcesell('all') assert not error assert res == '' @@ -462,7 +462,7 @@ def test_rpc_forcesell(default_conf, ticker, mocker) -> None: assert res == '' assert cancel_order_mock.call_count == 1 - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() # make an limit-sell open trade mocker.patch( 'freqtrade.freqtradebot.exchange.get_order', @@ -497,7 +497,7 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, rpc = RPC(freqtradebot) # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() trade = Trade.query.first() assert trade @@ -540,7 +540,7 @@ def test_rpc_count(mocker, default_conf, ticker) -> None: assert nb_trades == 0 # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() (error, trades) = rpc.rpc_count() nb_trades = len(trades) assert not error diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py index d227bd9fb..18764c604 100644 --- a/freqtrade/tests/rpc/test_rpc_telegram.py +++ b/freqtrade/tests/rpc/test_rpc_telegram.py @@ -266,7 +266,7 @@ def test_status(default_conf, update, mocker, ticker) -> None: # Create some test data for _ in range(3): - freqtradebot.create_trade(0.001, 5) + freqtradebot.create_trade() telegram._status(bot=MagicMock(), update=update) assert msg_mock.call_count == 3 @@ -314,7 +314,7 @@ def test_status_handle(default_conf, update, ticker, mocker) -> None: msg_mock.reset_mock() # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() # Trigger status while we have a fulfilled order for the open trade telegram._status(bot=MagicMock(), update=update) @@ -342,7 +342,9 @@ def test_status_table_handle(default_conf, update, ticker, mocker) -> None: ) mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) - freqtradebot = FreqtradeBot(default_conf, create_engine('sqlite://')) + conf = deepcopy(default_conf) + conf['stake_amount'] = 15.0 + freqtradebot = FreqtradeBot(conf, create_engine('sqlite://')) telegram = Telegram(freqtradebot) freqtradebot.update_state(State.STOPPED) @@ -358,7 +360,7 @@ def test_status_table_handle(default_conf, update, ticker, mocker) -> None: msg_mock.reset_mock() # Create some test data - freqtradebot.create_trade(15.0, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() telegram._status_table(bot=MagicMock(), update=update) @@ -399,7 +401,7 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, telegram = Telegram(freqtradebot) # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() trade = Trade.query.first() assert trade @@ -426,8 +428,8 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, # Reset msg_mock msg_mock.reset_mock() # Add two other trades - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() + freqtradebot.create_trade() trades = Trade.query.all() for trade in trades: @@ -512,7 +514,7 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, msg_mock.reset_mock() # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() trade = Trade.query.first() # Simulate fulfilled LIMIT_BUY order for trade @@ -764,7 +766,7 @@ def test_forcesell_handle(default_conf, update, ticker, ticker_sell_up, mocker) telegram = Telegram(freqtradebot) # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() trade = Trade.query.first() assert trade @@ -803,7 +805,7 @@ def test_forcesell_down_handle(default_conf, update, ticker, ticker_sell_down, m telegram = Telegram(freqtradebot) # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() # Decrease the price and sell it mocker.patch.multiple( @@ -847,7 +849,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, mocker) -> None: # Create some test data for _ in range(4): - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() rpc_mock.reset_mock() update.message.text = '/forcesell all' @@ -925,7 +927,7 @@ def test_performance_handle(default_conf, update, ticker, limit_buy_order, telegram = Telegram(freqtradebot) # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() trade = Trade.query.first() assert trade @@ -995,7 +997,7 @@ def test_count_handle(default_conf, update, ticker, mocker) -> None: freqtradebot.update_state(State.RUNNING) # Create some test data - freqtradebot.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtradebot.create_trade() msg_mock.reset_mock() telegram._count(bot=MagicMock(), update=update) diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py index 521c4ba06..1987f62b0 100644 --- a/freqtrade/tests/test_freqtradebot.py +++ b/freqtrade/tests/test_freqtradebot.py @@ -255,7 +255,7 @@ def test_create_trade(default_conf, ticker, limit_buy_order, mocker) -> None: # Save state of current whitelist whitelist = deepcopy(default_conf['exchange']['pair_whitelist']) freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() assert trade is not None @@ -287,12 +287,14 @@ def test_create_trade_minimal_amount(default_conf, ticker, mocker) -> None: get_ticker=ticker, buy=buy_mock ) - freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) - min_stake_amount = 0.0005 - freqtrade.create_trade(min_stake_amount, int(default_conf['ticker_interval'])) + conf = deepcopy(default_conf) + conf['stake_amount'] = 0.0005 + freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) + + freqtrade.create_trade() rate, amount = buy_mock.call_args[0][1], buy_mock.call_args[0][2] - assert rate * amount >= min_stake_amount + assert rate * amount >= conf['stake_amount'] def test_create_trade_no_stake_amount(default_conf, ticker, mocker) -> None: @@ -312,7 +314,7 @@ def test_create_trade_no_stake_amount(default_conf, ticker, mocker) -> None: freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) with pytest.raises(DependencyException, match=r'.*stake amount.*'): - freqtrade.create_trade(default_conf['stake_amount'], int(default_conf['ticker_interval'])) + freqtrade.create_trade() def test_create_trade_no_pairs(default_conf, ticker, mocker) -> None: @@ -334,10 +336,10 @@ def test_create_trade_no_pairs(default_conf, ticker, mocker) -> None: conf['exchange']['pair_blacklist'] = ["BTC_ETH"] freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() with pytest.raises(DependencyException, match=r'.*No currency pairs in whitelist.*'): - freqtrade.create_trade(default_conf['stake_amount'], int(default_conf['ticker_interval'])) + freqtrade.create_trade() def test_create_trade_no_pairs_after_blacklist(default_conf, ticker, mocker) -> None: @@ -359,10 +361,10 @@ def test_create_trade_no_pairs_after_blacklist(default_conf, ticker, mocker) -> conf['exchange']['pair_blacklist'] = ["BTC_ETH"] freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() with pytest.raises(DependencyException, match=r'.*No currency pairs in whitelist.*'): - freqtrade.create_trade(conf['stake_amount'], int(conf['ticker_interval'])) + freqtrade.create_trade() def test_create_trade_no_signal(default_conf, mocker) -> None: @@ -381,12 +383,14 @@ def test_create_trade_no_signal(default_conf, mocker) -> None: get_ticker_history=MagicMock(return_value=20), get_balance=MagicMock(return_value=20) ) + + conf = deepcopy(default_conf) + conf['stake_amount'] = 10 freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - stake_amount = 10 Trade.query = MagicMock() Trade.query.filter = MagicMock() - assert not freqtrade.create_trade(stake_amount, int(conf['ticker_interval'])) + assert not freqtrade.create_trade() def test_process_trade_creation(default_conf, ticker, limit_buy_order, @@ -410,7 +414,7 @@ def test_process_trade_creation(default_conf, ticker, limit_buy_order, trades = Trade.query.filter(Trade.is_open.is_(True)).all() assert not trades - result = freqtrade._process(interval=int(default_conf['ticker_interval'])) + result = freqtrade._process() assert result is True trades = Trade.query.filter(Trade.is_open.is_(True)).all() @@ -447,7 +451,7 @@ def test_process_exchange_failures(default_conf, ticker, health, mocker) -> None sleep_mock = mocker.patch('time.sleep', side_effect=lambda _: None) freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) - result = freqtrade._process(interval=int(default_conf['ticker_interval'])) + result = freqtrade._process() assert result is False assert sleep_mock.has_calls() @@ -469,7 +473,7 @@ def test_process_operational_exception(default_conf, ticker, health, mocker) -> freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) assert freqtrade.get_state() == State.RUNNING - result = freqtrade._process(interval=int(default_conf['ticker_interval'])) + result = freqtrade._process() assert result is False assert freqtrade.get_state() == State.STOPPED assert 'OperationalException' in msg_mock.call_args_list[-1][0][0] @@ -494,12 +498,12 @@ def test_process_trade_handling(default_conf, ticker, limit_buy_order, health, m trades = Trade.query.filter(Trade.is_open.is_(True)).all() assert not trades - result = freqtrade._process(interval=int(default_conf['ticker_interval'])) + result = freqtrade._process() assert result is True trades = Trade.query.filter(Trade.is_open.is_(True)).all() assert len(trades) == 1 - result = freqtrade._process(interval=int(default_conf['ticker_interval'])) + result = freqtrade._process() assert result is False @@ -537,10 +541,10 @@ def test_process_maybe_execute_buy(mocker, default_conf) -> None: freqtrade = get_patched_freqtradebot(mocker, default_conf) mocker.patch('freqtrade.freqtradebot.FreqtradeBot.create_trade', MagicMock(return_value=True)) - assert freqtrade.process_maybe_execute_buy(int(default_conf['ticker_interval'])) + assert freqtrade.process_maybe_execute_buy() mocker.patch('freqtrade.freqtradebot.FreqtradeBot.create_trade', MagicMock(return_value=False)) - assert not freqtrade.process_maybe_execute_buy(int(default_conf['ticker_interval'])) + assert not freqtrade.process_maybe_execute_buy() def test_process_maybe_execute_buy_exception(mocker, default_conf, caplog) -> None: @@ -553,7 +557,7 @@ def test_process_maybe_execute_buy_exception(mocker, default_conf, caplog) -> No 'freqtrade.freqtradebot.FreqtradeBot.create_trade', MagicMock(side_effect=DependencyException) ) - freqtrade.process_maybe_execute_buy(int(default_conf['ticker_interval'])) + freqtrade.process_maybe_execute_buy() log_has('Unable to create trade:', caplog.record_tuples) @@ -568,11 +572,11 @@ def test_process_maybe_execute_sell(mocker, default_conf) -> None: trade = MagicMock() trade.open_order_id = '123' - assert not freqtrade.process_maybe_execute_sell(trade, int(default_conf['ticker_interval'])) + assert not freqtrade.process_maybe_execute_sell(trade) trade.is_open = True trade.open_order_id = None # Assert we call handle_trade() if trade is feasible for execution - assert freqtrade.process_maybe_execute_sell(trade, int(default_conf['ticker_interval'])) + assert freqtrade.process_maybe_execute_sell(trade) def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker) -> None: @@ -597,7 +601,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker) - freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() assert trade @@ -606,7 +610,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker) - assert trade.is_open is True patch_get_signal(mocker, value=(False, True)) - assert freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) is True + assert freqtrade.handle_trade(trade) is True assert trade.open_order_id == 'mocked_limit_sell' # Simulate fulfilled LIMIT_SELL order for trade @@ -638,7 +642,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker) -> None: freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() # Buy and Sell triggering, so doing nothing ... trades = Trade.query.all() @@ -647,7 +651,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker) -> None: # Buy is triggering, so buying ... patch_get_signal(mocker, value=(True, False)) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trades = Trade.query.all() nb_trades = len(trades) assert nb_trades == 1 @@ -655,7 +659,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker) -> None: # Buy and Sell are not triggering, so doing nothing ... patch_get_signal(mocker, value=(False, False)) - assert freqtrade.handle_trade(trades[0], int(default_conf['ticker_interval'])) is False + assert freqtrade.handle_trade(trades[0]) is False trades = Trade.query.all() nb_trades = len(trades) assert nb_trades == 1 @@ -663,7 +667,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker) -> None: # Buy and Sell are triggering, so doing nothing ... patch_get_signal(mocker, value=(True, True)) - assert freqtrade.handle_trade(trades[0], int(default_conf['ticker_interval'])) is False + assert freqtrade.handle_trade(trades[0]) is False trades = Trade.query.all() nb_trades = len(trades) assert nb_trades == 1 @@ -672,7 +676,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker) -> None: # Sell is triggering, guess what : we are Selling! patch_get_signal(mocker, value=(False, True)) trades = Trade.query.all() - assert freqtrade.handle_trade(trades[0], int(default_conf['ticker_interval'])) is True + assert freqtrade.handle_trade(trades[0]) is True def test_handle_trade_roi(default_conf, ticker, mocker, caplog) -> None: @@ -695,7 +699,7 @@ def test_handle_trade_roi(default_conf, ticker, mocker, caplog) -> None: mocker.patch('freqtrade.freqtradebot.Analyze.min_roi_reached', return_value=True) freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() trade.is_open = True @@ -706,7 +710,7 @@ def test_handle_trade_roi(default_conf, ticker, mocker, caplog) -> None: # executing # if ROI is reached we must sell patch_get_signal(mocker, value=(False, True)) - assert freqtrade.handle_trade(trade, interval=int(default_conf['ticker_interval'])) + assert freqtrade.handle_trade(trade) assert log_has('Required profit reached. Selling..', caplog.record_tuples) @@ -730,16 +734,16 @@ def test_handle_trade_experimental(default_conf, ticker, mocker, caplog) -> None mocker.patch('freqtrade.freqtradebot.Analyze.min_roi_reached', return_value=False) freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() trade.is_open = True patch_get_signal(mocker, value=(False, False)) - assert not freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) + assert not freqtrade.handle_trade(trade) patch_get_signal(mocker, value=(False, True)) - assert freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) + assert freqtrade.handle_trade(trade) assert log_has('Sell signal received. Selling..', caplog.record_tuples) @@ -759,7 +763,7 @@ def test_close_trade(default_conf, ticker, limit_buy_order, limit_sell_order, mo freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) # Create trade and sell it - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() assert trade @@ -769,7 +773,7 @@ def test_close_trade(default_conf, ticker, limit_buy_order, limit_sell_order, mo assert trade.is_open is False with pytest.raises(ValueError, match=r'.*closed trade.*'): - freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) + freqtrade.handle_trade(trade) def test_check_handle_timedout_buy(default_conf, ticker, limit_buy_order_old, mocker) -> None: @@ -1004,7 +1008,7 @@ def test_execute_sell_up(default_conf, ticker, ticker_sell_up, mocker) -> None: freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) # Create some test data - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() assert trade @@ -1044,7 +1048,7 @@ def test_execute_sell_down(default_conf, ticker, ticker_sell_down, mocker) -> No freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) # Create some test data - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() assert trade @@ -1082,7 +1086,7 @@ def test_execute_sell_without_conf_sell_up(default_conf, ticker, ticker_sell_up, freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) # Create some test data - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() assert trade @@ -1122,7 +1126,7 @@ def test_execute_sell_without_conf_sell_down(default_conf, ticker, freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://')) # Create some test data - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() assert trade @@ -1168,12 +1172,12 @@ def test_sell_profit_only_enable_profit(default_conf, limit_buy_order, mocker) - 'sell_profit_only': True, } freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() trade.update(limit_buy_order) patch_get_signal(mocker, value=(False, True)) - assert freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) is True + assert freqtrade.handle_trade(trade) is True def test_sell_profit_only_disable_profit(default_conf, limit_buy_order, mocker) -> None: @@ -1200,12 +1204,12 @@ def test_sell_profit_only_disable_profit(default_conf, limit_buy_order, mocker) 'sell_profit_only': False, } freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() trade.update(limit_buy_order) patch_get_signal(mocker, value=(False, True)) - assert freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) is True + assert freqtrade.handle_trade(trade) is True def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, mocker) -> None: @@ -1232,12 +1236,12 @@ def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, mocker) -> 'sell_profit_only': True, } freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() trade.update(limit_buy_order) patch_get_signal(mocker, value=(False, True)) - assert freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) is False + assert freqtrade.handle_trade(trade) is False def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, mocker) -> None: @@ -1266,9 +1270,9 @@ def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, mocker) -> } freqtrade = FreqtradeBot(conf, create_engine('sqlite://')) - freqtrade.create_trade(0.001, int(default_conf['ticker_interval'])) + freqtrade.create_trade() trade = Trade.query.first() trade.update(limit_buy_order) patch_get_signal(mocker, value=(False, True)) - assert freqtrade.handle_trade(trade, int(default_conf['ticker_interval'])) is True + assert freqtrade.handle_trade(trade) is True