Improve futures detection, add ccxt-compat test
This commit is contained in:
@@ -778,6 +778,7 @@ def get_markets():
|
||||
'quote': 'USDT',
|
||||
'spot': True,
|
||||
'future': True,
|
||||
'swap': True,
|
||||
'margin': True,
|
||||
'type': 'spot',
|
||||
'precision': {
|
||||
@@ -805,6 +806,7 @@ def get_markets():
|
||||
'active': False,
|
||||
'spot': True,
|
||||
'future': True,
|
||||
'swap': True,
|
||||
'margin': True,
|
||||
'type': 'spot',
|
||||
'precision': {
|
||||
|
@@ -26,6 +26,7 @@ EXCHANGES = {
|
||||
'pair': 'BTC/USDT',
|
||||
'hasQuoteVolume': True,
|
||||
'timeframe': '5m',
|
||||
'futures': True,
|
||||
},
|
||||
'kraken': {
|
||||
'pair': 'BTC/USDT',
|
||||
@@ -82,13 +83,19 @@ def exchange(request, exchange_conf):
|
||||
|
||||
|
||||
@pytest.fixture(params=EXCHANGES, scope="class")
|
||||
def exchange_futures(request, exchange_conf):
|
||||
def exchange_futures(request, exchange_conf, class_mocker):
|
||||
if not EXCHANGES[request.param].get('futures') is True:
|
||||
yield None, request.param
|
||||
else:
|
||||
exchange_conf['exchange']['name'] = request.param
|
||||
exchange_conf['trading_mode'] = 'futures'
|
||||
exchange_conf['collateral'] = 'cross'
|
||||
# TODO-lev This mock should no longer be necessary once futures are enabled.
|
||||
class_mocker.patch(
|
||||
'freqtrade.exchange.exchange.Exchange.validate_trading_mode_and_collateral')
|
||||
class_mocker.patch(
|
||||
'freqtrade.exchange.binance.Binance.fill_leverage_brackets')
|
||||
|
||||
exchange = ExchangeResolver.load_exchange(request.param, exchange_conf, validate=True)
|
||||
|
||||
yield exchange, request.param
|
||||
@@ -103,6 +110,20 @@ class TestCCXTExchange():
|
||||
markets = exchange.markets
|
||||
assert pair in markets
|
||||
assert isinstance(markets[pair], dict)
|
||||
assert exchange.market_is_spot(markets[pair])
|
||||
|
||||
def test_load_markets_futures(self, exchange_futures):
|
||||
exchange, exchangename = exchange_futures
|
||||
if not exchange:
|
||||
# exchange_futures only returns values for supported exchanges
|
||||
return
|
||||
pair = EXCHANGES[exchangename]['pair']
|
||||
pair = EXCHANGES[exchangename].get('futures_pair', pair)
|
||||
markets = exchange.markets
|
||||
assert pair in markets
|
||||
assert isinstance(markets[pair], dict)
|
||||
|
||||
assert exchange.market_is_future(markets[pair])
|
||||
|
||||
def test_ccxt_fetch_tickers(self, exchange):
|
||||
exchange, exchangename = exchange
|
||||
|
@@ -2985,6 +2985,10 @@ def test_timeframe_to_next_date():
|
||||
("BTC-PERP", 'BTC', 'USD', "ftx", False, False, True, 'spot', {}, False),
|
||||
("BTC-PERP", 'BTC', 'USD', "ftx", False, False, True, 'margin', {}, False),
|
||||
("BTC-PERP", 'BTC', 'USD', "ftx", False, False, True, 'futures', {}, True),
|
||||
|
||||
("BTC/USDT:USDT", 'BTC', 'USD', "okex", False, False, True, 'spot', {}, False),
|
||||
("BTC/USDT:USDT", 'BTC', 'USD', "okex", False, False, True, 'margin', {}, False),
|
||||
("BTC/USDT:USDT", 'BTC', 'USD', "okex", False, False, True, 'futures', {}, True),
|
||||
])
|
||||
def test_market_is_tradable(
|
||||
mocker, default_conf, market_symbol, base,
|
||||
@@ -2999,6 +3003,7 @@ def test_market_is_tradable(
|
||||
'quote': quote,
|
||||
'spot': spot,
|
||||
'future': futures,
|
||||
'swap': futures,
|
||||
'margin': margin,
|
||||
**(add_dict),
|
||||
}
|
||||
|
Reference in New Issue
Block a user