Merge branch 'develop' into backtest-export
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
from datetime import datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
import arrow
|
||||
import pytest
|
||||
from jsonschema import validate
|
||||
from telegram import Message, Chat, Update
|
||||
from telegram import Chat, Message, Update
|
||||
|
||||
from freqtrade.misc import CONF_SCHEMA
|
||||
|
||||
@@ -20,10 +20,10 @@ def default_conf():
|
||||
"fiat_display_currency": "USD",
|
||||
"dry_run": True,
|
||||
"minimal_roi": {
|
||||
"40": 0.0,
|
||||
"30": 0.01,
|
||||
"20": 0.02,
|
||||
"0": 0.04
|
||||
"40": 0.0,
|
||||
"30": 0.01,
|
||||
"20": 0.02,
|
||||
"0": 0.04
|
||||
},
|
||||
"stoploss": -0.10,
|
||||
"unfilledtimeout": 600,
|
||||
|
@@ -32,7 +32,7 @@ def _stub_config():
|
||||
'secret': ''}
|
||||
|
||||
|
||||
class Fake_bittrex():
|
||||
class FakeBittrex():
|
||||
def __init__(self, success=True):
|
||||
self.success = True # Believe in yourself
|
||||
self.result = None
|
||||
@@ -145,7 +145,7 @@ def test_exchange_bittrex_fee():
|
||||
|
||||
def test_exchange_bittrex_buy_good(mocker):
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
uuid = wb.buy('BTC_ETH', 1, 1)
|
||||
assert uuid == fb.fake_buysell_limit(1, 2, 3)['result']['uuid']
|
||||
|
||||
@@ -156,7 +156,7 @@ def test_exchange_bittrex_buy_good(mocker):
|
||||
|
||||
def test_exchange_bittrex_sell_good(mocker):
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
uuid = wb.sell('BTC_ETH', 1, 1)
|
||||
assert uuid == fb.fake_buysell_limit(1, 2, 3)['result']['uuid']
|
||||
|
||||
@@ -167,7 +167,7 @@ def test_exchange_bittrex_sell_good(mocker):
|
||||
|
||||
def test_exchange_bittrex_get_balance(mocker):
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
bal = wb.get_balance('BTC_ETH')
|
||||
assert bal == fb.fake_get_balance(1)['result']['Balance']
|
||||
|
||||
@@ -178,7 +178,7 @@ def test_exchange_bittrex_get_balance(mocker):
|
||||
|
||||
def test_exchange_bittrex_get_balances():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
bals = wb.get_balances()
|
||||
assert bals == fb.fake_get_balances()['result']
|
||||
|
||||
@@ -189,7 +189,7 @@ def test_exchange_bittrex_get_balances():
|
||||
|
||||
def test_exchange_bittrex_get_ticker():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
|
||||
# Poll ticker, which updates the cache
|
||||
tick = wb.get_ticker('BTC_ETH')
|
||||
@@ -210,7 +210,7 @@ def test_exchange_bittrex_get_ticker():
|
||||
|
||||
def test_exchange_bittrex_get_ticker_bad():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
fb.result = {'success': True,
|
||||
'result': {'Bid': 1}} # incomplete result
|
||||
with pytest.raises(ContentDecodingError, match=r'.*Got invalid response from bittrex params.*'):
|
||||
@@ -222,15 +222,15 @@ def test_exchange_bittrex_get_ticker_bad():
|
||||
wb.get_ticker('BTC_ETH')
|
||||
|
||||
|
||||
def test_exchange_bittrex_get_ticker_historyOne():
|
||||
def test_exchange_bittrex_get_ticker_history_one():
|
||||
wb = make_wrap_bittrex()
|
||||
Fake_bittrex()
|
||||
FakeBittrex()
|
||||
assert wb.get_ticker_history('BTC_ETH', 1)
|
||||
|
||||
|
||||
def test_exchange_bittrex_get_ticker_history():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
assert wb.get_ticker_history('BTC_ETH', 5)
|
||||
with pytest.raises(ValueError, match=r'.*Cannot parse tick_interval.*'):
|
||||
wb.get_ticker_history('BTC_ETH', 2)
|
||||
@@ -253,7 +253,7 @@ def test_exchange_bittrex_get_ticker_history():
|
||||
|
||||
def test_exchange_bittrex_get_order():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
order = wb.get_order('someUUID')
|
||||
assert order['id'] == 'ABC123'
|
||||
fb.success = False
|
||||
@@ -263,7 +263,7 @@ def test_exchange_bittrex_get_order():
|
||||
|
||||
def test_exchange_bittrex_cancel_order():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
wb.cancel_order('someUUID')
|
||||
with pytest.raises(btx.OperationalException, match=r'no such order'):
|
||||
fb.success = False
|
||||
@@ -284,7 +284,7 @@ def test_exchange_get_pair_detail_url():
|
||||
|
||||
def test_exchange_get_markets():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
x = wb.get_markets()
|
||||
assert x == ['__']
|
||||
with pytest.raises(btx.OperationalException, match=r'market gone'):
|
||||
@@ -294,7 +294,7 @@ def test_exchange_get_markets():
|
||||
|
||||
def test_exchange_get_market_summaries():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
assert ['sum'] == wb.get_market_summaries()
|
||||
with pytest.raises(btx.OperationalException, match=r'no summary'):
|
||||
fb.success = False
|
||||
@@ -303,7 +303,7 @@ def test_exchange_get_market_summaries():
|
||||
|
||||
def test_exchange_get_wallet_health():
|
||||
wb = make_wrap_bittrex()
|
||||
fb = Fake_bittrex()
|
||||
fb = FakeBittrex()
|
||||
x = wb.get_wallet_health()
|
||||
assert x[0]['Currency'] == 'BTC_ETH'
|
||||
with pytest.raises(btx.OperationalException, match=r'bad health'):
|
||||
|
@@ -1,7 +1,6 @@
|
||||
# pragma pylint: disable=missing-docstring,W0212,C0103
|
||||
|
||||
from freqtrade.optimize.hyperopt import calculate_loss, TARGET_TRADES, EXPECTED_MAX_PROFIT, start, \
|
||||
log_results
|
||||
log_results, save_trials, read_trials
|
||||
|
||||
|
||||
def test_loss_calculation_prefer_correct_trade_count():
|
||||
@@ -27,16 +26,37 @@ def test_loss_calculation_has_limited_profit():
|
||||
|
||||
|
||||
def create_trials(mocker):
|
||||
"""
|
||||
When creating trials, mock the hyperopt Trials so that *by default*
|
||||
- we don't create any pickle'd files in the filesystem
|
||||
- we might have a pickle'd file so make sure that we return
|
||||
false when looking for it
|
||||
"""
|
||||
mocker.patch('freqtrade.optimize.hyperopt.TRIALS_FILE',
|
||||
return_value='freqtrade/tests/optimize/ut_trials.pickle')
|
||||
mocker.patch('freqtrade.optimize.hyperopt.os.path.exists',
|
||||
return_value=False)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.save_trials',
|
||||
return_value=None)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.read_trials',
|
||||
return_value=None)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.os.remove',
|
||||
return_value=True)
|
||||
return mocker.Mock(
|
||||
results=[{
|
||||
'loss': 1,
|
||||
'result': 'foo'
|
||||
}]
|
||||
'result': 'foo',
|
||||
'status': 'ok'
|
||||
}],
|
||||
best_trial={'misc': {'vals': {'adx': 999}}}
|
||||
)
|
||||
|
||||
|
||||
def test_start_calls_fmin(mocker):
|
||||
mocker.patch('freqtrade.optimize.hyperopt.Trials', return_value=create_trials(mocker))
|
||||
trials = create_trials(mocker)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.TRIALS', return_value=trials)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.sorted',
|
||||
return_value=trials.results)
|
||||
mocker.patch('freqtrade.optimize.preprocess')
|
||||
mocker.patch('freqtrade.optimize.load_data')
|
||||
mock_fmin = mocker.patch('freqtrade.optimize.hyperopt.fmin', return_value={})
|
||||
@@ -141,3 +161,63 @@ def test_fmin_throw_value_error(mocker, caplog):
|
||||
|
||||
for line in exists:
|
||||
assert line in caplog.text
|
||||
|
||||
|
||||
def test_resuming_previous_hyperopt_results_succeeds(mocker):
|
||||
import freqtrade.optimize.hyperopt as hyperopt
|
||||
trials = create_trials(mocker)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.TRIALS',
|
||||
return_value=trials)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.os.path.exists',
|
||||
return_value=True)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.len',
|
||||
return_value=len(trials.results))
|
||||
mock_read = mocker.patch('freqtrade.optimize.hyperopt.read_trials',
|
||||
return_value=trials)
|
||||
mock_save = mocker.patch('freqtrade.optimize.hyperopt.save_trials',
|
||||
return_value=None)
|
||||
mocker.patch('freqtrade.optimize.hyperopt.sorted',
|
||||
return_value=trials.results)
|
||||
mocker.patch('freqtrade.optimize.preprocess')
|
||||
mocker.patch('freqtrade.optimize.load_data')
|
||||
mocker.patch('freqtrade.optimize.hyperopt.fmin',
|
||||
return_value={})
|
||||
args = mocker.Mock(epochs=1,
|
||||
config='config.json.example',
|
||||
mongodb=False)
|
||||
|
||||
start(args)
|
||||
|
||||
mock_read.assert_called_once()
|
||||
mock_save.assert_called_once()
|
||||
|
||||
current_tries = hyperopt._CURRENT_TRIES
|
||||
total_tries = hyperopt.TOTAL_TRIES
|
||||
|
||||
assert current_tries == len(trials.results)
|
||||
assert total_tries == (current_tries + len(trials.results))
|
||||
|
||||
|
||||
def test_save_trials_saves_trials(mocker):
|
||||
trials = create_trials(mocker)
|
||||
mock_dump = mocker.patch('freqtrade.optimize.hyperopt.pickle.dump',
|
||||
return_value=None)
|
||||
trials_path = mocker.patch('freqtrade.optimize.hyperopt.TRIALS_FILE',
|
||||
return_value='ut_trials.pickle')
|
||||
mocker.patch('freqtrade.optimize.hyperopt.open',
|
||||
return_value=trials_path)
|
||||
save_trials(trials, trials_path)
|
||||
|
||||
mock_dump.assert_called_once_with(trials, trials_path)
|
||||
|
||||
|
||||
def test_read_trials_returns_trials_file(mocker):
|
||||
trials = create_trials(mocker)
|
||||
mock_load = mocker.patch('freqtrade.optimize.hyperopt.pickle.load',
|
||||
return_value=trials)
|
||||
mock_open = mocker.patch('freqtrade.optimize.hyperopt.open',
|
||||
return_value=mock_load)
|
||||
|
||||
assert read_trials() == trials
|
||||
mock_open.assert_called_once()
|
||||
mock_load.assert_called_once()
|
||||
|
@@ -6,7 +6,7 @@ from shutil import copyfile
|
||||
from freqtrade import exchange, optimize
|
||||
from freqtrade.exchange import Bittrex
|
||||
from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\
|
||||
download_backtesting_testdata, load_tickerdata_file
|
||||
download_backtesting_testdata, load_tickerdata_file
|
||||
|
||||
# Change this if modifying BTC_UNITEST testdatafile
|
||||
_btc_unittest_length = 13681
|
||||
|
@@ -7,17 +7,17 @@ from freqtrade.main import refresh_whitelist, gen_pair_whitelist
|
||||
|
||||
def whitelist_conf():
|
||||
return {
|
||||
"stake_currency": "BTC",
|
||||
"exchange": {
|
||||
"pair_whitelist": [
|
||||
"BTC_ETH",
|
||||
"BTC_TKN",
|
||||
"BTC_TRST",
|
||||
"BTC_SWT",
|
||||
"BTC_BCC"
|
||||
'stake_currency': 'BTC',
|
||||
'exchange': {
|
||||
'pair_whitelist': [
|
||||
'BTC_ETH',
|
||||
'BTC_TKN',
|
||||
'BTC_TRST',
|
||||
'BTC_SWT',
|
||||
'BTC_BCC'
|
||||
],
|
||||
"pair_blacklist": [
|
||||
"BTC_BLK"
|
||||
'pair_blacklist': [
|
||||
'BTC_BLK'
|
||||
],
|
||||
},
|
||||
}
|
||||
@@ -25,52 +25,51 @@ def whitelist_conf():
|
||||
|
||||
def get_market_summaries():
|
||||
return [{
|
||||
"MarketName": "BTC-TKN",
|
||||
"High": 0.00000919,
|
||||
"Low": 0.00000820,
|
||||
"Volume": 74339.61396015,
|
||||
"Last": 0.00000820,
|
||||
"BaseVolume": 1664,
|
||||
"TimeStamp": "2014-07-09T07:19:30.15",
|
||||
"Bid": 0.00000820,
|
||||
"Ask": 0.00000831,
|
||||
"OpenBuyOrders": 15,
|
||||
"OpenSellOrders": 15,
|
||||
"PrevDay": 0.00000821,
|
||||
"Created": "2014-03-20T06:00:00",
|
||||
"DisplayMarketName": ""
|
||||
}, {
|
||||
"MarketName": "BTC-ETH",
|
||||
"High": 0.00000072,
|
||||
"Low": 0.00000001,
|
||||
"Volume": 166340678.42280999,
|
||||
"Last": 0.00000005,
|
||||
"BaseVolume": 42,
|
||||
"TimeStamp": "2014-07-09T07:21:40.51",
|
||||
"Bid": 0.00000004,
|
||||
"Ask": 0.00000005,
|
||||
"OpenBuyOrders": 18,
|
||||
"OpenSellOrders": 18,
|
||||
"PrevDay": 0.00000002,
|
||||
"Created": "2014-05-30T07:57:49.637",
|
||||
"DisplayMarketName": ""
|
||||
}, {
|
||||
"MarketName": "BTC-BLK",
|
||||
"High": 0.00000072,
|
||||
"Low": 0.00000001,
|
||||
"Volume": 166340678.42280999,
|
||||
"Last": 0.00000005,
|
||||
"BaseVolume": 3,
|
||||
"TimeStamp": "2014-07-09T07:21:40.51",
|
||||
"Bid": 0.00000004,
|
||||
"Ask": 0.00000005,
|
||||
"OpenBuyOrders": 18,
|
||||
"OpenSellOrders": 18,
|
||||
"PrevDay": 0.00000002,
|
||||
"Created": "2014-05-30T07:57:49.637",
|
||||
"DisplayMarketName": ""
|
||||
}
|
||||
]
|
||||
'MarketName': 'BTC-TKN',
|
||||
'High': 0.00000919,
|
||||
'Low': 0.00000820,
|
||||
'Volume': 74339.61396015,
|
||||
'Last': 0.00000820,
|
||||
'BaseVolume': 1664,
|
||||
'TimeStamp': '2014-07-09T07:19:30.15',
|
||||
'Bid': 0.00000820,
|
||||
'Ask': 0.00000831,
|
||||
'OpenBuyOrders': 15,
|
||||
'OpenSellOrders': 15,
|
||||
'PrevDay': 0.00000821,
|
||||
'Created': '2014-03-20T06:00:00',
|
||||
'DisplayMarketName': ''
|
||||
}, {
|
||||
'MarketName': 'BTC-ETH',
|
||||
'High': 0.00000072,
|
||||
'Low': 0.00000001,
|
||||
'Volume': 166340678.42280999,
|
||||
'Last': 0.00000005,
|
||||
'BaseVolume': 42,
|
||||
'TimeStamp': '2014-07-09T07:21:40.51',
|
||||
'Bid': 0.00000004,
|
||||
'Ask': 0.00000005,
|
||||
'OpenBuyOrders': 18,
|
||||
'OpenSellOrders': 18,
|
||||
'PrevDay': 0.00000002,
|
||||
'Created': '2014-05-30T07:57:49.637',
|
||||
'DisplayMarketName': ''
|
||||
}, {
|
||||
'MarketName': 'BTC-BLK',
|
||||
'High': 0.00000072,
|
||||
'Low': 0.00000001,
|
||||
'Volume': 166340678.42280999,
|
||||
'Last': 0.00000005,
|
||||
'BaseVolume': 3,
|
||||
'TimeStamp': '2014-07-09T07:21:40.51',
|
||||
'Bid': 0.00000004,
|
||||
'Ask': 0.00000005,
|
||||
'OpenBuyOrders': 18,
|
||||
'OpenSellOrders': 18,
|
||||
'PrevDay': 0.00000002,
|
||||
'Created': '2014-05-30T07:57:49.637',
|
||||
'DisplayMarketName': ''
|
||||
}]
|
||||
|
||||
|
||||
def get_health():
|
||||
@@ -95,7 +94,8 @@ def test_refresh_market_pair_not_in_whitelist(mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
get_wallet_health=get_health)
|
||||
refreshedwhitelist = refresh_whitelist(conf['exchange']['pair_whitelist'] + ['BTC_XXX'])
|
||||
refreshedwhitelist = refresh_whitelist(
|
||||
conf['exchange']['pair_whitelist'] + ['BTC_XXX'])
|
||||
# List ordered by BaseVolume
|
||||
whitelist = ['BTC_ETH', 'BTC_TKN']
|
||||
# Ensure all except those in whitelist are removed
|
||||
@@ -123,7 +123,8 @@ def test_refresh_whitelist_dynamic(mocker):
|
||||
get_market_summaries=get_market_summaries)
|
||||
# argument: use the whitelist dynamically by exchange-volume
|
||||
whitelist = ['BTC_TKN', 'BTC_ETH']
|
||||
refreshedwhitelist = refresh_whitelist(gen_pair_whitelist(conf['stake_currency']))
|
||||
refreshedwhitelist = refresh_whitelist(
|
||||
gen_pair_whitelist(conf['stake_currency']))
|
||||
assert whitelist == refreshedwhitelist
|
||||
|
||||
|
||||
|
@@ -6,8 +6,9 @@ import arrow
|
||||
import pytest
|
||||
from pandas import DataFrame
|
||||
|
||||
from freqtrade.analyze import parse_ticker_dataframe, populate_buy_trend, populate_indicators, \
|
||||
get_signal, SignalType, populate_sell_trend
|
||||
from freqtrade.analyze import (SignalType, get_signal, parse_ticker_dataframe,
|
||||
populate_buy_trend, populate_indicators,
|
||||
populate_sell_trend)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import pandas
|
||||
|
||||
from freqtrade import analyze
|
||||
import freqtrade.optimize
|
||||
from freqtrade import analyze
|
||||
|
||||
_pairs = ['BTC_ETH']
|
||||
|
||||
|
@@ -1,10 +1,11 @@
|
||||
# pragma pylint: disable=missing-docstring, too-many-arguments, too-many-ancestors, C0103
|
||||
|
||||
import time
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from freqtrade.fiat_convert import CryptoToFiatConverter, CryptoFiat
|
||||
import pytest
|
||||
|
||||
from freqtrade.fiat_convert import CryptoFiat, CryptoToFiatConverter
|
||||
|
||||
|
||||
def test_pair_convertion_object():
|
||||
|
@@ -1,28 +1,27 @@
|
||||
# pragma pylint: disable=missing-docstring,C0103
|
||||
import copy
|
||||
import logging
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import arrow
|
||||
import pytest
|
||||
import requests
|
||||
import logging
|
||||
import arrow
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
import freqtrade.main as main
|
||||
from freqtrade import DependencyException, OperationalException
|
||||
from freqtrade.analyze import SignalType
|
||||
from freqtrade.exchange import Exchanges
|
||||
from freqtrade.main import create_trade, handle_trade, init, \
|
||||
get_target_bid, _process, execute_sell, check_handle_timedout
|
||||
from freqtrade.misc import get_state, State
|
||||
from freqtrade.main import (_process, check_handle_timedout, create_trade,
|
||||
execute_sell, get_target_bid, handle_trade, init)
|
||||
from freqtrade.misc import State, get_state
|
||||
from freqtrade.persistence import Trade
|
||||
import freqtrade.main as main
|
||||
|
||||
|
||||
# Test that main() can start backtesting or hyperopt.
|
||||
# and also ensure we can pass some specific arguments
|
||||
# argument parsing is done in test_misc.py
|
||||
|
||||
def test_parse_args_backtesting(mocker):
|
||||
""" Test that main() can start backtesting or hyperopt.
|
||||
and also ensure we can pass some specific arguments
|
||||
argument parsing is done in test_misc.py """
|
||||
backtesting_mock = mocker.patch(
|
||||
'freqtrade.optimize.backtesting.start', MagicMock())
|
||||
with pytest.raises(SystemExit, match=r'0'):
|
||||
@@ -269,7 +268,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order, mocker):
|
||||
assert trade.close_date is not None
|
||||
|
||||
|
||||
def test_handle_trade_roi(default_conf, ticker, limit_buy_order, mocker, caplog):
|
||||
def test_handle_trade_roi(default_conf, ticker, mocker, caplog):
|
||||
default_conf.update({'experimental': {'use_sell_signal': True}})
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
|
||||
@@ -301,7 +300,7 @@ def test_handle_trade_roi(default_conf, ticker, limit_buy_order, mocker, caplog)
|
||||
assert ('freqtrade', logging.DEBUG, 'Executing sell due to ROI ...') in caplog.record_tuples
|
||||
|
||||
|
||||
def test_handle_trade_experimental(default_conf, ticker, limit_buy_order, mocker, caplog):
|
||||
def test_handle_trade_experimental(default_conf, ticker, mocker, caplog):
|
||||
default_conf.update({'experimental': {'use_sell_signal': True}})
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
|
||||
@@ -353,7 +352,7 @@ def test_close_trade(default_conf, ticker, limit_buy_order, limit_sell_order, mo
|
||||
handle_trade(trade)
|
||||
|
||||
|
||||
def test_check_handle_timedout_buy(default_conf, ticker, health, limit_buy_order_old, mocker):
|
||||
def test_check_handle_timedout_buy(default_conf, ticker, limit_buy_order_old, mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
cancel_order_mock = MagicMock()
|
||||
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
@@ -385,7 +384,7 @@ def test_check_handle_timedout_buy(default_conf, ticker, health, limit_buy_order
|
||||
assert len(trades) == 0
|
||||
|
||||
|
||||
def test_check_handle_timedout_sell(default_conf, ticker, health, limit_sell_order_old, mocker):
|
||||
def test_check_handle_timedout_sell(default_conf, ticker, limit_sell_order_old, mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
cancel_order_mock = MagicMock()
|
||||
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
@@ -418,7 +417,7 @@ def test_check_handle_timedout_sell(default_conf, ticker, health, limit_sell_ord
|
||||
|
||||
|
||||
def test_check_handle_timedout_partial(default_conf, ticker, limit_buy_order_old_partial,
|
||||
health, mocker):
|
||||
mocker):
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
cancel_order_mock = MagicMock()
|
||||
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
@@ -624,54 +623,54 @@ def test_sell_profit_only_disable_profit(default_conf, limit_buy_order, mocker):
|
||||
|
||||
|
||||
def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, mocker):
|
||||
default_conf['experimental'] = {
|
||||
'use_sell_signal': True,
|
||||
'sell_profit_only': True,
|
||||
}
|
||||
default_conf['experimental'] = {
|
||||
'use_sell_signal': True,
|
||||
'sell_profit_only': True,
|
||||
}
|
||||
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True)
|
||||
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
get_ticker=MagicMock(return_value={
|
||||
'bid': 0.00000172,
|
||||
'ask': 0.00000173,
|
||||
'last': 0.00000172
|
||||
}),
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True)
|
||||
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
get_ticker=MagicMock(return_value={
|
||||
'bid': 0.00000172,
|
||||
'ask': 0.00000173,
|
||||
'last': 0.00000172
|
||||
}),
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
assert handle_trade(trade) is False
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
assert handle_trade(trade) is False
|
||||
|
||||
|
||||
def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, mocker):
|
||||
default_conf['experimental'] = {
|
||||
'use_sell_signal': True,
|
||||
'sell_profit_only': False,
|
||||
}
|
||||
default_conf['experimental'] = {
|
||||
'use_sell_signal': True,
|
||||
'sell_profit_only': False,
|
||||
}
|
||||
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True)
|
||||
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
get_ticker=MagicMock(return_value={
|
||||
'bid': 0.00000172,
|
||||
'ask': 0.00000173,
|
||||
'last': 0.00000172
|
||||
}),
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
|
||||
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True)
|
||||
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
get_ticker=MagicMock(return_value={
|
||||
'bid': 0.00000172,
|
||||
'ask': 0.00000173,
|
||||
'last': 0.00000172
|
||||
}),
|
||||
buy=MagicMock(return_value='mocked_limit_buy'))
|
||||
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
init(default_conf, create_engine('sqlite://'))
|
||||
create_trade(0.001)
|
||||
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
assert handle_trade(trade) is True
|
||||
trade = Trade.query.first()
|
||||
trade.update(limit_buy_order)
|
||||
assert handle_trade(trade) is True
|
||||
|
@@ -1,15 +1,15 @@
|
||||
# pragma pylint: disable=missing-docstring,C0103
|
||||
import argparse
|
||||
import json
|
||||
import time
|
||||
import argparse
|
||||
from copy import deepcopy
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
from jsonschema import ValidationError
|
||||
|
||||
from freqtrade.misc import throttle, parse_args, load_config,\
|
||||
parse_args_common, file_dump_json
|
||||
from freqtrade.misc import (common_args_parser, load_config, parse_args,
|
||||
throttle, file_dump_json)
|
||||
|
||||
|
||||
def test_throttle():
|
||||
@@ -40,12 +40,10 @@ def test_throttle_with_assets():
|
||||
assert result == -1
|
||||
|
||||
|
||||
# Parse common command-line-arguments
|
||||
# used for all tools
|
||||
|
||||
# Parse common command-line-arguments. Used for all tools
|
||||
|
||||
def test_parse_args_none():
|
||||
args = parse_args_common([], '')
|
||||
args = common_args_parser('')
|
||||
assert isinstance(args, argparse.ArgumentParser)
|
||||
|
||||
|
||||
@@ -88,12 +86,12 @@ def test_parse_args_invalid():
|
||||
|
||||
def test_parse_args_dynamic_whitelist():
|
||||
args = parse_args(['--dynamic-whitelist'], '')
|
||||
assert args.dynamic_whitelist is 20
|
||||
assert args.dynamic_whitelist == 20
|
||||
|
||||
|
||||
def test_parse_args_dynamic_whitelist_10():
|
||||
args = parse_args(['--dynamic-whitelist', '10'], '')
|
||||
assert args.dynamic_whitelist is 10
|
||||
assert args.dynamic_whitelist == 10
|
||||
|
||||
|
||||
def test_parse_args_dynamic_whitelist_invalid_values():
|
||||
|
@@ -1,9 +1,10 @@
|
||||
# pragma pylint: disable=missing-docstring
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
import os
|
||||
from freqtrade.exchange import Exchanges
|
||||
from freqtrade.persistence import init, Trade
|
||||
from freqtrade.persistence import Trade, init
|
||||
|
||||
|
||||
def test_init_create_session(default_conf, mocker):
|
||||
|
Reference in New Issue
Block a user