mock exchange to avoid random failures

This commit is contained in:
Matthias 2018-08-25 13:21:10 +02:00
parent a489a044ad
commit 42587741dd
1 changed files with 28 additions and 8 deletions

View File

@ -1946,12 +1946,17 @@ def test_order_book_depth_of_market_high_delta(default_conf, ticker, limit_buy_o
assert trade is None assert trade is None
def test_order_book_bid_strategy1(mocker, default_conf, order_book_l2) -> None: def test_order_book_bid_strategy1(mocker, default_conf, order_book_l2, markets) -> None:
""" """
test if function get_target_bid will return the order book price test if function get_target_bid will return the order book price
instead of the ask rate instead of the ask rate
""" """
mocker.patch('freqtrade.exchange.Exchange.get_order_book', order_book_l2) mocker.patch.multiple(
'freqtrade.exchange.Exchange',
validate_pairs=MagicMock(),
get_markets=markets,
get_order_book=order_book_l2
)
default_conf['exchange']['name'] = 'binance' default_conf['exchange']['name'] = 'binance'
default_conf['experimental']['bid_strategy']['use_order_book'] = True default_conf['experimental']['bid_strategy']['use_order_book'] = True
default_conf['experimental']['bid_strategy']['order_book_top'] = 2 default_conf['experimental']['bid_strategy']['order_book_top'] = 2
@ -1962,12 +1967,17 @@ def test_order_book_bid_strategy1(mocker, default_conf, order_book_l2) -> None:
assert freqtrade.get_target_bid('ETH/BTC', {'ask': 0.045, 'last': 0.046}) == 0.043935 assert freqtrade.get_target_bid('ETH/BTC', {'ask': 0.045, 'last': 0.046}) == 0.043935
def test_order_book_bid_strategy2(mocker, default_conf, order_book_l2) -> None: def test_order_book_bid_strategy2(mocker, default_conf, order_book_l2, markets) -> None:
""" """
test if function get_target_bid will return the ask rate (since its value is lower) test if function get_target_bid will return the ask rate (since its value is lower)
instead of the order book rate (even if enabled) instead of the order book rate (even if enabled)
""" """
mocker.patch('freqtrade.exchange.Exchange.get_order_book', order_book_l2) mocker.patch.multiple(
'freqtrade.exchange.Exchange',
validate_pairs=MagicMock(),
get_markets=markets,
get_order_book=order_book_l2
)
default_conf['exchange']['name'] = 'binance' default_conf['exchange']['name'] = 'binance'
default_conf['experimental']['bid_strategy']['use_order_book'] = True default_conf['experimental']['bid_strategy']['use_order_book'] = True
default_conf['experimental']['bid_strategy']['order_book_top'] = 2 default_conf['experimental']['bid_strategy']['order_book_top'] = 2
@ -1978,12 +1988,17 @@ def test_order_book_bid_strategy2(mocker, default_conf, order_book_l2) -> None:
assert freqtrade.get_target_bid('ETH/BTC', {'ask': 0.042, 'last': 0.046}) == 0.042 assert freqtrade.get_target_bid('ETH/BTC', {'ask': 0.042, 'last': 0.046}) == 0.042
def test_order_book_bid_strategy3(default_conf, mocker, order_book_l2) -> None: def test_order_book_bid_strategy3(default_conf, mocker, order_book_l2, markets) -> None:
""" """
test if function get_target_bid will return ask rate instead test if function get_target_bid will return ask rate instead
of the order book rate of the order book rate
""" """
mocker.patch('freqtrade.exchange.Exchange.get_order_book', order_book_l2) mocker.patch.multiple(
'freqtrade.exchange.Exchange',
validate_pairs=MagicMock(),
get_markets=markets,
get_order_book=order_book_l2
)
default_conf['exchange']['name'] = 'binance' default_conf['exchange']['name'] = 'binance'
default_conf['experimental']['bid_strategy']['use_order_book'] = True default_conf['experimental']['bid_strategy']['use_order_book'] = True
default_conf['experimental']['bid_strategy']['order_book_top'] = 1 default_conf['experimental']['bid_strategy']['order_book_top'] = 1
@ -1995,11 +2010,16 @@ def test_order_book_bid_strategy3(default_conf, mocker, order_book_l2) -> None:
assert freqtrade.get_target_bid('ETH/BTC', {'ask': 0.03, 'last': 0.029}) == 0.03 assert freqtrade.get_target_bid('ETH/BTC', {'ask': 0.03, 'last': 0.029}) == 0.03
def test_check_depth_of_market_buy(default_conf, mocker, order_book_l2) -> None: def test_check_depth_of_market_buy(default_conf, mocker, order_book_l2, markets) -> None:
""" """
test check depth of market test check depth of market
""" """
mocker.patch('freqtrade.exchange.Exchange.get_order_book', order_book_l2) mocker.patch.multiple(
'freqtrade.exchange.Exchange',
validate_pairs=MagicMock(),
get_markets=markets,
get_order_book=order_book_l2
)
default_conf['telegram']['enabled'] = False default_conf['telegram']['enabled'] = False
default_conf['exchange']['name'] = 'binance' default_conf['exchange']['name'] = 'binance'
default_conf['experimental']['check_depth_of_market']['enabled'] = True default_conf['experimental']['check_depth_of_market']['enabled'] = True