improve formatting, add tests
This commit is contained in:
parent
dd0db7ee5d
commit
fd23ab3d64
@ -284,12 +284,12 @@ class Telegram(RPCHandler):
|
||||
elif msg_type == RPCMessageType.PROTECTION_TRIGGER:
|
||||
message = (
|
||||
"*Protection* triggered due to {reason}. "
|
||||
"{pair} will be locked until {lock_end_time}."
|
||||
"`{pair}` will be locked until `{lock_end_time}`."
|
||||
).format(**msg)
|
||||
elif msg_type == RPCMessageType.PROTECTION_TRIGGER_GLOBAL:
|
||||
message = (
|
||||
"*Protection* triggered due to {reason}. "
|
||||
"All pairs will be locked until {lock_end_time}."
|
||||
"*All pairs* will be locked until `{lock_end_time}`."
|
||||
).format(**msg)
|
||||
elif msg_type == RPCMessageType.STATUS:
|
||||
message = '*Status:* `{status}`'.format(**msg)
|
||||
|
@ -1324,7 +1324,7 @@ def test_send_msg_protection_notification(default_conf, mocker, time_machine) ->
|
||||
msg.update(lock.to_json())
|
||||
telegram.send_msg(msg)
|
||||
assert (msg_mock.call_args[0][0] == "*Protection* triggered due to randreason. "
|
||||
"ETH/BTC will be locked until 2021-09-01 05:10:00.")
|
||||
"`ETH/BTC` will be locked until `2021-09-01 05:10:00`.")
|
||||
|
||||
msg_mock.reset_mock()
|
||||
# Test global protection
|
||||
@ -1336,8 +1336,7 @@ def test_send_msg_protection_notification(default_conf, mocker, time_machine) ->
|
||||
msg.update(lock.to_json())
|
||||
telegram.send_msg(msg)
|
||||
assert (msg_mock.call_args[0][0] == "*Protection* triggered due to randreason. "
|
||||
"All pairs will be locked until 2021-09-01 06:45:00.")
|
||||
|
||||
"*All pairs* will be locked until `2021-09-01 06:45:00`.")
|
||||
|
||||
|
||||
def test_send_msg_buy_fill_notification(default_conf, mocker) -> None:
|
||||
|
@ -526,6 +526,29 @@ def test_enter_positions_global_pairlock(default_conf, ticker, limit_buy_order,
|
||||
assert log_has_re(message, caplog)
|
||||
|
||||
|
||||
def test_handle_protections(mocker, default_conf, fee):
|
||||
default_conf['protections'] = [
|
||||
{"method": "CooldownPeriod", "stop_duration": 60},
|
||||
{
|
||||
"method": "StoplossGuard",
|
||||
"lookback_period_candles": 24,
|
||||
"trade_limit": 4,
|
||||
"stop_duration_candles": 4,
|
||||
"only_per_pair": False
|
||||
}
|
||||
]
|
||||
|
||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||
freqtrade.protections._protection_handlers[1].global_stop = MagicMock(
|
||||
return_value=(True, arrow.utcnow().shift(hours=1).datetime, "asdf"))
|
||||
create_mock_trades(fee)
|
||||
freqtrade.handle_protections('ETC/BTC')
|
||||
send_msg_mock = freqtrade.rpc.send_msg
|
||||
assert send_msg_mock.call_count == 2
|
||||
assert send_msg_mock.call_args_list[0][0][0]['type'] == RPCMessageType.PROTECTION_TRIGGER
|
||||
assert send_msg_mock.call_args_list[1][0][0]['type'] == RPCMessageType.PROTECTION_TRIGGER_GLOBAL
|
||||
|
||||
|
||||
def test_create_trade_no_signal(default_conf, fee, mocker) -> None:
|
||||
default_conf['dry_run'] = True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user