fixed breaking tests for liquidation price
This commit is contained in:
parent
1eee5373b9
commit
2d545a2def
@ -139,12 +139,12 @@ class Binance(Exchange):
|
|||||||
[amt, old_ratio] = [None, None]
|
[amt, old_ratio] = [None, None]
|
||||||
brackets = []
|
brackets = []
|
||||||
for [notional_floor, mm_ratio] in brkts:
|
for [notional_floor, mm_ratio] in brkts:
|
||||||
amt = ((float(notional_floor) * (mm_ratio - old_ratio)) +
|
amt = ((float(notional_floor) * (float(mm_ratio) - float(old_ratio))) +
|
||||||
amt) if old_ratio else 0
|
amt) if old_ratio else 0
|
||||||
old_ratio = mm_ratio
|
old_ratio = mm_ratio
|
||||||
brackets.append([
|
brackets.append([
|
||||||
float(notional_floor),
|
float(notional_floor),
|
||||||
mm_ratio,
|
float(mm_ratio),
|
||||||
amt,
|
amt,
|
||||||
])
|
])
|
||||||
self._leverage_brackets[pair] = brackets
|
self._leverage_brackets[pair] = brackets
|
||||||
@ -231,8 +231,8 @@ class Binance(Exchange):
|
|||||||
|
|
||||||
def get_maintenance_ratio_and_amt(
|
def get_maintenance_ratio_and_amt(
|
||||||
self,
|
self,
|
||||||
pair: Optional[str],
|
pair: str,
|
||||||
nominal_value: Optional[float]
|
nominal_value: Optional[float] = 0.0,
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Maintenance amt = Floor of Position Bracket on Level n *
|
Maintenance amt = Floor of Position Bracket on Level n *
|
||||||
|
@ -2005,8 +2005,8 @@ class Exchange:
|
|||||||
|
|
||||||
def get_maintenance_ratio_and_amt(
|
def get_maintenance_ratio_and_amt(
|
||||||
self,
|
self,
|
||||||
pair: Optional[str],
|
pair: str,
|
||||||
nominal_value: Optional[float]
|
nominal_value: Optional[float] = 0.0,
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
:return: The maintenance amount, and maintenance margin rate
|
:return: The maintenance amount, and maintenance margin rate
|
||||||
|
@ -43,8 +43,8 @@ class Gateio(Exchange):
|
|||||||
|
|
||||||
def get_maintenance_ratio_and_amt(
|
def get_maintenance_ratio_and_amt(
|
||||||
self,
|
self,
|
||||||
pair: Optional[str],
|
pair: str,
|
||||||
nominal_value: Optional[float]
|
nominal_value: Optional[float] = 0.0,
|
||||||
):
|
):
|
||||||
info = self.markets[pair]['info']
|
info = self.markets[pair]['info']
|
||||||
if 'maintenance_rate' in info:
|
if 'maintenance_rate' in info:
|
||||||
|
@ -242,7 +242,7 @@ def test_fill_leverage_brackets_binance(default_conf, mocker):
|
|||||||
[500000.0, 0.1, 27500.0],
|
[500000.0, 0.1, 27500.0],
|
||||||
[1000000.0, 0.15, 77499.99999999999],
|
[1000000.0, 0.15, 77499.99999999999],
|
||||||
[2000000.0, 0.25, 277500.0],
|
[2000000.0, 0.25, 277500.0],
|
||||||
[5000000.0, 0.5, 1827500.0]],
|
[5000000.0, 0.5, 1527500.0]],
|
||||||
'BTC/USDT': [[0.0, 0.004, 0.0],
|
'BTC/USDT': [[0.0, 0.004, 0.0],
|
||||||
[50000.0, 0.005, 50.0],
|
[50000.0, 0.005, 50.0],
|
||||||
[250000.0, 0.01, 1300.0],
|
[250000.0, 0.01, 1300.0],
|
||||||
@ -284,37 +284,37 @@ def test_fill_leverage_brackets_binance_dryrun(default_conf, mocker):
|
|||||||
|
|
||||||
leverage_brackets = {
|
leverage_brackets = {
|
||||||
"1000SHIB/USDT": [
|
"1000SHIB/USDT": [
|
||||||
[0.0, 0.01],
|
[0.0, 0.01, 0.0],
|
||||||
[5000.0, 0.025],
|
[5000.0, 0.025, 75.0],
|
||||||
[25000.0, 0.05],
|
[25000.0, 0.05, 700.0],
|
||||||
[100000.0, 0.1],
|
[100000.0, 0.1, 5700.0],
|
||||||
[250000.0, 0.125],
|
[250000.0, 0.125, 11949.999999999998],
|
||||||
[1000000.0, 0.5]
|
[1000000.0, 0.5, 386950.0],
|
||||||
],
|
],
|
||||||
"1INCH/USDT": [
|
"1INCH/USDT": [
|
||||||
[0.0, 0.012],
|
[0.0, 0.012, 0.0],
|
||||||
[5000.0, 0.025],
|
[5000.0, 0.025, 65.0],
|
||||||
[25000.0, 0.05],
|
[25000.0, 0.05, 690.0],
|
||||||
[100000.0, 0.1],
|
[100000.0, 0.1, 5690.0],
|
||||||
[250000.0, 0.125],
|
[250000.0, 0.125, 11939.999999999998],
|
||||||
[1000000.0, 0.5]
|
[1000000.0, 0.5, 386940.0],
|
||||||
],
|
],
|
||||||
"AAVE/USDT": [
|
"AAVE/USDT": [
|
||||||
[0.0, 0.01],
|
[0.0, 0.01, 0.0],
|
||||||
[50000.0, 0.02],
|
[50000.0, 0.02, 500.0],
|
||||||
[250000.0, 0.05],
|
[250000.0, 0.05, 8000.000000000001],
|
||||||
[1000000.0, 0.1],
|
[1000000.0, 0.1, 58000.0],
|
||||||
[2000000.0, 0.125],
|
[2000000.0, 0.125, 107999.99999999999],
|
||||||
[5000000.0, 0.1665],
|
[5000000.0, 0.1665, 315500.00000000006],
|
||||||
[10000000.0, 0.25]
|
[10000000.0, 0.25, 1150500.0],
|
||||||
],
|
],
|
||||||
"ADA/BUSD": [
|
"ADA/BUSD": [
|
||||||
[0.0, 0.025],
|
[0.0, 0.025, 0.0],
|
||||||
[100000.0, 0.05],
|
[100000.0, 0.05, 2500.0],
|
||||||
[500000.0, 0.1],
|
[500000.0, 0.1, 27500.0],
|
||||||
[1000000.0, 0.15],
|
[1000000.0, 0.15, 77499.99999999999],
|
||||||
[2000000.0, 0.25],
|
[2000000.0, 0.25, 277500.0],
|
||||||
[5000000.0, 0.5]
|
[5000000.0, 0.5, 1527500.0],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from unittest.mock import MagicMock, PropertyMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
@ -35,34 +37,40 @@ def test_validate_order_types_gateio(default_conf, mocker):
|
|||||||
("DOGE/USDT:USDT", None),
|
("DOGE/USDT:USDT", None),
|
||||||
])
|
])
|
||||||
def test_get_maintenance_ratio_and_amt_gateio(default_conf, mocker, pair, mm_ratio):
|
def test_get_maintenance_ratio_and_amt_gateio(default_conf, mocker, pair, mm_ratio):
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="gateio")
|
mocker.patch(
|
||||||
exchange.markets = {
|
'freqtrade.exchange.Exchange.markets',
|
||||||
'ETH/USDT:USDT': {
|
PropertyMock(
|
||||||
'taker': 0.0000075,
|
return_value={
|
||||||
'maker': -0.0000025,
|
'ETH/USDT:USDT': {
|
||||||
'info': {
|
'taker': 0.0000075,
|
||||||
'maintenance_rate': '0.005',
|
'maker': -0.0000025,
|
||||||
},
|
'info': {
|
||||||
'id': 'ETH_USDT',
|
'maintenance_rate': '0.005',
|
||||||
'symbol': 'ETH/USDT:USDT',
|
},
|
||||||
},
|
'id': 'ETH_USDT',
|
||||||
'ADA/USDT:USDT': {
|
'symbol': 'ETH/USDT:USDT',
|
||||||
'taker': 0.0000075,
|
},
|
||||||
'maker': -0.0000025,
|
'ADA/USDT:USDT': {
|
||||||
'info': {
|
'taker': 0.0000075,
|
||||||
'maintenance_rate': '0.003',
|
'maker': -0.0000025,
|
||||||
},
|
'info': {
|
||||||
'id': 'ADA_USDT',
|
'maintenance_rate': '0.003',
|
||||||
'symbol': 'ADA/USDT:USDT',
|
},
|
||||||
},
|
'id': 'ADA_USDT',
|
||||||
'DOGE/USDT:USDT': {
|
'symbol': 'ADA/USDT:USDT',
|
||||||
'taker': 0.0000075,
|
},
|
||||||
'maker': -0.0000025,
|
'DOGE/USDT:USDT': {
|
||||||
'info': {
|
'taker': 0.0000075,
|
||||||
'nonmaintenance_rate': '0.003',
|
'maker': -0.0000025,
|
||||||
},
|
'info': {
|
||||||
'id': 'DOGE_USDT',
|
'nonmaintenance_rate': '0.003',
|
||||||
'symbol': 'DOGE/USDT:USDT',
|
},
|
||||||
}
|
'id': 'DOGE_USDT',
|
||||||
}
|
'symbol': 'DOGE/USDT:USDT',
|
||||||
assert exchange.get_maintenance_ratio_and_amt_gateio(pair) == [mm_ratio, None]
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
api_mock = MagicMock()
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="gateio")
|
||||||
|
assert exchange.get_maintenance_ratio_and_amt(pair) == [mm_ratio, None]
|
||||||
|
Loading…
Reference in New Issue
Block a user