fixed breaking tests for liquidation price

This commit is contained in:
Sam Germain 2022-01-13 01:21:36 -06:00
parent 1eee5373b9
commit 2d545a2def
5 changed files with 73 additions and 65 deletions

View File

@ -139,12 +139,12 @@ class Binance(Exchange):
[amt, old_ratio] = [None, None]
brackets = []
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
old_ratio = mm_ratio
brackets.append([
float(notional_floor),
mm_ratio,
float(mm_ratio),
amt,
])
self._leverage_brackets[pair] = brackets
@ -231,8 +231,8 @@ class Binance(Exchange):
def get_maintenance_ratio_and_amt(
self,
pair: Optional[str],
nominal_value: Optional[float]
pair: str,
nominal_value: Optional[float] = 0.0,
):
'''
Maintenance amt = Floor of Position Bracket on Level n *

View File

@ -2005,8 +2005,8 @@ class Exchange:
def get_maintenance_ratio_and_amt(
self,
pair: Optional[str],
nominal_value: Optional[float]
pair: str,
nominal_value: Optional[float] = 0.0,
):
'''
:return: The maintenance amount, and maintenance margin rate

View File

@ -43,8 +43,8 @@ class Gateio(Exchange):
def get_maintenance_ratio_and_amt(
self,
pair: Optional[str],
nominal_value: Optional[float]
pair: str,
nominal_value: Optional[float] = 0.0,
):
info = self.markets[pair]['info']
if 'maintenance_rate' in info:

View File

@ -242,7 +242,7 @@ def test_fill_leverage_brackets_binance(default_conf, mocker):
[500000.0, 0.1, 27500.0],
[1000000.0, 0.15, 77499.99999999999],
[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],
[50000.0, 0.005, 50.0],
[250000.0, 0.01, 1300.0],
@ -284,37 +284,37 @@ def test_fill_leverage_brackets_binance_dryrun(default_conf, mocker):
leverage_brackets = {
"1000SHIB/USDT": [
[0.0, 0.01],
[5000.0, 0.025],
[25000.0, 0.05],
[100000.0, 0.1],
[250000.0, 0.125],
[1000000.0, 0.5]
[0.0, 0.01, 0.0],
[5000.0, 0.025, 75.0],
[25000.0, 0.05, 700.0],
[100000.0, 0.1, 5700.0],
[250000.0, 0.125, 11949.999999999998],
[1000000.0, 0.5, 386950.0],
],
"1INCH/USDT": [
[0.0, 0.012],
[5000.0, 0.025],
[25000.0, 0.05],
[100000.0, 0.1],
[250000.0, 0.125],
[1000000.0, 0.5]
[0.0, 0.012, 0.0],
[5000.0, 0.025, 65.0],
[25000.0, 0.05, 690.0],
[100000.0, 0.1, 5690.0],
[250000.0, 0.125, 11939.999999999998],
[1000000.0, 0.5, 386940.0],
],
"AAVE/USDT": [
[0.0, 0.01],
[50000.0, 0.02],
[250000.0, 0.05],
[1000000.0, 0.1],
[2000000.0, 0.125],
[5000000.0, 0.1665],
[10000000.0, 0.25]
[0.0, 0.01, 0.0],
[50000.0, 0.02, 500.0],
[250000.0, 0.05, 8000.000000000001],
[1000000.0, 0.1, 58000.0],
[2000000.0, 0.125, 107999.99999999999],
[5000000.0, 0.1665, 315500.00000000006],
[10000000.0, 0.25, 1150500.0],
],
"ADA/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]
[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],
]
}

View File

@ -1,3 +1,5 @@
from unittest.mock import MagicMock, PropertyMock
import pytest
from freqtrade.exceptions import OperationalException
@ -35,34 +37,40 @@ def test_validate_order_types_gateio(default_conf, mocker):
("DOGE/USDT:USDT", None),
])
def test_get_maintenance_ratio_and_amt_gateio(default_conf, mocker, pair, mm_ratio):
exchange = get_patched_exchange(mocker, default_conf, id="gateio")
exchange.markets = {
'ETH/USDT:USDT': {
'taker': 0.0000075,
'maker': -0.0000025,
'info': {
'maintenance_rate': '0.005',
},
'id': 'ETH_USDT',
'symbol': 'ETH/USDT:USDT',
},
'ADA/USDT:USDT': {
'taker': 0.0000075,
'maker': -0.0000025,
'info': {
'maintenance_rate': '0.003',
},
'id': 'ADA_USDT',
'symbol': 'ADA/USDT:USDT',
},
'DOGE/USDT:USDT': {
'taker': 0.0000075,
'maker': -0.0000025,
'info': {
'nonmaintenance_rate': '0.003',
},
'id': 'DOGE_USDT',
'symbol': 'DOGE/USDT:USDT',
}
}
assert exchange.get_maintenance_ratio_and_amt_gateio(pair) == [mm_ratio, None]
mocker.patch(
'freqtrade.exchange.Exchange.markets',
PropertyMock(
return_value={
'ETH/USDT:USDT': {
'taker': 0.0000075,
'maker': -0.0000025,
'info': {
'maintenance_rate': '0.005',
},
'id': 'ETH_USDT',
'symbol': 'ETH/USDT:USDT',
},
'ADA/USDT:USDT': {
'taker': 0.0000075,
'maker': -0.0000025,
'info': {
'maintenance_rate': '0.003',
},
'id': 'ADA_USDT',
'symbol': 'ADA/USDT:USDT',
},
'DOGE/USDT:USDT': {
'taker': 0.0000075,
'maker': -0.0000025,
'info': {
'nonmaintenance_rate': '0.003',
},
'id': 'DOGE_USDT',
'symbol': 'DOGE/USDT:USDT',
}
}
)
)
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]