Improve compat tests
This commit is contained in:
parent
36d60fa8a8
commit
38af1b2a5d
@ -223,7 +223,11 @@ def init_persistence(default_conf):
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def default_conf(testdatadir):
|
||||
def default_conf():
|
||||
return get_default_conf()
|
||||
|
||||
|
||||
def get_default_conf(testdatadir):
|
||||
""" Returns validated configuration suitable for most tests """
|
||||
configuration = {
|
||||
"max_open_trades": 1,
|
||||
|
@ -6,38 +6,95 @@ suitable to run with freqtrade.
|
||||
|
||||
"""
|
||||
|
||||
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
||||
from tests.conftest import get_default_conf
|
||||
|
||||
|
||||
# Exchanges that should be tested
|
||||
EXCHANGES = ['bittrex', 'binance', 'kraken', 'ftx']
|
||||
EXCHANGES = {
|
||||
'bittrex': {
|
||||
'pair': 'BTC/USDT',
|
||||
'hasQuoteVolume': False
|
||||
},
|
||||
'binance': {
|
||||
'pair': 'BTC/USDT',
|
||||
'hasQuoteVolume': True
|
||||
},
|
||||
'kraken': {
|
||||
'pair': 'BTC/USDT',
|
||||
'hasQuoteVolume': True
|
||||
},
|
||||
'ftx': {
|
||||
'pair': 'BTC/USDT',
|
||||
'hasQuoteVolume': True
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def exchange_conf(default_conf):
|
||||
default_conf['exchange']['pair_whitelist'] = []
|
||||
return default_conf
|
||||
@pytest.fixture(scope="class")
|
||||
def exchange_conf():
|
||||
config = get_default_conf((Path(__file__).parent / "testdata").resolve())
|
||||
config['exchange']['pair_whitelist'] = []
|
||||
return config
|
||||
|
||||
|
||||
@pytest.mark.parametrize('exchange', EXCHANGES)
|
||||
def test_ccxt_fetch_l2_orderbook(exchange_conf, exchange):
|
||||
|
||||
exchange_conf['exchange']['name'] = exchange
|
||||
exchange_conf['exchange']['name'] = exchange
|
||||
|
||||
exchange = ExchangeResolver.load_exchange(exchange, exchange_conf)
|
||||
l2 = exchange.fetch_l2_order_book('BTC/USDT')
|
||||
assert 'asks' in l2
|
||||
assert 'bids' in l2
|
||||
|
||||
for val in [1, 2, 5, 25, 100]:
|
||||
l2 = exchange.fetch_l2_order_book('BTC/USDT', val)
|
||||
if not exchange._ft_has['l2_limit_range'] or val in exchange._ft_has['l2_limit_range']:
|
||||
assert len(l2['asks']) == val
|
||||
assert len(l2['bids']) == val
|
||||
else:
|
||||
next_limit = exchange.get_next_limit_in_list(val, exchange._ft_has['l2_limit_range'])
|
||||
assert len(l2['asks']) == next_limit
|
||||
assert len(l2['asks']) == next_limit
|
||||
@pytest.fixture(params=EXCHANGES, scope="class")
|
||||
def exchange(request, exchange_conf):
|
||||
exchange_conf['exchange']['name'] = request.param
|
||||
exchange = ExchangeResolver.load_exchange(request.param, exchange_conf, validate=False)
|
||||
yield exchange, request.param
|
||||
|
||||
|
||||
class TestCCXTExchange():
|
||||
|
||||
def test_load_markets(self, exchange):
|
||||
exchange, exchangename = exchange
|
||||
pair = EXCHANGES[exchangename]['pair']
|
||||
markets = exchange.markets
|
||||
assert pair in markets
|
||||
assert isinstance(markets[pair], dict)
|
||||
|
||||
def test_ccxt_fetch_tickers(self, exchange):
|
||||
exchange, exchangename = exchange
|
||||
pair = EXCHANGES[exchangename]['pair']
|
||||
|
||||
tickers = exchange.get_tickers()
|
||||
assert pair in tickers
|
||||
assert 'ask' in tickers[pair]
|
||||
assert tickers[pair]['ask'] is not None
|
||||
assert 'bid' in tickers[pair]
|
||||
assert tickers[pair]['bid'] is not None
|
||||
assert 'quoteVolume' in tickers[pair]
|
||||
if EXCHANGES[exchangename].get('hasQuoteVolume'):
|
||||
assert tickers[pair]['quoteVolume'] is not None
|
||||
|
||||
def test_ccxt_fetch_ticker(self, exchange):
|
||||
exchange, exchangename = exchange
|
||||
pair = EXCHANGES[exchangename]['pair']
|
||||
|
||||
ticker = exchange.fetch_ticker(pair)
|
||||
assert 'ask' in ticker
|
||||
assert ticker['ask'] is not None
|
||||
assert 'bid' in ticker
|
||||
assert ticker['bid'] is not None
|
||||
assert 'quoteVolume' in ticker
|
||||
if EXCHANGES[exchangename].get('hasQuoteVolume'):
|
||||
assert ticker['quoteVolume'] is not None
|
||||
|
||||
def test_ccxt_fetch_l2_orderbook(self, exchange):
|
||||
exchange, exchangename = exchange
|
||||
l2 = exchange.fetch_l2_order_book('BTC/USDT')
|
||||
assert 'asks' in l2
|
||||
assert 'bids' in l2
|
||||
|
||||
for val in [1, 2, 5, 25, 100]:
|
||||
l2 = exchange.fetch_l2_order_book('BTC/USDT', val)
|
||||
if not exchange._ft_has['l2_limit_range'] or val in exchange._ft_has['l2_limit_range']:
|
||||
assert len(l2['asks']) == val
|
||||
assert len(l2['bids']) == val
|
||||
else:
|
||||
next_limit = exchange.get_next_limit_in_list(val, exchange._ft_has['l2_limit_range'])
|
||||
assert len(l2['asks']) == next_limit
|
||||
assert len(l2['asks']) == next_limit
|
||||
|
Loading…
Reference in New Issue
Block a user