stable/freqtrade/exchange/okex.py
Sam Germain 179947fa72
New config (#6333)
* updated new-config to add trading_mode and margin_mode

* added trading_mode and margin_mode to config examples

* added okex config example

* new file:   config_examples/config_binance_futures.example.json

* removed trading_mode and margin_mode from base_config and binance and okex example

* deleted okex and futures config files

* updated full config file

* updated new-config command to add trading_mode and margin_mode to config

* new file:   config_examples/config_okex_futures.example.json

* removed config_okex_futures.example.json

* added trading_mode to test_start_new_config

* new-config asks exchange before asking futures

* Simplify trading_mode selection

* margin_mode is empty string for spot new configs

* build_config_commands sorted exchanges

* isort

Co-authored-by: Matthias <xmatthias@outlook.com>
2022-02-02 14:46:44 +01:00

49 lines
1.4 KiB
Python

import logging
from typing import Dict, List, Tuple
from freqtrade.enums import MarginMode, TradingMode
from freqtrade.exceptions import OperationalException
from freqtrade.exchange import Exchange
logger = logging.getLogger(__name__)
class Okex(Exchange):
"""Okex exchange class.
Contains adjustments needed for Freqtrade to work with this exchange.
"""
_ft_has: Dict = {
"ohlcv_candle_limit": 300,
"mark_ohlcv_timeframe": "4h",
"funding_fee_timeframe": "8h",
}
_supported_trading_mode_margin_pairs: List[Tuple[TradingMode, MarginMode]] = [
# TradingMode.SPOT always supported and not required in this list
# (TradingMode.MARGIN, MarginMode.CROSS),
# (TradingMode.FUTURES, MarginMode.CROSS),
# (TradingMode.FUTURES, MarginMode.ISOLATED)
]
def _lev_prep(
self,
pair: str,
leverage: float,
side: str # buy or sell
):
if self.trading_mode != TradingMode.SPOT:
if self.margin_mode is None:
raise OperationalException(
f"{self.name}.margin_mode must be set for {self.trading_mode.value}"
)
self._api.set_leverage(
leverage,
pair,
params={
"mgnMode": self.margin_mode.value,
"posSide": "long" if side == "buy" else "short",
})