Fixed errors with tradinng_mode types

This commit is contained in:
Sam Germain 2021-08-04 04:51:30 -06:00
parent 970ca71848
commit 3e04e243b4
3 changed files with 15 additions and 19 deletions

View File

@ -69,7 +69,6 @@ class Exchange:
"l2_limit_range_required": True, # Allow Empty L2 limit (kucoin) "l2_limit_range_required": True, # Allow Empty L2 limit (kucoin)
} }
_ft_has: Dict = {} _ft_has: Dict = {}
liq_formula: LiqFormula
interest_mode: InterestMode = InterestMode.NONE interest_mode: InterestMode = InterestMode.NONE
liq_formula: LiqFormula = LiqFormula.NONE liq_formula: LiqFormula = LiqFormula.NONE

View File

@ -22,7 +22,7 @@ class Ftx(Exchange):
"stoploss_on_exchange": True, "stoploss_on_exchange": True,
"ohlcv_candle_limit": 1500, "ohlcv_candle_limit": 1500,
} }
#interest_mode: InterestMode = InterestMode.HOURSPERDAY # interest_mode: InterestMode = InterestMode.HOURSPERDAY
liq_formula: LiqFormula = LiqFormula.FTX liq_formula: LiqFormula = LiqFormula.FTX
def market_is_tradable(self, market: Dict[str, Any]) -> bool: def market_is_tradable(self, market: Dict[str, Any]) -> bool:

View File

@ -16,7 +16,7 @@ from freqtrade.configuration import validate_config_consistency
from freqtrade.data.converter import order_book_to_dataframe from freqtrade.data.converter import order_book_to_dataframe
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
from freqtrade.edge import Edge from freqtrade.edge import Edge
from freqtrade.enums import RPCMessageType, SellType, State, TradingMode from freqtrade.enums import Collateral, RPCMessageType, SellType, State, TradingMode
from freqtrade.exceptions import (DependencyException, ExchangeError, InsufficientFundsError, from freqtrade.exceptions import (DependencyException, ExchangeError, InsufficientFundsError,
InvalidOrderException, PricingError) InvalidOrderException, PricingError)
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds
@ -42,6 +42,9 @@ class FreqtradeBot(LoggingMixin):
This is from here the bot start its logic. This is from here the bot start its logic.
""" """
trading_mode: TradingMode = TradingMode.SPOT
collateral_type: Optional[Collateral] = None
def __init__(self, config: Dict[str, Any]) -> None: def __init__(self, config: Dict[str, Any]) -> None:
""" """
Init all variables and objects the bot needs to work Init all variables and objects the bot needs to work
@ -105,21 +108,17 @@ class FreqtradeBot(LoggingMixin):
self._exit_lock = Lock() self._exit_lock = Lock()
LoggingMixin.__init__(self, logger, timeframe_to_seconds(self.strategy.timeframe)) LoggingMixin.__init__(self, logger, timeframe_to_seconds(self.strategy.timeframe))
if self.config.get('trading_mode') == "cross_margin": trading_mode = self.config.get('trading_mode')
self.trading_mode = TradingMode.CROSS_MARGIN collateral_type = self.config.get('collateral_type')
elif self.config.get('trading_mode') == "isolated_margin": if trading_mode:
self.trading_mode = TradingMode.ISOLATED_MARGIN self.trading_mode = TradingMode(trading_mode)
elif self.config.get('trading_mode') == "cross_futures":
self.trading_mode = TradingMode.CROSS_FUTURES if collateral_type:
elif self.config.get('trading_mode') == "isolated_futures": self.collateral_type = Collateral(collateral_type)
self.trading_mode = TradingMode.ISOLATED_FUTURES
else:
self.trading_mode = TradingMode.SPOT
# Start calculating maintenance margin if on cross margin # Start calculating maintenance margin if on cross margin
# TODO: Add margin_mode to freqtrade.configuration? # TODO: Add margin_mode to freqtrade.configuration?
if self.trading_mode == TradingMode.CROSS_MARGIN or \ if self.collateral_type == Collateral.CROSS:
self.trading_mode == TradingMode.CROSS_FUTURES:
self.maintenance_margin = MaintenanceMargin( self.maintenance_margin = MaintenanceMargin(
liq_formula=self.exchange.liq_formula, liq_formula=self.exchange.liq_formula,
@ -551,8 +550,7 @@ class FreqtradeBot(LoggingMixin):
is_short=is_short is_short=is_short
) )
if self.trading_mode == TradingMode.ISOLATED_MARGIN or \ if self.collateral_type == Collateral.ISOLATED:
self.trading_mode == TradingMode.ISOLATED_FUTURES:
isolated_liq = self.exchange.liq_formula( isolated_liq = self.exchange.liq_formula(
trading_mode=self.trading_mode, trading_mode=self.trading_mode,
@ -562,8 +560,7 @@ class FreqtradeBot(LoggingMixin):
is_short=is_short is_short=is_short
) )
if self.trading_mode == TradingMode.CROSS_FUTURES or \ if self.trading_mode == TradingMode.FUTURES:
self.trading_mode == TradingMode.ISOLATED_FUTURES:
self.exchange.set_leverage(pair=pair, leverage=leverage) self.exchange.set_leverage(pair=pair, leverage=leverage)
return interest_rate, isolated_liq return interest_rate, isolated_liq