From 1eee5373b91655385817214c38bc8d2f3c8afcb9 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Tue, 11 Jan 2022 21:22:55 -0600 Subject: [PATCH] gateio.get_maintenance_ratio_and_amt --- freqtrade/exchange/gateio.py | 13 +++++++++++- tests/exchange/test_gateio.py | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/freqtrade/exchange/gateio.py b/freqtrade/exchange/gateio.py index 203aa735b..c6dc0c9b9 100644 --- a/freqtrade/exchange/gateio.py +++ b/freqtrade/exchange/gateio.py @@ -1,6 +1,6 @@ """ Gate.io exchange subclass """ import logging -from typing import Dict, List, Tuple +from typing import Dict, List, Optional, Tuple from freqtrade.enums import Collateral, TradingMode from freqtrade.exceptions import OperationalException @@ -40,3 +40,14 @@ class Gateio(Exchange): if any(v == 'market' for k, v in order_types.items()): raise OperationalException( f'Exchange {self.name} does not support market orders.') + + def get_maintenance_ratio_and_amt( + self, + pair: Optional[str], + nominal_value: Optional[float] + ): + info = self.markets[pair]['info'] + if 'maintenance_rate' in info: + return [float(info['maintenance_rate']), None] + else: + return [None, None] diff --git a/tests/exchange/test_gateio.py b/tests/exchange/test_gateio.py index 6f7862909..09bd5e1b3 100644 --- a/tests/exchange/test_gateio.py +++ b/tests/exchange/test_gateio.py @@ -3,6 +3,7 @@ import pytest from freqtrade.exceptions import OperationalException from freqtrade.exchange import Gateio from freqtrade.resolvers.exchange_resolver import ExchangeResolver +from tests.conftest import get_patched_exchange def test_validate_order_types_gateio(default_conf, mocker): @@ -26,3 +27,42 @@ def test_validate_order_types_gateio(default_conf, mocker): with pytest.raises(OperationalException, match=r'Exchange .* does not support market orders.'): ExchangeResolver.load_exchange('gateio', default_conf, True) + + +@pytest.mark.parametrize('pair,mm_ratio', [ + ("ETH/USDT:USDT", 0.005), + ("ADA/USDT:USDT", 0.003), + ("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]