adapt tests to send sell-reason in sell-message

This commit is contained in:
Matthias 2018-12-04 19:58:43 +01:00
parent 33e9ed5a5e
commit 4143e2c032
3 changed files with 35 additions and 16 deletions

View File

@ -17,6 +17,7 @@ from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
from freqtrade.rpc import RPCMessageType from freqtrade.rpc import RPCMessageType
from freqtrade.rpc.telegram import Telegram, authorized_only from freqtrade.rpc.telegram import Telegram, authorized_only
from freqtrade.strategy.interface import SellType
from freqtrade.state import State from freqtrade.state import State
from freqtrade.tests.conftest import (get_patched_freqtradebot, log_has, from freqtrade.tests.conftest import (get_patched_freqtradebot, log_has,
patch_exchange) patch_exchange)
@ -729,6 +730,7 @@ def test_forcesell_handle(default_conf, update, ticker, fee,
'profit_percent': 0.0611052, 'profit_percent': 0.0611052,
'stake_currency': 'BTC', 'stake_currency': 'BTC',
'fiat_currency': 'USD', 'fiat_currency': 'USD',
'sell_reason': SellType.FORCE_SELL.value
} == last_msg } == last_msg
@ -782,6 +784,7 @@ def test_forcesell_down_handle(default_conf, update, ticker, fee,
'profit_percent': -0.05478342, 'profit_percent': -0.05478342,
'stake_currency': 'BTC', 'stake_currency': 'BTC',
'fiat_currency': 'USD', 'fiat_currency': 'USD',
'sell_reason': SellType.FORCE_SELL.value
} == last_msg } == last_msg
@ -827,6 +830,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, markets, mocker
'profit_percent': -0.00589291, 'profit_percent': -0.00589291,
'stake_currency': 'BTC', 'stake_currency': 'BTC',
'fiat_currency': 'USD', 'fiat_currency': 'USD',
'sell_reason': SellType.FORCE_SELL.value
} == msg } == msg
@ -1127,16 +1131,18 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
'profit_amount': -0.05746268, 'profit_amount': -0.05746268,
'profit_percent': -0.57405275, 'profit_percent': -0.57405275,
'stake_currency': 'ETH', 'stake_currency': 'ETH',
'fiat_currency': 'USD' 'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value
}) })
assert msg_mock.call_args[0][0] \ assert msg_mock.call_args[0][0] \
== '*Binance:* Selling [KEY/ETH]' \ == ('*Binance:* Selling [KEY/ETH]'
'(https://www.binance.com/tradeDetail.html?symbol=KEY_ETH)\n' \ '(https://www.binance.com/tradeDetail.html?symbol=KEY_ETH)\n'
'*Limit:* `0.00003201`\n' \ '*Limit:* `0.00003201`\n'
'*Amount:* `1333.33333333`\n' \ '*Amount:* `1333.33333333`\n'
'*Open Rate:* `0.00007500`\n' \ '*Open Rate:* `0.00007500`\n'
'*Current Rate:* `0.00003201`\n' \ '*Current Rate:* `0.00003201`\n'
'*Profit:* `-57.41%`` (loss: -0.05746268 ETH`` / -24.812 USD)`' '*Sell Reason:* `stop_loss`\n'
'*Profit:* `-57.41%`` (loss: -0.05746268 ETH`` / -24.812 USD)`')
msg_mock.reset_mock() msg_mock.reset_mock()
telegram.send_msg({ telegram.send_msg({
@ -1152,15 +1158,17 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
'profit_amount': -0.05746268, 'profit_amount': -0.05746268,
'profit_percent': -0.57405275, 'profit_percent': -0.57405275,
'stake_currency': 'ETH', 'stake_currency': 'ETH',
'sell_reason': SellType.STOP_LOSS.value
}) })
assert msg_mock.call_args[0][0] \ assert msg_mock.call_args[0][0] \
== '*Binance:* Selling [KEY/ETH]' \ == ('*Binance:* Selling [KEY/ETH]'
'(https://www.binance.com/tradeDetail.html?symbol=KEY_ETH)\n' \ '(https://www.binance.com/tradeDetail.html?symbol=KEY_ETH)\n'
'*Limit:* `0.00003201`\n' \ '*Limit:* `0.00003201`\n'
'*Amount:* `1333.33333333`\n' \ '*Amount:* `1333.33333333`\n'
'*Open Rate:* `0.00007500`\n' \ '*Open Rate:* `0.00007500`\n'
'*Current Rate:* `0.00003201`\n' \ '*Current Rate:* `0.00003201`\n'
'*Profit:* `-57.41%`' '*Sell Reason:* `stop_loss`\n'
'*Profit:* `-57.41%`')
# Reset singleton function to avoid random breaks # Reset singleton function to avoid random breaks
telegram._fiat_converter.convert_amount = old_convamount telegram._fiat_converter.convert_amount = old_convamount
@ -1278,7 +1286,8 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
'profit_amount': -0.05746268, 'profit_amount': -0.05746268,
'profit_percent': -0.57405275, 'profit_percent': -0.57405275,
'stake_currency': 'ETH', 'stake_currency': 'ETH',
'fiat_currency': 'USD' 'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value
}) })
assert msg_mock.call_args[0][0] \ assert msg_mock.call_args[0][0] \
== '*Binance:* Selling [KEY/ETH]' \ == '*Binance:* Selling [KEY/ETH]' \
@ -1287,6 +1296,7 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
'*Amount:* `1333.33333333`\n' \ '*Amount:* `1333.33333333`\n' \
'*Open Rate:* `0.00007500`\n' \ '*Open Rate:* `0.00007500`\n' \
'*Current Rate:* `0.00003201`\n' \ '*Current Rate:* `0.00003201`\n' \
'*Sell Reason:* `stop_loss`\n' \
'*Profit:* `-57.41%`' '*Profit:* `-57.41%`'

View File

@ -7,6 +7,7 @@ from requests import RequestException
from freqtrade.rpc import RPCMessageType from freqtrade.rpc import RPCMessageType
from freqtrade.rpc.webhook import Webhook from freqtrade.rpc.webhook import Webhook
from freqtrade.strategy.interface import SellType
from freqtrade.tests.conftest import get_patched_freqtradebot, log_has from freqtrade.tests.conftest import get_patched_freqtradebot, log_has
@ -80,6 +81,7 @@ def test_send_msg(default_conf, mocker):
'profit_amount': 0.001, 'profit_amount': 0.001,
'profit_percent': 0.20, 'profit_percent': 0.20,
'stake_currency': 'BTC', 'stake_currency': 'BTC',
'sell_reason': SellType.STOP_LOSS.value
} }
webhook.send_msg(msg=msg) webhook.send_msg(msg=msg)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1

View File

@ -1513,6 +1513,7 @@ def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, markets, moc
'profit_percent': 0.0611052, 'profit_percent': 0.0611052,
'stake_currency': 'BTC', 'stake_currency': 'BTC',
'fiat_currency': 'USD', 'fiat_currency': 'USD',
'sell_reason': SellType.ROI.value
} == last_msg } == last_msg
@ -1559,6 +1560,7 @@ def test_execute_sell_down(default_conf, ticker, fee, ticker_sell_down, markets,
'profit_percent': -0.05478342, 'profit_percent': -0.05478342,
'stake_currency': 'BTC', 'stake_currency': 'BTC',
'fiat_currency': 'USD', 'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value
} == last_msg } == last_msg
@ -1613,6 +1615,8 @@ def test_execute_sell_down_stoploss_on_exchange_dry_run(default_conf, ticker, fe
'profit_percent': -0.01493766, 'profit_percent': -0.01493766,
'stake_currency': 'BTC', 'stake_currency': 'BTC',
'fiat_currency': 'USD', 'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value
} == last_msg } == last_msg
@ -1781,6 +1785,8 @@ def test_execute_sell_without_conf_sell_up(default_conf, ticker, fee,
'current_rate': 1.172e-05, 'current_rate': 1.172e-05,
'profit_amount': 6.126e-05, 'profit_amount': 6.126e-05,
'profit_percent': 0.0611052, 'profit_percent': 0.0611052,
'sell_reason': SellType.ROI.value
} == last_msg } == last_msg
@ -1827,6 +1833,7 @@ def test_execute_sell_without_conf_sell_down(default_conf, ticker, fee,
'current_rate': 1.044e-05, 'current_rate': 1.044e-05,
'profit_amount': -5.492e-05, 'profit_amount': -5.492e-05,
'profit_percent': -0.05478342, 'profit_percent': -0.05478342,
'sell_reason': SellType.STOP_LOSS.value
} == last_msg } == last_msg