Merge branch 'develop' into pr/imxuwang/3799

This commit is contained in:
Matthias
2020-11-19 13:18:03 +01:00
54 changed files with 772 additions and 511 deletions

View File

@@ -69,8 +69,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'min_rate': ANY,
'max_rate': ANY,
'strategy': ANY,
'ticker_interval': ANY,
'timeframe': ANY,
'timeframe': 5,
'open_order_id': ANY,
'close_date': None,
'close_date_hum': None,
@@ -87,14 +86,15 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'current_profit': -0.00408133,
'current_profit_pct': -0.41,
'current_profit_abs': -4.09e-06,
'stop_loss': 9.882e-06,
'profit_ratio': -0.00408133,
'profit_pct': -0.41,
'profit_abs': -4.09e-06,
'stop_loss_abs': 9.882e-06,
'stop_loss_pct': -10.0,
'stop_loss_ratio': -0.1,
'stoploss_order_id': None,
'stoploss_last_update': ANY,
'stoploss_last_update_timestamp': ANY,
'initial_stop_loss': 9.882e-06,
'initial_stop_loss_abs': 9.882e-06,
'initial_stop_loss_pct': -10.0,
'initial_stop_loss_ratio': -0.1,
@@ -134,7 +134,6 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'min_rate': ANY,
'max_rate': ANY,
'strategy': ANY,
'ticker_interval': ANY,
'timeframe': ANY,
'open_order_id': ANY,
'close_date': None,
@@ -152,14 +151,15 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'current_profit': ANY,
'current_profit_pct': ANY,
'current_profit_abs': ANY,
'stop_loss': 9.882e-06,
'profit_ratio': ANY,
'profit_pct': ANY,
'profit_abs': ANY,
'stop_loss_abs': 9.882e-06,
'stop_loss_pct': -10.0,
'stop_loss_ratio': -0.1,
'stoploss_order_id': None,
'stoploss_last_update': ANY,
'stoploss_last_update_timestamp': ANY,
'initial_stop_loss': 9.882e-06,
'initial_stop_loss_abs': 9.882e-06,
'initial_stop_loss_pct': -10.0,
'initial_stop_loss_ratio': -0.1,

View File

@@ -2,7 +2,7 @@
Unit test file for rpc/api_server.py
"""
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from pathlib import Path
from unittest.mock import ANY, MagicMock, PropertyMock
@@ -12,9 +12,9 @@ from requests.auth import _basic_auth_str
from freqtrade.__init__ import __version__
from freqtrade.loggers import setup_logging, setup_logging_pre
from freqtrade.persistence import PairLock, Trade
from freqtrade.persistence import PairLocks, Trade
from freqtrade.rpc.api_server import BASE_URI, ApiServer
from freqtrade.state import State
from freqtrade.state import RunMode, State
from tests.conftest import create_mock_trades, get_patched_freqtradebot, log_has, patch_get_signal
@@ -26,7 +26,7 @@ _TEST_PASS = "SuperSecurePassword1!"
def botclient(default_conf, mocker):
setup_logging_pre()
setup_logging(default_conf)
default_conf['runmode'] = RunMode.DRY_RUN
default_conf.update({"api_server": {"enabled": True,
"listen_ip_address": "127.0.0.1",
"listen_port": 8080,
@@ -339,8 +339,8 @@ def test_api_locks(botclient):
assert rc.json['lock_count'] == 0
assert rc.json['lock_count'] == len(rc.json['locks'])
PairLock.lock_pair('ETH/BTC', datetime.utcnow() + timedelta(minutes=4), 'randreason')
PairLock.lock_pair('XRP/BTC', datetime.utcnow() + timedelta(minutes=20), 'deadbeef')
PairLocks.lock_pair('ETH/BTC', datetime.now(timezone.utc) + timedelta(minutes=4), 'randreason')
PairLocks.lock_pair('XRP/BTC', datetime.now(timezone.utc) + timedelta(minutes=20), 'deadbeef')
rc = client_get(client, f"{BASE_URI}/locks")
assert_response(rc)
@@ -360,7 +360,6 @@ def test_api_show_config(botclient, mocker):
assert_response(rc)
assert 'dry_run' in rc.json
assert rc.json['exchange'] == 'bittrex'
assert rc.json['ticker_interval'] == '5m'
assert rc.json['timeframe'] == '5m'
assert rc.json['timeframe_ms'] == 300000
assert rc.json['timeframe_min'] == 5
@@ -639,6 +638,9 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'current_profit': -0.00408133,
'current_profit_pct': -0.41,
'current_profit_abs': -4.09e-06,
'profit_ratio': -0.00408133,
'profit_pct': -0.41,
'profit_abs': -4.09e-06,
'current_rate': 1.099e-05,
'open_date': ANY,
'open_date_hum': 'just now',
@@ -647,14 +649,12 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'open_rate': 1.098e-05,
'pair': 'ETH/BTC',
'stake_amount': 0.001,
'stop_loss': 9.882e-06,
'stop_loss_abs': 9.882e-06,
'stop_loss_pct': -10.0,
'stop_loss_ratio': -0.1,
'stoploss_order_id': None,
'stoploss_last_update': ANY,
'stoploss_last_update_timestamp': ANY,
'initial_stop_loss': 9.882e-06,
'initial_stop_loss_abs': 9.882e-06,
'initial_stop_loss_pct': -10.0,
'initial_stop_loss_ratio': -0.1,
@@ -682,7 +682,6 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
'sell_reason': None,
'sell_order_status': None,
'strategy': 'DefaultStrategy',
'ticker_interval': 5,
'timeframe': 5,
'exchange': 'bittrex',
}]
@@ -779,20 +778,22 @@ def test_api_forcebuy(botclient, mocker, fee):
'open_rate': 0.245441,
'pair': 'ETH/ETH',
'stake_amount': 1,
'stop_loss': None,
'stop_loss_abs': None,
'stop_loss_pct': None,
'stop_loss_ratio': None,
'stoploss_order_id': None,
'stoploss_last_update': None,
'stoploss_last_update_timestamp': None,
'initial_stop_loss': None,
'initial_stop_loss_abs': None,
'initial_stop_loss_pct': None,
'initial_stop_loss_ratio': None,
'close_profit': None,
'close_profit_pct': None,
'close_profit_abs': None,
'close_rate_requested': None,
'profit_ratio': None,
'profit_pct': None,
'profit_abs': None,
'fee_close': 0.0025,
'fee_close_cost': None,
'fee_close_currency': None,
@@ -808,7 +809,6 @@ def test_api_forcebuy(botclient, mocker, fee):
'sell_reason': None,
'sell_order_status': None,
'strategy': None,
'ticker_interval': None,
'timeframe': None,
'exchange': 'bittrex',
}

View File

@@ -18,10 +18,10 @@ from freqtrade.constants import CANCEL_REASON
from freqtrade.edge import PairInfo
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.loggers import setup_logging
from freqtrade.persistence import PairLock, Trade
from freqtrade.persistence import PairLocks, Trade
from freqtrade.rpc import RPCMessageType
from freqtrade.rpc.telegram import Telegram, authorized_only
from freqtrade.state import State
from freqtrade.state import RunMode, State
from freqtrade.strategy.interface import SellType
from tests.conftest import (create_mock_trades, get_patched_freqtradebot, log_has, patch_exchange,
patch_get_signal, patch_whitelist)
@@ -164,16 +164,17 @@ def test_telegram_status(default_conf, update, mocker) -> None:
'amount': 90.99181074,
'stake_amount': 90.99181074,
'close_profit_pct': None,
'current_profit': -0.0059,
'current_profit_pct': -0.59,
'initial_stop_loss': 1.098e-05,
'stop_loss': 1.099e-05,
'profit': -0.0059,
'profit_pct': -0.59,
'initial_stop_loss_abs': 1.098e-05,
'stop_loss_abs': 1.099e-05,
'sell_order_status': None,
'initial_stop_loss_pct': -0.05,
'stoploss_current_dist': 1e-08,
'stoploss_current_dist_pct': -0.02,
'stop_loss_pct': -0.01,
'open_order': '(limit buy rem=0.00000000)'
'open_order': '(limit buy rem=0.00000000)',
'is_open': True
}]),
_status_table=status_table,
_send_msg=msg_mock
@@ -1041,15 +1042,8 @@ def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None
patch_get_signal(freqtradebot, (True, False))
telegram = Telegram(freqtradebot)
freqtradebot.state = State.STOPPED
telegram._locks(update=update, context=MagicMock())
assert msg_mock.call_count == 1
assert 'not running' in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock()
freqtradebot.state = State.RUNNING
PairLock.lock_pair('ETH/BTC', arrow.utcnow().shift(minutes=4).datetime, 'randreason')
PairLock.lock_pair('XRP/BTC', arrow.utcnow().shift(minutes=20).datetime, 'deadbeef')
PairLocks.lock_pair('ETH/BTC', arrow.utcnow().shift(minutes=4).datetime, 'randreason')
PairLocks.lock_pair('XRP/BTC', arrow.utcnow().shift(minutes=20).datetime, 'deadbeef')
telegram._locks(update=update, context=MagicMock())
@@ -1309,6 +1303,7 @@ def test_show_config_handle(default_conf, update, mocker) -> None:
_init=MagicMock(),
_send_msg=msg_mock
)
default_conf['runmode'] = RunMode.DRY_RUN
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
telegram = Telegram(freqtradebot)