From a1e9e940dd8ded65a0d8a7ab5f0f7350af9b0e6a Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 16 Feb 2022 08:48:53 -0600 Subject: [PATCH 1/4] test_ccxt_load_leverage_tiers --- tests/exchange/test_ccxt_compat.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/exchange/test_ccxt_compat.py b/tests/exchange/test_ccxt_compat.py index bae74c948..53f00944f 100644 --- a/tests/exchange/test_ccxt_compat.py +++ b/tests/exchange/test_ccxt_compat.py @@ -359,19 +359,24 @@ class TestCCXTExchange(): assert futures_pair in leverage_tiers pair_tiers = leverage_tiers[futures_pair] assert len(pair_tiers) > 0 - oldLeverage = 0 - oldMaintenanceMarginRate = oldNotionalFloor = oldNotionalCap = float('inf') + oldLeverage = float('inf') + oldMaintenanceMarginRate = oldNotionalFloor = oldNotionalCap = -1 for tier in pair_tiers: - for key in ['maintenanceMarginRate', 'notionalFloor', 'notionalCap', 'maxLeverage']: + for key in [ + 'maintenanceMarginRatio', # TODO-lev: Change to maintenanceMarginRate + 'notionalFloor', + 'notionalCap', + 'maxLeverage' + ]: assert key in tier - assert pair_tiers[key] > 0.0 - assert pair_tiers['notionalCap'] > pair_tiers['notionalFloor'] - assert tier['maxLeverage'] < oldLeverage - assert tier['maintenanceMarginRate'] > oldMaintenanceMarginRate + assert tier[key] >= 0.0 + assert tier['notionalCap'] > tier['notionalFloor'] + assert tier['maxLeverage'] <= oldLeverage + assert tier['maintenanceMarginRatio'] >= oldMaintenanceMarginRate assert tier['notionalFloor'] > oldNotionalFloor assert tier['notionalCap'] > oldNotionalCap oldLeverage = tier['maxLeverage'] - oldMaintenanceMarginRate = tier['maintenanceMarginRate'] + oldMaintenanceMarginRate = tier['maintenanceMarginRatio'] oldNotionalFloor = tier['notionalFloor'] oldNotionalCap = tier['notionalCap'] From dc73fccd3c30cb2ee9ce2c6c4ac6794a1eaae62b Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 16 Feb 2022 09:03:50 -0600 Subject: [PATCH 2/4] removed test_ccxt_get_maintenance_ratio_and_amt --- tests/exchange/test_ccxt_compat.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/exchange/test_ccxt_compat.py b/tests/exchange/test_ccxt_compat.py index 53f00944f..992396388 100644 --- a/tests/exchange/test_ccxt_compat.py +++ b/tests/exchange/test_ccxt_compat.py @@ -134,7 +134,6 @@ def exchange_futures(request, exchange_conf, class_mocker): yield exchange, request.param -@pytest.mark.longrun class TestCCXTExchange(): def test_load_markets(self, exchange): @@ -380,14 +379,19 @@ class TestCCXTExchange(): oldNotionalFloor = tier['notionalFloor'] oldNotionalCap = tier['notionalCap'] - # def test_ccxt_get_liquidation_price(): - # return # TODO-lev + def test_ccxt_get_liquidation_price(): + return # TODO-lev - # def test_ccxt_liquidation_price(): - # return # TODO-lev + def test_ccxt_liquidation_price(): + return # TODO-lev - # def test_ccxt_get_max_pair_stake_amount(): - # return # TODO-lev - - # def test_ccxt_get_maintenance_ratio_and_amt(): - # return # TODO-lev + def test_ccxt_get_max_pair_stake_amount(self, exchange_futures): + futures, futures_name = exchange_futures + if futures: + futures_pair = EXCHANGES[futures_name].get( + 'futures_pair', + EXCHANGES[futures_name]['pair'] + ) + max_stake_amount = futures.get_max_pair_stake_amount(futures_pair, 40000) + assert (isinstance(max_stake_amount, float)) + assert max_stake_amount >= 0.0 From df86300729de336cb057dcff25e635b80ba1e009 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 16 Feb 2022 09:20:22 -0600 Subject: [PATCH 3/4] test_ccxt_dry_run_liquidation_price --- tests/exchange/test_ccxt_compat.py | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/exchange/test_ccxt_compat.py b/tests/exchange/test_ccxt_compat.py index 992396388..968980af1 100644 --- a/tests/exchange/test_ccxt_compat.py +++ b/tests/exchange/test_ccxt_compat.py @@ -120,7 +120,7 @@ def exchange_futures(request, exchange_conf, class_mocker): exchange_conf = deepcopy(exchange_conf) exchange_conf['exchange']['name'] = request.param exchange_conf['trading_mode'] = 'futures' - exchange_conf['margin_mode'] = 'cross' + exchange_conf['margin_mode'] = 'isolated' exchange_conf['stake_currency'] = EXCHANGES[request.param]['stake_currency'] # TODO-lev: This mock should no longer be necessary once futures are enabled. @@ -134,6 +134,7 @@ def exchange_futures(request, exchange_conf, class_mocker): yield exchange, request.param +@pytest.mark.longrun class TestCCXTExchange(): def test_load_markets(self, exchange): @@ -379,11 +380,34 @@ class TestCCXTExchange(): oldNotionalFloor = tier['notionalFloor'] oldNotionalCap = tier['notionalCap'] - def test_ccxt_get_liquidation_price(): - return # TODO-lev + def test_ccxt_dry_run_liquidation_price(self, exchange_futures): + futures, futures_name = exchange_futures + if futures and EXCHANGES[futures_name]['leverage_tiers_public']: - def test_ccxt_liquidation_price(): - return # TODO-lev + futures_pair = EXCHANGES[futures_name].get( + 'futures_pair', + EXCHANGES[futures_name]['pair'] + ) + + liquidation_price = futures.dry_run_liquidation_price( + futures_pair, + 40000, + False, + 100, + 100, + ) + assert (isinstance(liquidation_price, float)) + assert liquidation_price >= 0.0 + + liquidation_price = futures.dry_run_liquidation_price( + futures_pair, + 40000, + False, + 100, + 100, + ) + assert (isinstance(liquidation_price, float)) + assert liquidation_price >= 0.0 def test_ccxt_get_max_pair_stake_amount(self, exchange_futures): futures, futures_name = exchange_futures From 2015e9345d9b7a0fd227cbec881bf7c4eeade103 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 16 Feb 2022 09:25:08 -0600 Subject: [PATCH 4/4] test_ccxt_compat maintenanceMarginRatio -> maintenanceMarginRate --- tests/exchange/test_ccxt_compat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/exchange/test_ccxt_compat.py b/tests/exchange/test_ccxt_compat.py index 968980af1..6bf555867 100644 --- a/tests/exchange/test_ccxt_compat.py +++ b/tests/exchange/test_ccxt_compat.py @@ -363,7 +363,7 @@ class TestCCXTExchange(): oldMaintenanceMarginRate = oldNotionalFloor = oldNotionalCap = -1 for tier in pair_tiers: for key in [ - 'maintenanceMarginRatio', # TODO-lev: Change to maintenanceMarginRate + 'maintenanceMarginRate', 'notionalFloor', 'notionalCap', 'maxLeverage' @@ -372,11 +372,11 @@ class TestCCXTExchange(): assert tier[key] >= 0.0 assert tier['notionalCap'] > tier['notionalFloor'] assert tier['maxLeverage'] <= oldLeverage - assert tier['maintenanceMarginRatio'] >= oldMaintenanceMarginRate + assert tier['maintenanceMarginRate'] >= oldMaintenanceMarginRate assert tier['notionalFloor'] > oldNotionalFloor assert tier['notionalCap'] > oldNotionalCap oldLeverage = tier['maxLeverage'] - oldMaintenanceMarginRate = tier['maintenanceMarginRatio'] + oldMaintenanceMarginRate = tier['maintenanceMarginRate'] oldNotionalFloor = tier['notionalFloor'] oldNotionalCap = tier['notionalCap']