Merge branch 'develop' into test_coverage
This commit is contained in:
@@ -27,6 +27,7 @@ def default_conf():
|
||||
"stake_currency": "BTC",
|
||||
"stake_amount": 0.001,
|
||||
"fiat_display_currency": "USD",
|
||||
"ticker_interval": "5",
|
||||
"dry_run": True,
|
||||
"minimal_roi": {
|
||||
"40": 0.0,
|
||||
|
@@ -200,14 +200,14 @@ def test_get_ticker(default_conf, mocker, ticker):
|
||||
assert ticker['ask'] == 1
|
||||
|
||||
|
||||
def test_get_ticker_history(mocker, ticker):
|
||||
def test_get_ticker_history(default_conf, mocker, ticker):
|
||||
api_mock = MagicMock()
|
||||
tick = 123
|
||||
api_mock.get_ticker_history = MagicMock(return_value=tick)
|
||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||
|
||||
# retrieve original ticker
|
||||
ticks = get_ticker_history(pair='BTC_ETH')
|
||||
ticks = get_ticker_history('BTC_ETH', int(default_conf['ticker_interval']))
|
||||
assert ticks == 123
|
||||
|
||||
# change the ticker
|
||||
@@ -216,7 +216,7 @@ def test_get_ticker_history(mocker, ticker):
|
||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||
|
||||
# ensure caching will still return the original ticker
|
||||
get_ticker_history(pair='BTC_ETH')
|
||||
ticks = get_ticker_history('BTC_ETH', int(default_conf['ticker_interval']))
|
||||
assert ticks == 123
|
||||
|
||||
|
||||
|
@@ -232,6 +232,11 @@ def test_exchange_bittrex_get_ticker_bad():
|
||||
with pytest.raises(btx.OperationalException, match=r'.*gone bad.*'):
|
||||
wb.get_ticker('BTC_ETH')
|
||||
|
||||
fb.result = {'success': True,
|
||||
'result': {'Bid': 1, 'Ask': 0, 'Last': None}} # incomplete result
|
||||
with pytest.raises(ContentDecodingError, match=r'.*Got invalid response from bittrex params.*'):
|
||||
wb.get_ticker('BTC_ETH')
|
||||
|
||||
|
||||
def test_exchange_bittrex_get_ticker_history_one():
|
||||
wb = make_wrap_bittrex()
|
||||
|
@@ -44,6 +44,23 @@ def _clean_test_file(file: str) -> None:
|
||||
os.rename(file_swp, file)
|
||||
|
||||
|
||||
def test_load_data_30min_ticker(default_conf, ticker_history, mocker, caplog):
|
||||
mocker.patch('freqtrade.optimize.get_ticker_history', return_value=ticker_history)
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
|
||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||
|
||||
file = 'freqtrade/tests/testdata/BTC_UNITTEST-30.json'
|
||||
_backup_file(file, copy_file=True)
|
||||
optimize.load_data(None, pairs=['BTC_UNITTEST'], ticker_interval=30)
|
||||
assert os.path.isfile(file) is True
|
||||
assert ('freqtrade.optimize',
|
||||
logging.INFO,
|
||||
'Download the pair: "BTC_ETH", Interval: 30 min'
|
||||
) not in caplog.record_tuples
|
||||
_clean_test_file(file)
|
||||
|
||||
|
||||
def test_load_data_5min_ticker(default_conf, ticker_history, mocker, caplog):
|
||||
mocker.patch('freqtrade.optimize.get_ticker_history', return_value=ticker_history)
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
@@ -52,7 +69,7 @@ def test_load_data_5min_ticker(default_conf, ticker_history, mocker, caplog):
|
||||
|
||||
file = 'freqtrade/tests/testdata/BTC_ETH-5.json'
|
||||
_backup_file(file, copy_file=True)
|
||||
optimize.load_data(None, pairs=['BTC_ETH'])
|
||||
optimize.load_data(None, pairs=['BTC_ETH'], ticker_interval=5)
|
||||
assert os.path.isfile(file) is True
|
||||
assert ('freqtrade.optimize',
|
||||
logging.INFO,
|
||||
@@ -114,17 +131,28 @@ def test_download_pairs(default_conf, ticker_history, mocker):
|
||||
_backup_file(file2_1)
|
||||
_backup_file(file2_5)
|
||||
|
||||
assert download_pairs(None, pairs=['BTC-MEME', 'BTC-CFI']) is True
|
||||
assert os.path.isfile(file1_1) is False
|
||||
assert os.path.isfile(file2_1) is False
|
||||
|
||||
assert download_pairs(None, pairs=['BTC-MEME', 'BTC-CFI'], ticker_interval=1) is True
|
||||
|
||||
assert os.path.isfile(file1_1) is True
|
||||
assert os.path.isfile(file1_5) is True
|
||||
assert os.path.isfile(file2_1) is True
|
||||
assert os.path.isfile(file2_5) is True
|
||||
|
||||
# clean files freshly downloaded
|
||||
_clean_test_file(file1_1)
|
||||
_clean_test_file(file1_5)
|
||||
_clean_test_file(file2_1)
|
||||
|
||||
assert os.path.isfile(file1_5) is False
|
||||
assert os.path.isfile(file2_5) is False
|
||||
|
||||
assert download_pairs(None, pairs=['BTC-MEME', 'BTC-CFI'], ticker_interval=5) is True
|
||||
|
||||
assert os.path.isfile(file1_5) is True
|
||||
assert os.path.isfile(file2_5) is True
|
||||
|
||||
# clean files freshly downloaded
|
||||
_clean_test_file(file1_5)
|
||||
_clean_test_file(file2_5)
|
||||
|
||||
|
||||
@@ -140,7 +168,7 @@ def test_download_pairs_exception(default_conf, ticker_history, mocker, caplog):
|
||||
_backup_file(file1_1)
|
||||
_backup_file(file1_5)
|
||||
|
||||
download_pairs(None, pairs=['BTC-MEME'])
|
||||
download_pairs(None, pairs=['BTC-MEME'], ticker_interval=1)
|
||||
# clean files freshly downloaded
|
||||
_clean_test_file(file1_1)
|
||||
_clean_test_file(file1_5)
|
||||
@@ -185,10 +213,11 @@ def test_load_tickerdata_file():
|
||||
assert _btc_unittest_length == len(tickerdata)
|
||||
|
||||
|
||||
def test_init(mocker):
|
||||
def test_init(default_conf, mocker):
|
||||
conf = {'exchange': {'pair_whitelist': []}}
|
||||
mocker.patch('freqtrade.optimize.hyperopt_optimize_conf', return_value=conf)
|
||||
assert {} == optimize.load_data('', pairs=[], refresh_pairs=True)
|
||||
assert {} == optimize.load_data('', pairs=[], refresh_pairs=True,
|
||||
ticker_interval=int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_tickerdata_to_dataframe():
|
||||
|
@@ -102,7 +102,7 @@ def test_status_handle(default_conf, update, ticker, mocker):
|
||||
msg_mock.reset_mock()
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
# Trigger status while we have a fulfilled order for the open trade
|
||||
_status(bot=MagicMock(), update=update)
|
||||
|
||||
@@ -138,7 +138,7 @@ def test_status_table_handle(default_conf, update, ticker, mocker):
|
||||
msg_mock.reset_mock()
|
||||
|
||||
# Create some test data
|
||||
create_trade(15.0)
|
||||
create_trade(15.0, int(default_conf['ticker_interval']))
|
||||
|
||||
_status_table(bot=MagicMock(), update=update)
|
||||
|
||||
@@ -176,7 +176,7 @@ def test_profit_handle(
|
||||
msg_mock.reset_mock()
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
trade = Trade.query.first()
|
||||
|
||||
# Simulate fulfilled LIMIT_BUY order for trade
|
||||
@@ -225,7 +225,7 @@ def test_forcesell_handle(default_conf, update, ticker, ticker_sell_up, mocker):
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
@@ -262,7 +262,7 @@ def test_forcesell_down_handle(default_conf, update, ticker, ticker_sell_down, m
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
# Decrease the price and sell it
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
@@ -324,7 +324,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, mocker):
|
||||
|
||||
# Create some test data
|
||||
for _ in range(4):
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
rpc_mock.reset_mock()
|
||||
|
||||
update.message.text = '/forcesell all'
|
||||
@@ -389,7 +389,7 @@ def test_performance_handle(
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
|
||||
@@ -427,7 +427,7 @@ def test_daily_handle(
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
|
||||
@@ -454,8 +454,8 @@ def test_daily_handle(
|
||||
# Reset msg_mock
|
||||
msg_mock.reset_mock()
|
||||
# Add two other trades
|
||||
create_trade(0.001)
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trades = Trade.query.all()
|
||||
for trade in trades:
|
||||
@@ -502,7 +502,7 @@ def test_count_handle(default_conf, update, ticker, mocker):
|
||||
update_state(State.RUNNING)
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
msg_mock.reset_mock()
|
||||
_count(bot=MagicMock(), update=update)
|
||||
|
||||
|
@@ -44,13 +44,13 @@ def test_returns_latest_buy_signal(mocker):
|
||||
'freqtrade.analyze.analyze_ticker',
|
||||
return_value=DataFrame([{'buy': 1, 'sell': 0, 'date': arrow.utcnow()}])
|
||||
)
|
||||
assert get_signal('BTC-ETH') == (True, False)
|
||||
assert get_signal('BTC-ETH', 5) == (True, False)
|
||||
|
||||
mocker.patch(
|
||||
'freqtrade.analyze.analyze_ticker',
|
||||
return_value=DataFrame([{'buy': 0, 'sell': 1, 'date': arrow.utcnow()}])
|
||||
)
|
||||
assert get_signal('BTC-ETH') == (False, True)
|
||||
assert get_signal('BTC-ETH', 5) == (False, True)
|
||||
|
||||
|
||||
def test_returns_latest_sell_signal(mocker):
|
||||
@@ -59,46 +59,46 @@ def test_returns_latest_sell_signal(mocker):
|
||||
'freqtrade.analyze.analyze_ticker',
|
||||
return_value=DataFrame([{'sell': 1, 'buy': 0, 'date': arrow.utcnow()}])
|
||||
)
|
||||
assert get_signal('BTC-ETH') == (False, True)
|
||||
assert get_signal('BTC-ETH', 5) == (False, True)
|
||||
|
||||
mocker.patch(
|
||||
'freqtrade.analyze.analyze_ticker',
|
||||
return_value=DataFrame([{'sell': 0, 'buy': 1, 'date': arrow.utcnow()}])
|
||||
)
|
||||
assert get_signal('BTC-ETH') == (True, False)
|
||||
assert get_signal('BTC-ETH', 5) == (True, False)
|
||||
|
||||
|
||||
def test_get_signal_empty(mocker, caplog):
|
||||
def test_get_signal_empty(default_conf, mocker, caplog):
|
||||
mocker.patch('freqtrade.analyze.get_ticker_history', return_value=None)
|
||||
assert (False, False) == get_signal('foo')
|
||||
assert (False, False) == get_signal('foo', int(default_conf['ticker_interval']))
|
||||
assert tt.log_has('Empty ticker history for pair foo',
|
||||
caplog.record_tuples)
|
||||
|
||||
|
||||
def test_get_signal_execption_valueerror(mocker, caplog):
|
||||
def test_get_signal_exception_valueerror(default_conf, mocker, caplog):
|
||||
mocker.patch('freqtrade.analyze.get_ticker_history', return_value=1)
|
||||
mocker.patch('freqtrade.analyze.analyze_ticker',
|
||||
side_effect=ValueError('xyz'))
|
||||
assert (False, False) == get_signal('foo')
|
||||
assert (False, False) == get_signal('foo', int(default_conf['ticker_interval']))
|
||||
assert tt.log_has('Unable to analyze ticker for pair foo: xyz',
|
||||
caplog.record_tuples)
|
||||
|
||||
|
||||
def test_get_signal_empty_dataframe(mocker, caplog):
|
||||
def test_get_signal_empty_dataframe(default_conf, mocker, caplog):
|
||||
mocker.patch('freqtrade.analyze.get_ticker_history', return_value=1)
|
||||
mocker.patch('freqtrade.analyze.analyze_ticker', return_value=DataFrame([]))
|
||||
assert (False, False) == get_signal('xyz')
|
||||
assert (False, False) == get_signal('xyz', int(default_conf['ticker_interval']))
|
||||
assert tt.log_has('Empty dataframe for pair xyz',
|
||||
caplog.record_tuples)
|
||||
|
||||
|
||||
def test_get_signal_old_dataframe(mocker, caplog):
|
||||
def test_get_signal_old_dataframe(default_conf, mocker, caplog):
|
||||
mocker.patch('freqtrade.analyze.get_ticker_history', return_value=1)
|
||||
# FIX: The get_signal function has hardcoded 10, which we must inturn hardcode
|
||||
oldtime = arrow.utcnow() - datetime.timedelta(minutes=11)
|
||||
ticks = DataFrame([{'buy': 1, 'date': oldtime}])
|
||||
mocker.patch('freqtrade.analyze.analyze_ticker', return_value=DataFrame(ticks))
|
||||
assert (False, False) == get_signal('xyz')
|
||||
assert (False, False) == get_signal('xyz', int(default_conf['ticker_interval']))
|
||||
assert tt.log_has('Too old dataframe for pair xyz',
|
||||
caplog.record_tuples)
|
||||
|
||||
@@ -108,4 +108,4 @@ def test_get_signal_handles_exceptions(mocker):
|
||||
mocker.patch('freqtrade.analyze.analyze_ticker',
|
||||
side_effect=Exception('invalid ticker history '))
|
||||
|
||||
assert get_signal('BTC-ETH') == (False, False)
|
||||
assert get_signal('BTC-ETH', 5) == (False, False)
|
||||
|
@@ -50,9 +50,9 @@ def test_main_start_hyperopt(mocker):
|
||||
def test_process_maybe_execute_buy(default_conf, mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.create_trade', return_value=True)
|
||||
assert main.process_maybe_execute_buy(default_conf)
|
||||
assert main.process_maybe_execute_buy(default_conf, int(default_conf['ticker_interval']))
|
||||
mocker.patch('freqtrade.main.create_trade', return_value=False)
|
||||
assert not main.process_maybe_execute_buy(default_conf)
|
||||
assert not main.process_maybe_execute_buy(default_conf, int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_process_maybe_execute_sell(default_conf, mocker):
|
||||
@@ -61,17 +61,17 @@ def test_process_maybe_execute_sell(default_conf, mocker):
|
||||
mocker.patch('freqtrade.exchange.get_order', return_value=1)
|
||||
trade = MagicMock()
|
||||
trade.open_order_id = '123'
|
||||
assert not main.process_maybe_execute_sell(trade)
|
||||
assert not main.process_maybe_execute_sell(trade, int(default_conf['ticker_interval']))
|
||||
trade.is_open = True
|
||||
trade.open_order_id = None
|
||||
# Assert we call handle_trade() if trade is feasible for execution
|
||||
assert main.process_maybe_execute_sell(trade)
|
||||
assert main.process_maybe_execute_sell(trade, int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_process_maybe_execute_buy_exception(default_conf, mocker, caplog):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.create_trade', MagicMock(side_effect=DependencyException))
|
||||
main.process_maybe_execute_buy(default_conf)
|
||||
main.process_maybe_execute_buy(default_conf, int(default_conf['ticker_interval']))
|
||||
tt.log_has('Unable to create trade:', caplog.record_tuples)
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ def test_process_trade_creation(default_conf, ticker, limit_buy_order, health, m
|
||||
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
||||
assert not trades
|
||||
|
||||
result = _process()
|
||||
result = _process(interval=int(default_conf['ticker_interval']))
|
||||
assert result is True
|
||||
|
||||
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
||||
@@ -116,7 +116,7 @@ def test_process_exchange_failures(default_conf, ticker, health, mocker):
|
||||
get_wallet_health=health,
|
||||
buy=MagicMock(side_effect=requests.exceptions.RequestException))
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
result = _process()
|
||||
result = _process(interval=int(default_conf['ticker_interval']))
|
||||
assert result is False
|
||||
assert sleep_mock.has_calls()
|
||||
|
||||
@@ -134,7 +134,7 @@ def test_process_operational_exception(default_conf, ticker, health, mocker):
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
assert get_state() == State.RUNNING
|
||||
|
||||
result = _process()
|
||||
result = _process(interval=int(default_conf['ticker_interval']))
|
||||
assert result is False
|
||||
assert get_state() == State.STOPPED
|
||||
assert 'OperationalException' in msg_mock.call_args_list[-1][0][0]
|
||||
@@ -154,12 +154,12 @@ def test_process_trade_handling(default_conf, ticker, limit_buy_order, health, m
|
||||
|
||||
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
||||
assert not trades
|
||||
result = _process()
|
||||
result = _process(interval=int(default_conf['ticker_interval']))
|
||||
assert result is True
|
||||
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
||||
assert len(trades) == 1
|
||||
|
||||
result = _process()
|
||||
result = _process(interval=int(default_conf['ticker_interval']))
|
||||
assert result is False
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ def test_create_trade(default_conf, ticker, limit_buy_order, mocker):
|
||||
whitelist = copy.deepcopy(default_conf['exchange']['pair_whitelist'])
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade is not None
|
||||
@@ -205,7 +205,7 @@ def test_create_trade_minimal_amount(default_conf, ticker, mocker):
|
||||
get_ticker=ticker)
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
min_stake_amount = 0.0005
|
||||
create_trade(min_stake_amount)
|
||||
create_trade(min_stake_amount, int(default_conf['ticker_interval']))
|
||||
rate, amount = buy_mock.call_args[0][1], buy_mock.call_args[0][2]
|
||||
assert rate * amount >= min_stake_amount
|
||||
|
||||
@@ -220,7 +220,7 @@ def test_create_trade_no_stake_amount(default_conf, ticker, mocker):
|
||||
buy=MagicMock(return_value='mocked_limit_buy'),
|
||||
get_balance=MagicMock(return_value=default_conf['stake_amount'] * 0.5))
|
||||
with pytest.raises(DependencyException, match=r'.*stake amount.*'):
|
||||
create_trade(default_conf['stake_amount'])
|
||||
create_trade(default_conf['stake_amount'], int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_create_trade_no_pairs(default_conf, ticker, mocker):
|
||||
@@ -236,7 +236,7 @@ def test_create_trade_no_pairs(default_conf, ticker, mocker):
|
||||
conf = copy.deepcopy(default_conf)
|
||||
conf['exchange']['pair_whitelist'] = []
|
||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
||||
create_trade(default_conf['stake_amount'])
|
||||
create_trade(default_conf['stake_amount'], int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_create_trade_no_pairs_after_blacklist(default_conf, ticker, mocker):
|
||||
@@ -253,7 +253,7 @@ def test_create_trade_no_pairs_after_blacklist(default_conf, ticker, mocker):
|
||||
conf['exchange']['pair_whitelist'] = ["BTC_ETH"]
|
||||
conf['exchange']['pair_blacklist'] = ["BTC_ETH"]
|
||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
||||
create_trade(default_conf['stake_amount'])
|
||||
create_trade(default_conf['stake_amount'], int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_create_trade_no_signal(default_conf, ticker, mocker):
|
||||
@@ -267,7 +267,7 @@ def test_create_trade_no_signal(default_conf, ticker, mocker):
|
||||
stake_amount = 10
|
||||
Trade.query = MagicMock()
|
||||
Trade.query.filter = MagicMock()
|
||||
assert not create_trade(stake_amount)
|
||||
assert not create_trade(stake_amount, int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker):
|
||||
@@ -287,7 +287,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker):
|
||||
ticker=MagicMock(return_value={'price_usd': 15000.0}),
|
||||
_cache_symbols=MagicMock(return_value={'BTC': 1}))
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
@@ -296,7 +296,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker):
|
||||
assert trade.is_open is True
|
||||
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
handle_trade(trade)
|
||||
assert handle_trade(trade, int(default_conf['ticker_interval'])) is True
|
||||
assert trade.open_order_id == 'mocked_limit_sell'
|
||||
|
||||
# Simulate fulfilled LIMIT_SELL order for trade
|
||||
@@ -321,7 +321,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker, caplog):
|
||||
mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
# Buy and Sell triggering, so doing nothing ...
|
||||
trades = Trade.query.all()
|
||||
@@ -329,21 +329,21 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker, caplog):
|
||||
|
||||
# Buy is triggering, so buying ...
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (True, False))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
trades = Trade.query.all()
|
||||
assert len(trades) == 1
|
||||
assert trades[0].is_open is True
|
||||
|
||||
# Buy and Sell are not triggering, so doing nothing ...
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, False))
|
||||
assert handle_trade(trades[0]) is False
|
||||
assert handle_trade(trades[0], int(default_conf['ticker_interval'])) is False
|
||||
trades = Trade.query.all()
|
||||
assert len(trades) == 1
|
||||
assert trades[0].is_open is True
|
||||
|
||||
# Buy and Sell are triggering, so doing nothing ...
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (True, True))
|
||||
assert handle_trade(trades[0]) is False
|
||||
assert handle_trade(trades[0], int(default_conf['ticker_interval'])) is False
|
||||
trades = Trade.query.all()
|
||||
assert len(trades) == 1
|
||||
assert trades[0].is_open is True
|
||||
@@ -351,7 +351,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, mocker, caplog):
|
||||
# Sell is triggering, guess what : we are Selling!
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
trades = Trade.query.all()
|
||||
assert handle_trade(trades[0]) is True
|
||||
assert handle_trade(trades[0], int(default_conf['ticker_interval'])) is True
|
||||
|
||||
|
||||
def test_handle_trade_roi(default_conf, ticker, mocker, caplog):
|
||||
@@ -367,7 +367,7 @@ def test_handle_trade_roi(default_conf, ticker, mocker, caplog):
|
||||
mocker.patch('freqtrade.main.min_roi_reached', return_value=True)
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.is_open = True
|
||||
@@ -378,11 +378,11 @@ def test_handle_trade_roi(default_conf, ticker, mocker, caplog):
|
||||
# executing
|
||||
# if ROI is reached we must sell
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
assert handle_trade(trade)
|
||||
assert handle_trade(trade, interval=int(default_conf['ticker_interval']))
|
||||
assert ('freqtrade', logging.DEBUG, 'Executing sell due to ROI ...') in caplog.record_tuples
|
||||
# if ROI is reached we must sell even if sell-signal is not signalled
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
assert handle_trade(trade)
|
||||
assert handle_trade(trade, interval=int(default_conf['ticker_interval']))
|
||||
assert ('freqtrade', logging.DEBUG, 'Executing sell due to ROI ...') in caplog.record_tuples
|
||||
|
||||
|
||||
@@ -399,16 +399,16 @@ def test_handle_trade_experimental(default_conf, ticker, mocker, caplog):
|
||||
mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.is_open = True
|
||||
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, False))
|
||||
value_returned = handle_trade(trade)
|
||||
value_returned = handle_trade(trade, int(default_conf['ticker_interval']))
|
||||
assert value_returned is False
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
assert handle_trade(trade)
|
||||
assert handle_trade(trade, int(default_conf['ticker_interval']))
|
||||
s = 'Executing sell due to sell signal ...'
|
||||
assert ('freqtrade', logging.DEBUG, s) in caplog.record_tuples
|
||||
|
||||
@@ -424,7 +424,7 @@ def test_close_trade(default_conf, ticker, limit_buy_order, limit_sell_order, mo
|
||||
|
||||
# Create trade and sell it
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
@@ -434,7 +434,7 @@ def test_close_trade(default_conf, ticker, limit_buy_order, limit_sell_order, mo
|
||||
assert trade.is_open is False
|
||||
|
||||
with pytest.raises(ValueError, match=r'.*closed trade.*'):
|
||||
handle_trade(trade)
|
||||
handle_trade(trade, int(default_conf['ticker_interval']))
|
||||
|
||||
|
||||
def test_check_handle_timedout_buy(default_conf, ticker, limit_buy_order_old, mocker):
|
||||
@@ -600,7 +600,7 @@ def test_execute_sell_up(default_conf, ticker, ticker_sell_up, mocker):
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
@@ -637,7 +637,7 @@ def test_execute_sell_down(default_conf, ticker, ticker_sell_down, mocker):
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
@@ -656,7 +656,7 @@ def test_execute_sell_down(default_conf, ticker, ticker_sell_down, mocker):
|
||||
assert '-0.824 USD' in rpc_mock.call_args_list[-1][0][0]
|
||||
|
||||
|
||||
def test_execute_sell_without_conf(default_conf, ticker, ticker_sell_up, mocker):
|
||||
def test_execute_sell_without_conf_sell_down(default_conf, ticker, ticker_sell_down, mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (True, False))
|
||||
mocker.patch('freqtrade.rpc.init', MagicMock())
|
||||
@@ -667,7 +667,39 @@ def test_execute_sell_without_conf(default_conf, ticker, ticker_sell_up, mocker)
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
|
||||
# Decrease the price and sell it
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
get_ticker=ticker_sell_down)
|
||||
mocker.patch('freqtrade.main._CONF', {})
|
||||
|
||||
execute_sell(trade=trade, limit=ticker_sell_down()['bid'])
|
||||
|
||||
print(rpc_mock.call_args_list[-1][0][0])
|
||||
|
||||
assert rpc_mock.call_count == 2
|
||||
assert 'Selling [BTC/ETH]' in rpc_mock.call_args_list[-1][0][0]
|
||||
assert '0.00001044' in rpc_mock.call_args_list[-1][0][0]
|
||||
assert 'loss: -5.48%, -0.00005492' in rpc_mock.call_args_list[-1][0][0]
|
||||
|
||||
|
||||
def test_execute_sell_without_conf_sell_up(default_conf, ticker, ticker_sell_up, mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (True, False))
|
||||
mocker.patch('freqtrade.rpc.init', MagicMock())
|
||||
rpc_mock = mocker.patch('freqtrade.main.rpc.send_msg', MagicMock())
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
get_ticker=ticker)
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
|
||||
# Create some test data
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
@@ -707,12 +739,12 @@ def test_sell_profit_only_enable_profit(default_conf, limit_buy_order, mocker):
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
assert handle_trade(trade) is True
|
||||
assert handle_trade(trade, int(default_conf['ticker_interval'])) is True
|
||||
|
||||
|
||||
def test_sell_profit_only_disable_profit(default_conf, limit_buy_order, mocker):
|
||||
@@ -735,12 +767,12 @@ def test_sell_profit_only_disable_profit(default_conf, limit_buy_order, mocker):
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
assert handle_trade(trade) is True
|
||||
assert handle_trade(trade, int(default_conf['ticker_interval'])) is True
|
||||
|
||||
|
||||
def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, mocker):
|
||||
@@ -763,12 +795,12 @@ def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, mocker):
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
assert handle_trade(trade) is False
|
||||
assert handle_trade(trade, int(default_conf['ticker_interval'])) is False
|
||||
|
||||
|
||||
def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, mocker):
|
||||
@@ -791,10 +823,9 @@ def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, mocker):
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
create_trade(0.001, int(default_conf['ticker_interval']))
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s: (False, True))
|
||||
assert handle_trade(trade) is True
|
||||
assert handle_trade(trade, int(default_conf['ticker_interval'])) is True
|
||||
|
1
freqtrade/tests/testdata/BTC_UNITEST-30.json
vendored
Normal file
1
freqtrade/tests/testdata/BTC_UNITEST-30.json
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user