Merge pull request #5773 from samgermain/gateio-futures

Gateio futures
This commit is contained in:
Matthias 2021-10-24 08:45:24 +02:00 committed by GitHub
commit 4966619f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 5 deletions

View File

@ -1,7 +1,8 @@
""" Gate.io exchange subclass """
import logging
from typing import Dict, List
from typing import Dict, List, Tuple
from freqtrade.enums import Collateral, TradingMode
from freqtrade.exceptions import OperationalException
from freqtrade.exchange import Exchange
@ -27,6 +28,31 @@ class Gateio(Exchange):
funding_fee_times: List[int] = [0, 8, 16] # hours of the day
_supported_trading_mode_collateral_pairs: List[Tuple[TradingMode, Collateral]] = [
# TradingMode.SPOT always supported and not required in this list
# (TradingMode.MARGIN, Collateral.CROSS), # TODO-lev: Uncomment once supported
# (TradingMode.FUTURES, Collateral.CROSS), # TODO-lev: Uncomment once supported
# (TradingMode.FUTURES, Collateral.ISOLATED) # TODO-lev: Uncomment once supported
]
@property
def _ccxt_config(self) -> Dict:
# Parameters to add directly to ccxt sync/async initialization.
if self.trading_mode == TradingMode.MARGIN:
return {
"options": {
"defaultType": "margin"
}
}
elif self.trading_mode == TradingMode.FUTURES:
return {
"options": {
"defaultType": "swap"
}
}
else:
return {}
def validate_ordertypes(self, order_types: Dict) -> None:
super().validate_ordertypes(order_types)

View File

@ -25,7 +25,7 @@ from tests.conftest import get_mock_coro, get_patched_exchange, log_has, log_has
# Make sure to always keep one exchange here which is NOT subclassed!!
EXCHANGES = ['bittrex', 'binance', 'kraken', 'ftx']
EXCHANGES = ['bittrex', 'binance', 'kraken', 'ftx', 'gateio']
def ccxt_exceptionhandlers(mocker, default_conf, api_mock, exchange_name,
@ -3206,6 +3206,7 @@ def test_set_margin_mode(mocker, default_conf, collateral):
("bittrex", TradingMode.MARGIN, Collateral.ISOLATED, True),
("bittrex", TradingMode.FUTURES, Collateral.CROSS, True),
("bittrex", TradingMode.FUTURES, Collateral.ISOLATED, True),
("gateio", TradingMode.MARGIN, Collateral.ISOLATED, True),
# TODO-lev: Remove once implemented
("binance", TradingMode.MARGIN, Collateral.CROSS, True),
@ -3215,6 +3216,9 @@ def test_set_margin_mode(mocker, default_conf, collateral):
("kraken", TradingMode.FUTURES, Collateral.CROSS, True),
("ftx", TradingMode.MARGIN, Collateral.CROSS, True),
("ftx", TradingMode.FUTURES, Collateral.CROSS, True),
("gateio", TradingMode.MARGIN, Collateral.CROSS, True),
("gateio", TradingMode.FUTURES, Collateral.CROSS, True),
("gateio", TradingMode.FUTURES, Collateral.ISOLATED, True),
# TODO-lev: Uncomment once implemented
# ("binance", TradingMode.MARGIN, Collateral.CROSS, False),
@ -3223,7 +3227,10 @@ def test_set_margin_mode(mocker, default_conf, collateral):
# ("kraken", TradingMode.MARGIN, Collateral.CROSS, False),
# ("kraken", TradingMode.FUTURES, Collateral.CROSS, False),
# ("ftx", TradingMode.MARGIN, Collateral.CROSS, False),
# ("ftx", TradingMode.FUTURES, Collateral.CROSS, False)
# ("ftx", TradingMode.FUTURES, Collateral.CROSS, False),
# ("gateio", TradingMode.MARGIN, Collateral.CROSS, False),
# ("gateio", TradingMode.FUTURES, Collateral.CROSS, False),
# ("gateio", TradingMode.FUTURES, Collateral.ISOLATED, False),
])
def test_validate_trading_mode_and_collateral(
default_conf,
@ -3253,8 +3260,9 @@ def test_validate_trading_mode_and_collateral(
("ftx", "margin", {}),
("ftx", "futures", {}),
("bittrex", "spot", {}),
("bittrex", "margin", {}),
("bittrex", "futures", {}),
("gateio", "spot", {}),
("gateio", "margin", {"options": {"defaultType": "margin"}}),
("gateio", "futures", {"options": {"defaultType": "swap"}}),
])
def test__ccxt_config(
default_conf,