From b2c0b20a58c161961d13bb1fa34494516f93332e Mon Sep 17 00:00:00 2001 From: misagh Date: Sat, 24 Nov 2018 18:26:04 +0100 Subject: [PATCH] added real tests for stop on exchange in dry-run --- freqtrade/exchange/__init__.py | 17 +++++++++++++++++ freqtrade/tests/exchange/test_exchange.py | 23 ++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index a88fb6ee8..fc28516f4 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -349,6 +349,23 @@ class Exchange(object): raise OperationalException( 'In stoploss limit order, stop price should be more than limit price') + if self._conf['dry_run']: + order_id = f'dry_run_buy_{randint(0, 10**6)}' + self._dry_run_open_orders[order_id] = { + 'info': {}, + 'id': order_id, + 'pair': pair, + 'price': stop_price, + 'amount': amount, + 'type': 'stop_loss_limit', + 'side': 'sell', + 'remaining': amount, + 'datetime': arrow.utcnow().isoformat(), + 'status': 'open', + 'fee': None + } + return self._dry_run_open_orders[order_id] + return self._api.create_order(pair, 'stop_loss', 'sell', amount, rate, {'stopPrice': stop_price}) diff --git a/freqtrade/tests/exchange/test_exchange.py b/freqtrade/tests/exchange/test_exchange.py index 402596da8..5ae6a031a 100644 --- a/freqtrade/tests/exchange/test_exchange.py +++ b/freqtrade/tests/exchange/test_exchange.py @@ -1218,16 +1218,7 @@ def test_stoploss_limit_order(default_conf, mocker): def test_stoploss_limit_order_dry_run(default_conf, mocker): api_mock = MagicMock() - order_id = 'test_prod_buy_{}'.format(randint(0, 10 ** 6)) - order_type = 'stop_loss' - - api_mock.create_order = MagicMock(return_value={ - 'id': order_id, - 'info': { - 'foo': 'bar' - } - }) - + order_type = 'stop_loss_limit' default_conf['dry_run'] = True mocker.patch('freqtrade.exchange.Exchange.symbol_amount_prec', lambda s, x, y: y) mocker.patch('freqtrade.exchange.Exchange.symbol_price_prec', lambda s, x, y: y) @@ -1243,10 +1234,8 @@ def test_stoploss_limit_order_dry_run(default_conf, mocker): assert 'id' in order assert 'info' in order - assert order['id'] == order_id - assert api_mock.create_order.call_args[0][0] == 'ETH/BTC' - assert api_mock.create_order.call_args[0][1] == order_type - assert api_mock.create_order.call_args[0][2] == 'sell' - assert api_mock.create_order.call_args[0][3] == 1 - assert api_mock.create_order.call_args[0][4] == 200 - assert api_mock.create_order.call_args[0][5] == {'stopPrice': 220} + assert 'type' in order + + assert order['type'] == order_type + assert order['price'] == 220 + assert order['amount'] == 1