2021-08-20 04:51:04 +00:00
|
|
|
""" Gate.io exchange subclass """
|
|
|
|
import logging
|
2022-02-16 09:36:08 +00:00
|
|
|
from typing import Dict, List, Optional, Tuple
|
2021-08-20 04:51:04 +00:00
|
|
|
|
2022-02-01 18:53:38 +00:00
|
|
|
from freqtrade.enums import MarginMode, TradingMode
|
2021-10-03 12:14:16 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2021-08-20 04:51:04 +00:00
|
|
|
from freqtrade.exchange import Exchange
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Gateio(Exchange):
|
|
|
|
"""
|
|
|
|
Gate.io exchange class. Contains adjustments needed for Freqtrade to work
|
|
|
|
with this exchange.
|
|
|
|
|
|
|
|
Please note that this exchange is not included in the list of exchanges
|
|
|
|
officially supported by the Freqtrade development team. So some features
|
|
|
|
may still not work as expected.
|
|
|
|
"""
|
|
|
|
|
|
|
|
_ft_has: Dict = {
|
|
|
|
"ohlcv_candle_limit": 1000,
|
2022-01-06 15:13:10 +00:00
|
|
|
"ohlcv_volume_currency": "quote",
|
2021-08-20 04:51:04 +00:00
|
|
|
}
|
2021-09-16 04:28:10 +00:00
|
|
|
|
|
|
|
_headers = {'X-Gate-Channel-Id': 'freqtrade'}
|
2021-10-09 18:36:00 +00:00
|
|
|
|
2022-02-01 18:53:38 +00:00
|
|
|
_supported_trading_mode_margin_pairs: List[Tuple[TradingMode, MarginMode]] = [
|
2021-10-20 11:43:46 +00:00
|
|
|
# TradingMode.SPOT always supported and not required in this list
|
2022-02-01 18:53:38 +00:00
|
|
|
# (TradingMode.MARGIN, MarginMode.CROSS),
|
|
|
|
# (TradingMode.FUTURES, MarginMode.CROSS),
|
2022-02-16 09:36:08 +00:00
|
|
|
(TradingMode.FUTURES, MarginMode.ISOLATED)
|
2021-10-20 11:43:46 +00:00
|
|
|
]
|
|
|
|
|
2021-10-03 12:14:16 +00:00
|
|
|
def validate_ordertypes(self, order_types: Dict) -> None:
|
|
|
|
super().validate_ordertypes(order_types)
|
|
|
|
|
|
|
|
if any(v == 'market' for k, v in order_types.items()):
|
|
|
|
raise OperationalException(
|
2021-10-13 23:56:40 +00:00
|
|
|
f'Exchange {self.name} does not support market orders.')
|
2022-02-16 09:36:08 +00:00
|
|
|
|
|
|
|
def get_maintenance_ratio_and_amt(
|
|
|
|
self,
|
|
|
|
pair: str,
|
|
|
|
nominal_value: Optional[float] = 0.0,
|
|
|
|
) -> Tuple[float, Optional[float]]:
|
|
|
|
"""
|
|
|
|
:return: The maintenance margin ratio and maintenance amount
|
|
|
|
"""
|
|
|
|
info = self.markets[pair]['info']
|
|
|
|
return (float(info['maintenance_rate']), None)
|
|
|
|
|
|
|
|
def get_max_leverage(self, pair: str, stake_amount: Optional[float]) -> float:
|
|
|
|
"""
|
|
|
|
Returns the maximum leverage that a pair can be traded at
|
|
|
|
:param pair: The base/quote currency pair being traded
|
|
|
|
:param nominal_value: The total value of the trade in quote currency (margin_mode + debt)
|
|
|
|
"""
|
|
|
|
market = self.markets[pair]
|
|
|
|
if market['limits']['leverage']['max'] is not None:
|
|
|
|
return market['limits']['leverage']['max']
|
2022-02-16 10:05:27 +00:00
|
|
|
else:
|
|
|
|
return 1.0
|