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

@ -347,7 +347,10 @@ class Exchange:
return self.markets.get(pair, {}).get('base', '') return self.markets.get(pair, {}).get('base', '')
def market_is_future(self, market: Dict[str, Any]) -> bool: def market_is_future(self, market: Dict[str, Any]) -> bool:
return market.get(self._ft_has["ccxt_futures_name"], False) is True return (
market.get(self._ft_has["ccxt_futures_name"], False) is True and
market.get('linear', False) is True
)
def market_is_spot(self, market: Dict[str, Any]) -> bool: def market_is_spot(self, market: Dict[str, Any]) -> bool:
return market.get('spot', False) is True return market.get('spot', False) is True

View File

@ -77,7 +77,8 @@ class Okx(Exchange):
tiers = {} tiers = {}
for symbol in symbols: for symbol in symbols:
res = self._api.fetchLeverageTiers(symbol) res = self._api.fetchLeverageTiers(symbol)
tiers[symbol] = res[symbol] res_symbol = res[symbol]
tiers[symbol] = self.parse_leverage_tier(res[symbol])
return tiers return tiers
else: else:

View File

@ -891,7 +891,8 @@ def get_markets():
'future': True, 'future': True,
'swap': True, 'swap': True,
'margin': True, 'margin': True,
'linear': True, 'linear': False,
'inverse': True,
'type': 'spot', 'type': 'spot',
'contractSize': None, 'contractSize': None,
'taker': 0.0006, 'taker': 0.0006,
@ -1286,7 +1287,108 @@ def get_markets():
'strike': None, 'strike': None,
'optionType': None, 'optionType': None,
'info': {} 'info': {}
},
'SOL/BUSD:BUSD': {
'limits': {
'leverage': {'min': None, 'max': None},
'amount': {'min': 1, 'max': 1000000},
'price': {'min': 0.04, 'max': 100000},
'cost': {'min': 5, 'max': None},
'market': {'min': 1, 'max': 1500}
},
'precision': {'amount': 0, 'price': 2, 'base': 8, 'quote': 8},
'tierBased': False,
'percentage': True,
'taker': 0.0004,
'maker': 0.0002,
'feeSide': 'get',
'id': 'SOLBUSD',
'lowercaseId': 'solbusd',
'symbol': 'SOL/BUSD',
'base': 'SOL',
'quote': 'BUSD',
'settle': 'BUSD',
'baseId': 'SOL',
'quoteId': 'BUSD',
'settleId': 'BUSD',
'type': 'future',
'spot': False,
'margin': False,
'future': True,
'delivery': False,
'option': False,
'active': True,
'contract': True,
'linear': True,
'inverse': False,
'contractSize': 1,
'expiry': None,
'expiryDatetime': None,
'strike': None,
'optionType': None,
'info': {
'symbol': 'SOLBUSD',
'pair': 'SOLBUSD',
'contractType': 'PERPETUAL',
'deliveryDate': '4133404800000',
'onboardDate': '1630566000000',
'status': 'TRADING',
'maintMarginPercent': '2.5000',
'requiredMarginPercent': '5.0000',
'baseAsset': 'SOL',
'quoteAsset': 'BUSD',
'marginAsset': 'BUSD',
'pricePrecision': '4',
'quantityPrecision': '0',
'baseAssetPrecision': '8',
'quotePrecision': '8',
'underlyingType': 'COIN',
'underlyingSubType': [],
'settlePlan': '0',
'triggerProtect': '0.0500',
'liquidationFee': '0.005000',
'marketTakeBound': '0.05',
'filters': [
{
'minPrice': '0.0400',
'maxPrice': '100000',
'filterType': 'PRICE_FILTER',
'tickSize': '0.0100'
},
{
'stepSize': '1',
'filterType': 'LOT_SIZE',
'maxQty': '1000000',
'minQty': '1'
},
{
'stepSize': '1',
'filterType': 'MARKET_LOT_SIZE',
'maxQty': '1500',
'minQty': '1'
},
{'limit': '200', 'filterType': 'MAX_NUM_ORDERS'},
{'limit': '10', 'filterType': 'MAX_NUM_ALGO_ORDERS'},
{'notional': '5', 'filterType': 'MIN_NOTIONAL'},
{
'multiplierDown': '0.9500',
'multiplierUp': '1.0500',
'multiplierDecimal': '4',
'filterType': 'PERCENT_PRICE'
} }
],
'orderTypes': [
'LIMIT',
'MARKET',
'STOP',
'STOP_MARKET',
'TAKE_PROFIT',
'TAKE_PROFIT_MARKET',
'TRAILING_STOP_MARKET'
],
'timeInForce': ['GTC', 'IOC', 'FOK', 'GTX']
}
},
} }

View File

@ -1,6 +1,7 @@
from unittest.mock import MagicMock # , PropertyMock from unittest.mock import MagicMock # , PropertyMock
from tests.conftest import get_patched_exchange from tests.conftest import get_patched_exchange
from freqtrade.enums import TradingMode, MarginMode
def test_get_maintenance_ratio_and_amt_okx( 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 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): def test_load_leverage_tiers_okx(default_conf, mocker, markets):
# mocker.patch.multiple( api_mock = MagicMock()
# 'freqtrade.exchange.okx', api_mock.fetch_leverage_tiers = MagicMock(side_effect=[
# load_leverage_tiers=MagicMock(return_value={ {
# 'ETH/USDT:USDT': [ 'ADA/USDT:USDT': [
# { {
# 'tier': 1, 'tier': 1,
# 'notionalFloor': 0, 'notionalFloor': 0,
# 'notionalCap': 2000, 'notionalCap': 500,
# 'maintenanceMarginRatio': 0.01, 'maintenanceMarginRatio': 0.02,
# 'maxLeverage': 75, 'maxLeverage': 75,
# 'info': { 'info': {
# 'baseMaxLoan': '', 'baseMaxLoan': '',
# 'imr': '0.013', 'imr': '0.013',
# 'instId': '', 'instId': '',
# 'maxLever': '75', 'maxLever': '75',
# 'maxSz': '2000', 'maxSz': '500',
# 'minSz': '0', 'minSz': '0',
# 'mmr': '0.01', 'mmr': '0.01',
# 'optMgnFactor': '0', 'optMgnFactor': '0',
# 'quoteMaxLoan': '', 'quoteMaxLoan': '',
# 'tier': '1', 'tier': '1',
# 'uly': 'ETH-USDT' 'uly': 'ADA-USDT'
# } }
# }, },
# { {
# 'tier': 2, 'tier': 2,
# 'notionalFloor': 2001, 'notionalFloor': 501,
# 'notionalCap': 4000, 'notionalCap': 1000,
# 'maintenanceMarginRatio': 0.015, 'maintenanceMarginRatio': 0.025,
# 'maxLeverage': 50, 'maxLeverage': 50,
# 'info': { 'info': {
# 'baseMaxLoan': '', 'baseMaxLoan': '',
# 'imr': '0.02', 'imr': '0.02',
# 'instId': '', 'instId': '',
# 'maxLever': '50', 'maxLever': '50',
# 'maxSz': '4000', 'maxSz': '1000',
# 'minSz': '2001', 'minSz': '501',
# 'mmr': '0.015', 'mmr': '0.015',
# 'optMgnFactor': '0', 'optMgnFactor': '0',
# 'quoteMaxLoan': '', 'quoteMaxLoan': '',
# 'tier': '2', 'tier': '2',
# 'uly': 'ETH-USDT' 'uly': 'ADA-USDT'
# } }
# }, },
# { {
# 'tier': 3, 'tier': 3,
# 'notionalFloor': 4001, 'notionalFloor': 1001,
# 'notionalCap': 8000, 'notionalCap': 2000,
# 'maintenanceMarginRatio': 0.02, 'maintenanceMarginRatio': 0.03,
# 'maxLeverage': 20, 'maxLeverage': 20,
# 'info': { 'info': {
# 'baseMaxLoan': '', 'baseMaxLoan': '',
# 'imr': '0.05', 'imr': '0.05',
# 'instId': '', 'instId': '',
# 'maxLever': '20', 'maxLever': '20',
# 'maxSz': '8000', 'maxSz': '2000',
# 'minSz': '4001', 'minSz': '1001',
# 'mmr': '0.02', 'mmr': '0.02',
# 'optMgnFactor': '0', 'optMgnFactor': '0',
# 'quoteMaxLoan': '', 'quoteMaxLoan': '',
# 'tier': '3', 'tier': '3',
# 'uly': 'ETH-USDT' 'uly': 'ADA-USDT'
# } }
# }, },
# ], ]
# 'ADA/USDT:USDT': [ },
# { {
# 'tier': 1, 'ETH/USDT:USDT': [
# 'notionalFloor': 0, {
# 'notionalCap': 500, 'tier': 1,
# 'maintenanceMarginRatio': 0.02, 'notionalFloor': 0,
# 'maxLeverage': 75, 'notionalCap': 2000,
# 'info': { 'maintenanceMarginRatio': 0.01,
# 'baseMaxLoan': '', 'maxLeverage': 75,
# 'imr': '0.013', 'info': {
# 'instId': '', 'baseMaxLoan': '',
# 'maxLever': '75', 'imr': '0.013',
# 'maxSz': '500', 'instId': '',
# 'minSz': '0', 'maxLever': '75',
# 'mmr': '0.01', 'maxSz': '2000',
# 'optMgnFactor': '0', 'minSz': '0',
# 'quoteMaxLoan': '', 'mmr': '0.01',
# 'tier': '1', 'optMgnFactor': '0',
# 'uly': 'ADA-USDT' 'quoteMaxLoan': '',
# } 'tier': '1',
# }, 'uly': 'ETH-USDT'
# { }
# 'tier': 2, },
# 'notionalFloor': 501, {
# 'notionalCap': 1000, 'tier': 2,
# 'maintenanceMarginRatio': 0.025, 'notionalFloor': 2001,
# 'maxLeverage': 50, 'notionalCap': 4000,
# 'info': { 'maintenanceMarginRatio': 0.015,
# 'baseMaxLoan': '', 'maxLeverage': 50,
# 'imr': '0.02', 'info': {
# 'instId': '', 'baseMaxLoan': '',
# 'maxLever': '50', 'imr': '0.02',
# 'maxSz': '1000', 'instId': '',
# 'minSz': '501', 'maxLever': '50',
# 'mmr': '0.015', 'maxSz': '4000',
# 'optMgnFactor': '0', 'minSz': '2001',
# 'quoteMaxLoan': '', 'mmr': '0.015',
# 'tier': '2', 'optMgnFactor': '0',
# 'uly': 'ADA-USDT' 'quoteMaxLoan': '',
# } 'tier': '2',
# }, 'uly': 'ETH-USDT'
# { }
# 'tier': 3, },
# 'notionalFloor': 1001, {
# 'notionalCap': 2000, 'tier': 3,
# 'maintenanceMarginRatio': 0.03, 'notionalFloor': 4001,
# 'maxLeverage': 20, 'notionalCap': 8000,
# 'info': { 'maintenanceMarginRatio': 0.02,
# 'baseMaxLoan': '', 'maxLeverage': 20,
# 'imr': '0.05', 'info': {
# 'instId': '', 'baseMaxLoan': '',
# 'maxLever': '20', 'imr': '0.05',
# 'maxSz': '2000', 'instId': '',
# 'minSz': '1001', 'maxLever': '20',
# 'mmr': '0.02', 'maxSz': '8000',
# 'optMgnFactor': '0', 'minSz': '4001',
# 'quoteMaxLoan': '', 'mmr': '0.02',
# 'tier': '3', 'optMgnFactor': '0',
# 'uly': 'ADA-USDT' '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
},
],
}