Test short trade exiting
This commit is contained in:
parent
5b65448e56
commit
09cc43b533
@ -10,16 +10,19 @@ class RPCMessageType(Enum):
|
|||||||
BUY_FILL = 'buy_fill'
|
BUY_FILL = 'buy_fill'
|
||||||
BUY_CANCEL = 'buy_cancel'
|
BUY_CANCEL = 'buy_cancel'
|
||||||
|
|
||||||
SELL = 'sell'
|
|
||||||
SELL_FILL = 'sell_fill'
|
|
||||||
SELL_CANCEL = 'sell_cancel'
|
|
||||||
PROTECTION_TRIGGER = 'protection_trigger'
|
|
||||||
PROTECTION_TRIGGER_GLOBAL = 'protection_trigger_global'
|
|
||||||
|
|
||||||
SHORT = 'short'
|
SHORT = 'short'
|
||||||
SHORT_FILL = 'short_fill'
|
SHORT_FILL = 'short_fill'
|
||||||
SHORT_CANCEL = 'short_cancel'
|
SHORT_CANCEL = 'short_cancel'
|
||||||
|
|
||||||
|
# TODO: The below messagetypes should be renamed to "exit"!
|
||||||
|
# Careful - has an impact on webhooks, therefore needs proper communication
|
||||||
|
SELL = 'sell'
|
||||||
|
SELL_FILL = 'sell_fill'
|
||||||
|
SELL_CANCEL = 'sell_cancel'
|
||||||
|
|
||||||
|
PROTECTION_TRIGGER = 'protection_trigger'
|
||||||
|
PROTECTION_TRIGGER_GLOBAL = 'protection_trigger_global'
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
@ -3266,9 +3266,9 @@ def test_execute_trade_exit_with_stoploss_on_exchange(
|
|||||||
assert rpc_mock.call_count == 3
|
assert rpc_mock.call_count == 3
|
||||||
|
|
||||||
|
|
||||||
# TODO-lev: add short, RPC short, short fill
|
@pytest.mark.parametrize("is_short", [False, True])
|
||||||
def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(default_conf_usdt, ticker_usdt, fee,
|
def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(
|
||||||
mocker) -> None:
|
default_conf_usdt, ticker_usdt, fee, mocker, is_short) -> None:
|
||||||
default_conf_usdt['exchange']['name'] = 'binance'
|
default_conf_usdt['exchange']['name'] = 'binance'
|
||||||
rpc_mock = patch_RPCManager(mocker)
|
rpc_mock = patch_RPCManager(mocker)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
@ -3292,7 +3292,7 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(default_conf_usdt
|
|||||||
|
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade, enter_long=not is_short, enter_short=is_short)
|
||||||
|
|
||||||
# Create some test data
|
# Create some test data
|
||||||
freqtrade.enter_positions()
|
freqtrade.enter_positions()
|
||||||
@ -3306,7 +3306,7 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(default_conf_usdt
|
|||||||
assert trade.stoploss_order_id == '123'
|
assert trade.stoploss_order_id == '123'
|
||||||
assert trade.open_order_id is None
|
assert trade.open_order_id is None
|
||||||
|
|
||||||
# Assuming stoploss on exchnage is hit
|
# Assuming stoploss on exchange is hit
|
||||||
# stoploss_order_id should become None
|
# stoploss_order_id should become None
|
||||||
# and trade should be sold at the price of stoploss
|
# and trade should be sold at the price of stoploss
|
||||||
stoploss_executed = MagicMock(return_value={
|
stoploss_executed = MagicMock(return_value={
|
||||||
@ -3334,9 +3334,15 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(default_conf_usdt
|
|||||||
assert trade.is_open is False
|
assert trade.is_open is False
|
||||||
assert trade.sell_reason == SellType.STOPLOSS_ON_EXCHANGE.value
|
assert trade.sell_reason == SellType.STOPLOSS_ON_EXCHANGE.value
|
||||||
assert rpc_mock.call_count == 3
|
assert rpc_mock.call_count == 3
|
||||||
assert rpc_mock.call_args_list[0][0][0]['type'] == RPCMessageType.BUY
|
if is_short:
|
||||||
assert rpc_mock.call_args_list[1][0][0]['type'] == RPCMessageType.BUY_FILL
|
assert rpc_mock.call_args_list[0][0][0]['type'] == RPCMessageType.SHORT
|
||||||
assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.SELL
|
assert rpc_mock.call_args_list[1][0][0]['type'] == RPCMessageType.SHORT_FILL
|
||||||
|
assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.SELL
|
||||||
|
|
||||||
|
else:
|
||||||
|
assert rpc_mock.call_args_list[0][0][0]['type'] == RPCMessageType.BUY
|
||||||
|
assert rpc_mock.call_args_list[1][0][0]['type'] == RPCMessageType.BUY_FILL
|
||||||
|
assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.SELL
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
Reference in New Issue
Block a user