Add tests for margin mode
This commit is contained in:
parent
0dd9a277d3
commit
bfe3760f68
@ -2946,33 +2946,58 @@ def test_timeframe_to_next_date():
|
|||||||
assert timeframe_to_next_date("5m", date) == date + timedelta(minutes=5)
|
assert timeframe_to_next_date("5m", date) == date + timedelta(minutes=5)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("market_symbol,base,quote,exchange,spot,futures,add_dict,expected_result", [
|
@pytest.mark.parametrize(
|
||||||
("BTC/USDT", 'BTC', 'USDT', "binance", True, False, {}, True),
|
"market_symbol,base,quote,exchange,spot,margin,futures,trademode,add_dict,expected_result",
|
||||||
("USDT/BTC", 'USDT', 'BTC', "binance", True, False, {}, True),
|
[
|
||||||
("BTCUSDT", 'BTC', 'USDT', "binance", True, False, {}, True), # No seperating /
|
("BTC/USDT", 'BTC', 'USDT', "binance", True, False, False, 'spot', {}, True),
|
||||||
("BTCUSDT", None, "USDT", "binance", True, False, {}, False), #
|
("USDT/BTC", 'USDT', 'BTC', "binance", True, False, False, 'spot', {}, True),
|
||||||
("USDT/BTC", "BTC", None, "binance", True, False, {}, False),
|
# No seperating /
|
||||||
("BTCUSDT", "BTC", None, "binance", True, False, {}, False),
|
("BTCUSDT", 'BTC', 'USDT', "binance", True, False, False, 'spot', {}, True),
|
||||||
("BTC/USDT", "BTC", "USDT", "binance", True, False, {}, True),
|
("BTCUSDT", None, "USDT", "binance", True, False, False, 'spot', {}, False),
|
||||||
("BTC/UNK", "BTC", 'UNK', "binance", False, True, {}, False), # Futures market
|
("USDT/BTC", "BTC", None, "binance", True, False, False, 'spot', {}, False),
|
||||||
("BTC/EUR", 'BTC', 'EUR', "kraken", True, False, {"darkpool": False}, True),
|
("BTCUSDT", "BTC", None, "binance", True, False, False, 'spot', {}, False),
|
||||||
("EUR/BTC", 'EUR', 'BTC', "kraken", True, False, {"darkpool": False}, True),
|
("BTC/USDT", "BTC", "USDT", "binance", True, False, False, 'spot', {}, True),
|
||||||
("BTC/EUR", 'BTC', 'EUR', "kraken", True, False, {"darkpool": True}, False), # no darkpools
|
# Futures mode, spot pair
|
||||||
("BTC/EUR.d", 'BTC', 'EUR', "kraken", True, False, {"darkpool": True}, False), # no darkpools
|
("BTC/USDT", "BTC", "USDT", "binance", True, False, False, 'futures', {}, False),
|
||||||
("BTC/USD", 'BTC', 'USD', "ftx", True, False, {'spot': True}, True),
|
("BTC/USDT", "BTC", "USDT", "binance", True, False, False, 'margin', {}, False),
|
||||||
("USD/BTC", 'USD', 'BTC', "ftx", True, False, {'spot': True}, True),
|
("BTC/USDT", "BTC", "USDT", "binance", True, True, True, 'margin', {}, True),
|
||||||
("BTC/USD", 'BTC', 'USD', "ftx", False, True, {'spot': False}, False), # Can only trade spot markets
|
("BTC/USDT", "BTC", "USDT", "binance", False, True, False, 'margin', {}, True),
|
||||||
("BTC-PERP", 'BTC', 'USD', "ftx", False, True, {'spot': False}, False), # Can only trade spot markets
|
# Futures mode, futures pair
|
||||||
|
("BTC/USDT", "BTC", "USDT", "binance", False, False, True, 'futures', {}, True),
|
||||||
|
# Futures market
|
||||||
|
("BTC/UNK", "BTC", 'UNK', "binance", False, False, True, 'spot', {}, False),
|
||||||
|
("BTC/EUR", 'BTC', 'EUR', "kraken", True, False, False, 'spot', {"darkpool": False}, True),
|
||||||
|
("EUR/BTC", 'EUR', 'BTC', "kraken", True, False, False, 'spot', {"darkpool": False}, True),
|
||||||
|
# no darkpools
|
||||||
|
("BTC/EUR", 'BTC', 'EUR', "kraken", True, False, False, 'spot',
|
||||||
|
{"darkpool": True}, False),
|
||||||
|
# no darkpools
|
||||||
|
("BTC/EUR.d", 'BTC', 'EUR', "kraken", True, False, False, 'spot',
|
||||||
|
{"darkpool": True}, False),
|
||||||
|
("BTC/USD", 'BTC', 'USD', "ftx", True, False, False, 'spot', {}, True),
|
||||||
|
("USD/BTC", 'USD', 'BTC', "ftx", True, False, False, 'spot', {}, True),
|
||||||
|
# Can only trade spot markets
|
||||||
|
("BTC/USD", 'BTC', 'USD', "ftx", False, False, True, 'spot', {}, False),
|
||||||
|
("BTC/USD", 'BTC', 'USD', "ftx", False, False, True, 'futures', {}, True),
|
||||||
|
# Can only trade spot markets
|
||||||
|
("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),
|
||||||
])
|
])
|
||||||
def test_market_is_tradable(mocker, default_conf, market_symbol, base,
|
def test_market_is_tradable(
|
||||||
quote, spot, futures, add_dict, exchange, expected_result) -> None:
|
mocker, default_conf, market_symbol, base,
|
||||||
|
quote, spot, margin, futures, trademode, add_dict, exchange, expected_result
|
||||||
|
) -> None:
|
||||||
|
default_conf['trading_mode'] = trademode
|
||||||
|
mocker.patch('freqtrade.exchange.exchange.Exchange.validate_trading_mode_and_collateral')
|
||||||
ex = get_patched_exchange(mocker, default_conf, id=exchange)
|
ex = get_patched_exchange(mocker, default_conf, id=exchange)
|
||||||
market = {
|
market = {
|
||||||
'symbol': market_symbol,
|
'symbol': market_symbol,
|
||||||
'base': base,
|
'base': base,
|
||||||
'quote': quote,
|
'quote': quote,
|
||||||
'spot': spot,
|
'spot': spot,
|
||||||
'futures': futures,
|
'future': futures,
|
||||||
|
'margin': margin,
|
||||||
**(add_dict),
|
**(add_dict),
|
||||||
}
|
}
|
||||||
assert ex.market_is_tradable(market) == expected_result
|
assert ex.market_is_tradable(market) == expected_result
|
||||||
|
Loading…
Reference in New Issue
Block a user