test_get_liquidation_price/test_get_maintenance_ratio_and_amt_binance/fill_leverage_brackets/test_validate_trading_mode_and_collateral TODO comments
This commit is contained in:
@@ -397,9 +397,9 @@ def test__ccxt_config(default_conf, mocker, trading_mode, collateral, config):
|
||||
("BNB/BUSD", 0.0, 0.025, 0),
|
||||
("BNB/USDT", 100.0, 0.0065, 0),
|
||||
("BTC/USDT", 170.30, 0.004, 0),
|
||||
("BNB/BUSD", 999999.9, 0.1, 0),
|
||||
("BNB/USDT", 5000000.0, 0.5, 0),
|
||||
("BTC/USDT", 300000000.1, 0.5, 0),
|
||||
("BNB/BUSD", 999999.9, 0.1, 27500.0),
|
||||
("BNB/USDT", 5000000.0, 0.15, 233034.99999999994),
|
||||
("BTC/USDT", 300000000.1, 0.5, 99891300.0),
|
||||
])
|
||||
def test_get_maintenance_ratio_and_amt_binance(
|
||||
default_conf,
|
||||
@@ -411,29 +411,30 @@ def test_get_maintenance_ratio_and_amt_binance(
|
||||
):
|
||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||
exchange._leverage_brackets = {
|
||||
'BNB/BUSD': [[0.0, 0.025],
|
||||
[100000.0, 0.05],
|
||||
[500000.0, 0.1],
|
||||
[1000000.0, 0.15],
|
||||
[2000000.0, 0.25],
|
||||
[5000000.0, 0.5]],
|
||||
'BNB/USDT': [[0.0, 0.0065],
|
||||
[10000.0, 0.01],
|
||||
[50000.0, 0.02],
|
||||
[250000.0, 0.05],
|
||||
[1000000.0, 0.1],
|
||||
[2000000.0, 0.125],
|
||||
[5000000.0, 0.15],
|
||||
[10000000.0, 0.25]],
|
||||
'BTC/USDT': [[0.0, 0.004],
|
||||
[50000.0, 0.005],
|
||||
[250000.0, 0.01],
|
||||
[1000000.0, 0.025],
|
||||
[5000000.0, 0.05],
|
||||
[20000000.0, 0.1],
|
||||
[50000000.0, 0.125],
|
||||
[100000000.0, 0.15],
|
||||
[200000000.0, 0.25],
|
||||
[300000000.0, 0.5]],
|
||||
'BNB/BUSD': [[0.0, 0.025, 0.0],
|
||||
[100000.0, 0.05, 2500.0],
|
||||
[500000.0, 0.1, 27500.0],
|
||||
[1000000.0, 0.15, 77499.99999999999],
|
||||
[2000000.0, 0.25, 277500.0],
|
||||
[5000000.0, 0.5, 1527500.0]],
|
||||
'BNB/USDT': [[0.0, 0.0065, 0.0],
|
||||
[10000.0, 0.01, 35.00000000000001],
|
||||
[50000.0, 0.02, 535.0],
|
||||
[250000.0, 0.05, 8035.000000000001],
|
||||
[1000000.0, 0.1, 58035.0],
|
||||
[2000000.0, 0.125, 108034.99999999999],
|
||||
[5000000.0, 0.15, 233034.99999999994],
|
||||
[10000000.0, 0.25, 1233035.0]],
|
||||
'BTC/USDT': [[0.0, 0.004, 0.0],
|
||||
[50000.0, 0.005, 50.0],
|
||||
[250000.0, 0.01, 1300.0],
|
||||
[1000000.0, 0.025, 16300.000000000002],
|
||||
[5000000.0, 0.05, 141300.0],
|
||||
[20000000.0, 0.1, 1141300.0],
|
||||
[50000000.0, 0.125, 2391300.0],
|
||||
[100000000.0, 0.15, 4891300.0],
|
||||
[200000000.0, 0.25, 24891300.0],
|
||||
[300000000.0, 0.5, 99891300.0]
|
||||
]
|
||||
}
|
||||
assert exchange.get_maintenance_ratio_and_amt(pair, nominal_value) == (mm_ratio, amt)
|
||||
|
@@ -3438,8 +3438,18 @@ def test_set_margin_mode(mocker, default_conf, collateral):
|
||||
("bittrex", TradingMode.FUTURES, Collateral.CROSS, True),
|
||||
("bittrex", TradingMode.FUTURES, Collateral.ISOLATED, True),
|
||||
("gateio", TradingMode.MARGIN, Collateral.ISOLATED, True),
|
||||
("okex", TradingMode.SPOT, None, False),
|
||||
("okex", TradingMode.MARGIN, Collateral.CROSS, True),
|
||||
("okex", TradingMode.MARGIN, Collateral.ISOLATED, True),
|
||||
("okex", TradingMode.FUTURES, Collateral.CROSS, True),
|
||||
|
||||
# TODO-lev: Remove once implemented
|
||||
("binance", TradingMode.FUTURES, Collateral.ISOLATED, False),
|
||||
("gateio", TradingMode.FUTURES, Collateral.ISOLATED, False),
|
||||
|
||||
# ("okex", TradingMode.FUTURES, Collateral.ISOLATED, False), # TODO-lev: uncomment once impleme
|
||||
("okex", TradingMode.FUTURES, Collateral.ISOLATED, True), # TODO-lev: remove once implemented
|
||||
|
||||
# * Remove once implemented
|
||||
("binance", TradingMode.MARGIN, Collateral.CROSS, True),
|
||||
("binance", TradingMode.FUTURES, Collateral.CROSS, True),
|
||||
("kraken", TradingMode.MARGIN, Collateral.CROSS, True),
|
||||
@@ -3449,17 +3459,15 @@ def test_set_margin_mode(mocker, default_conf, collateral):
|
||||
("gateio", TradingMode.MARGIN, Collateral.CROSS, True),
|
||||
("gateio", TradingMode.FUTURES, Collateral.CROSS, True),
|
||||
|
||||
# TODO-lev: Uncomment once implemented
|
||||
# * Uncomment once implemented
|
||||
# ("binance", TradingMode.MARGIN, Collateral.CROSS, False),
|
||||
# ("binance", TradingMode.FUTURES, Collateral.CROSS, False),
|
||||
("binance", TradingMode.FUTURES, Collateral.ISOLATED, False),
|
||||
# ("kraken", TradingMode.MARGIN, Collateral.CROSS, False),
|
||||
# ("kraken", TradingMode.FUTURES, Collateral.CROSS, False),
|
||||
# ("ftx", TradingMode.MARGIN, Collateral.CROSS, False),
|
||||
# ("ftx", TradingMode.FUTURES, Collateral.CROSS, False),
|
||||
# ("gateio", TradingMode.MARGIN, Collateral.CROSS, False),
|
||||
# ("gateio", TradingMode.FUTURES, Collateral.CROSS, False),
|
||||
("gateio", TradingMode.FUTURES, Collateral.ISOLATED, False),
|
||||
])
|
||||
def test_validate_trading_mode_and_collateral(
|
||||
default_conf,
|
||||
@@ -3583,36 +3591,39 @@ def test_calculate_funding_fees(
|
||||
def test_get_liquidation_price(mocker, default_conf):
|
||||
|
||||
api_mock = MagicMock()
|
||||
api_mock.fetch_positions = MagicMock(return_value=[{
|
||||
'info': {},
|
||||
'symbol': 'NEAR/USDT:USDT',
|
||||
'timestamp': 1642164737148,
|
||||
'datetime': '2022-01-14T12:52:17.148Z',
|
||||
'initialMargin': 1.51072,
|
||||
'initialMarginPercentage': 0.1,
|
||||
'maintenanceMargin': 0.38916147,
|
||||
'maintenanceMarginPercentage': 0.025,
|
||||
'entryPrice': 18.884,
|
||||
'notional': 15.1072,
|
||||
'leverage': 9.97,
|
||||
'unrealizedPnl': 0.0048,
|
||||
'contracts': 8,
|
||||
'contractSize': 0.1,
|
||||
'marginRatio': None,
|
||||
'liquidationPrice': 17.47,
|
||||
'markPrice': 18.89,
|
||||
'collateral': 1.52549075,
|
||||
'marginType': 'isolated',
|
||||
'side': 'buy',
|
||||
'percentage': 0.003177292946409658
|
||||
}])
|
||||
positions = [
|
||||
{
|
||||
'info': {},
|
||||
'symbol': 'NEAR/USDT:USDT',
|
||||
'timestamp': 1642164737148,
|
||||
'datetime': '2022-01-14T12:52:17.148Z',
|
||||
'initialMargin': 1.51072,
|
||||
'initialMarginPercentage': 0.1,
|
||||
'maintenanceMargin': 0.38916147,
|
||||
'maintenanceMarginPercentage': 0.025,
|
||||
'entryPrice': 18.884,
|
||||
'notional': 15.1072,
|
||||
'leverage': 9.97,
|
||||
'unrealizedPnl': 0.0048,
|
||||
'contracts': 8,
|
||||
'contractSize': 0.1,
|
||||
'marginRatio': None,
|
||||
'liquidationPrice': 17.47,
|
||||
'markPrice': 18.89,
|
||||
'collateral': 1.52549075,
|
||||
'marginType': 'isolated',
|
||||
'side': 'buy',
|
||||
'percentage': 0.003177292946409658
|
||||
}
|
||||
]
|
||||
api_mock.fetch_positions = MagicMock(return_value=positions)
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
exchange_has=MagicMock(return_value=True),
|
||||
)
|
||||
default_conf['dry_run'] = False
|
||||
|
||||
exchange = get_patched_exchange(mocker, default_conf)
|
||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||
liq_price = exchange.get_liquidation_price('NEAR/USDT:USDT')
|
||||
assert liq_price == 17.47
|
||||
|
||||
|
Reference in New Issue
Block a user