Filled in test_load_leverage_tiers_okx

This commit is contained in:
Sam Germain
2022-02-14 16:53:29 -06:00
parent 5cd2501397
commit f4a57b71e7
4 changed files with 304 additions and 134 deletions

View File

@@ -1,6 +1,7 @@
from unittest.mock import MagicMock # , PropertyMock
from tests.conftest import get_patched_exchange
from freqtrade.enums import TradingMode, MarginMode
def test_get_maintenance_ratio_and_amt_okx(
@@ -169,133 +170,196 @@ def test_get_max_pair_stake_amount_okx(default_conf, mocker, leverage_tiers):
assert exchange.get_max_pair_stake_amount('TTT/USDT', 1.0) == float('inf') # Not in tiers
# def test_load_leverage_tiers_okx(default_conf, mocker):
# mocker.patch.multiple(
# 'freqtrade.exchange.okx',
# load_leverage_tiers=MagicMock(return_value={
# 'ETH/USDT:USDT': [
# {
# 'tier': 1,
# 'notionalFloor': 0,
# 'notionalCap': 2000,
# 'maintenanceMarginRatio': 0.01,
# 'maxLeverage': 75,
# 'info': {
# 'baseMaxLoan': '',
# 'imr': '0.013',
# 'instId': '',
# 'maxLever': '75',
# 'maxSz': '2000',
# 'minSz': '0',
# 'mmr': '0.01',
# 'optMgnFactor': '0',
# 'quoteMaxLoan': '',
# 'tier': '1',
# 'uly': 'ETH-USDT'
# }
# },
# {
# 'tier': 2,
# 'notionalFloor': 2001,
# 'notionalCap': 4000,
# 'maintenanceMarginRatio': 0.015,
# 'maxLeverage': 50,
# 'info': {
# 'baseMaxLoan': '',
# 'imr': '0.02',
# 'instId': '',
# 'maxLever': '50',
# 'maxSz': '4000',
# 'minSz': '2001',
# 'mmr': '0.015',
# 'optMgnFactor': '0',
# 'quoteMaxLoan': '',
# 'tier': '2',
# 'uly': 'ETH-USDT'
# }
# },
# {
# 'tier': 3,
# 'notionalFloor': 4001,
# 'notionalCap': 8000,
# 'maintenanceMarginRatio': 0.02,
# 'maxLeverage': 20,
# 'info': {
# 'baseMaxLoan': '',
# 'imr': '0.05',
# 'instId': '',
# 'maxLever': '20',
# 'maxSz': '8000',
# 'minSz': '4001',
# 'mmr': '0.02',
# 'optMgnFactor': '0',
# 'quoteMaxLoan': '',
# 'tier': '3',
# 'uly': 'ETH-USDT'
# }
# },
# ],
# 'ADA/USDT:USDT': [
# {
# 'tier': 1,
# 'notionalFloor': 0,
# 'notionalCap': 500,
# 'maintenanceMarginRatio': 0.02,
# 'maxLeverage': 75,
# 'info': {
# 'baseMaxLoan': '',
# 'imr': '0.013',
# 'instId': '',
# 'maxLever': '75',
# 'maxSz': '500',
# 'minSz': '0',
# 'mmr': '0.01',
# 'optMgnFactor': '0',
# 'quoteMaxLoan': '',
# 'tier': '1',
# 'uly': 'ADA-USDT'
# }
# },
# {
# 'tier': 2,
# 'notionalFloor': 501,
# 'notionalCap': 1000,
# 'maintenanceMarginRatio': 0.025,
# 'maxLeverage': 50,
# 'info': {
# 'baseMaxLoan': '',
# 'imr': '0.02',
# 'instId': '',
# 'maxLever': '50',
# 'maxSz': '1000',
# 'minSz': '501',
# 'mmr': '0.015',
# 'optMgnFactor': '0',
# 'quoteMaxLoan': '',
# 'tier': '2',
# 'uly': 'ADA-USDT'
# }
# },
# {
# 'tier': 3,
# 'notionalFloor': 1001,
# 'notionalCap': 2000,
# 'maintenanceMarginRatio': 0.03,
# 'maxLeverage': 20,
# 'info': {
# 'baseMaxLoan': '',
# 'imr': '0.05',
# 'instId': '',
# 'maxLever': '20',
# 'maxSz': '2000',
# 'minSz': '1001',
# 'mmr': '0.02',
# 'optMgnFactor': '0',
# 'quoteMaxLoan': '',
# 'tier': '3',
# 'uly': 'ADA-USDT'
# }
# },
# ]
# })
# )
def test_load_leverage_tiers_okx(default_conf, mocker, markets):
api_mock = MagicMock()
api_mock.fetch_leverage_tiers = MagicMock(side_effect=[
{
'ADA/USDT:USDT': [
{
'tier': 1,
'notionalFloor': 0,
'notionalCap': 500,
'maintenanceMarginRatio': 0.02,
'maxLeverage': 75,
'info': {
'baseMaxLoan': '',
'imr': '0.013',
'instId': '',
'maxLever': '75',
'maxSz': '500',
'minSz': '0',
'mmr': '0.01',
'optMgnFactor': '0',
'quoteMaxLoan': '',
'tier': '1',
'uly': 'ADA-USDT'
}
},
{
'tier': 2,
'notionalFloor': 501,
'notionalCap': 1000,
'maintenanceMarginRatio': 0.025,
'maxLeverage': 50,
'info': {
'baseMaxLoan': '',
'imr': '0.02',
'instId': '',
'maxLever': '50',
'maxSz': '1000',
'minSz': '501',
'mmr': '0.015',
'optMgnFactor': '0',
'quoteMaxLoan': '',
'tier': '2',
'uly': 'ADA-USDT'
}
},
{
'tier': 3,
'notionalFloor': 1001,
'notionalCap': 2000,
'maintenanceMarginRatio': 0.03,
'maxLeverage': 20,
'info': {
'baseMaxLoan': '',
'imr': '0.05',
'instId': '',
'maxLever': '20',
'maxSz': '2000',
'minSz': '1001',
'mmr': '0.02',
'optMgnFactor': '0',
'quoteMaxLoan': '',
'tier': '3',
'uly': 'ADA-USDT'
}
},
]
},
{
'ETH/USDT:USDT': [
{
'tier': 1,
'notionalFloor': 0,
'notionalCap': 2000,
'maintenanceMarginRatio': 0.01,
'maxLeverage': 75,
'info': {
'baseMaxLoan': '',
'imr': '0.013',
'instId': '',
'maxLever': '75',
'maxSz': '2000',
'minSz': '0',
'mmr': '0.01',
'optMgnFactor': '0',
'quoteMaxLoan': '',
'tier': '1',
'uly': 'ETH-USDT'
}
},
{
'tier': 2,
'notionalFloor': 2001,
'notionalCap': 4000,
'maintenanceMarginRatio': 0.015,
'maxLeverage': 50,
'info': {
'baseMaxLoan': '',
'imr': '0.02',
'instId': '',
'maxLever': '50',
'maxSz': '4000',
'minSz': '2001',
'mmr': '0.015',
'optMgnFactor': '0',
'quoteMaxLoan': '',
'tier': '2',
'uly': 'ETH-USDT'
}
},
{
'tier': 3,
'notionalFloor': 4001,
'notionalCap': 8000,
'maintenanceMarginRatio': 0.02,
'maxLeverage': 20,
'info': {
'baseMaxLoan': '',
'imr': '0.05',
'instId': '',
'maxLever': '20',
'maxSz': '8000',
'minSz': '4001',
'mmr': '0.02',
'optMgnFactor': '0',
'quoteMaxLoan': '',
'tier': '3',
'uly': 'ETH-USDT'
}
},
]
},
])
default_conf['trading_mode'] = 'futures'
default_conf['margin_mode'] = 'isolated'
default_conf['stake_currency'] = 'USDT'
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="okx")
exchange.trading_mode = TradingMode.FUTURES
exchange.margin_mode = MarginMode.ISOLATED
exchange.markets = markets
assert exchange.load_leverage_tiers() == {
'ADA/USDT:USDT': [
{
'tier': 1,
'min': 0,
'max': 500,
'mmr': 0.02,
'lev': 75,
'maintAmt': None
},
{
'tier': 2,
'min': 501,
'max': 1000,
'mmr': 0.025,
'lev': 50,
'maintAmt': None
},
{
'tier': 3,
'min': 1001,
'max': 2000,
'mmr': 0.03,
'lev': 20,
'maintAmt': None
},
],
'ETH/USDT:USDT': [
{
'tier': 1,
'min': 0,
'max': 2000,
'mmr': 0.01,
'lev': 75,
'maintAmt': None
},
{
'tier': 2,
'min': 2001,
'max': 4000,
'mmr': 0.015,
'lev': 50,
'maintAmt': None
},
{
'tier': 3,
'min': 4001,
'max': 8000,
'mmr': 0.02,
'lev': 20,
'maintAmt': None
},
],
}