added real tests for stop on exchange in dry-run
This commit is contained in:
		| @@ -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}) | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user