mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
added real tests for stop on exchange in dry-run
This commit is contained in:
parent
000711b025
commit
b2c0b20a58
|
@ -349,6 +349,23 @@ class Exchange(object):
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
'In stoploss limit order, stop price should be more than limit price')
|
'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',
|
return self._api.create_order(pair, 'stop_loss', 'sell',
|
||||||
amount, rate, {'stopPrice': stop_price})
|
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):
|
def test_stoploss_limit_order_dry_run(default_conf, mocker):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
order_id = 'test_prod_buy_{}'.format(randint(0, 10 ** 6))
|
order_type = 'stop_loss_limit'
|
||||||
order_type = 'stop_loss'
|
|
||||||
|
|
||||||
api_mock.create_order = MagicMock(return_value={
|
|
||||||
'id': order_id,
|
|
||||||
'info': {
|
|
||||||
'foo': 'bar'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
default_conf['dry_run'] = True
|
default_conf['dry_run'] = True
|
||||||
mocker.patch('freqtrade.exchange.Exchange.symbol_amount_prec', lambda s, x, y: y)
|
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)
|
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 'id' in order
|
||||||
assert 'info' in order
|
assert 'info' in order
|
||||||
assert order['id'] == order_id
|
assert 'type' in order
|
||||||
assert api_mock.create_order.call_args[0][0] == 'ETH/BTC'
|
|
||||||
assert api_mock.create_order.call_args[0][1] == order_type
|
assert order['type'] == order_type
|
||||||
assert api_mock.create_order.call_args[0][2] == 'sell'
|
assert order['price'] == 220
|
||||||
assert api_mock.create_order.call_args[0][3] == 1
|
assert order['amount'] == 1
|
||||||
assert api_mock.create_order.call_args[0][4] == 200
|
|
||||||
assert api_mock.create_order.call_args[0][5] == {'stopPrice': 220}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user