feat: properly parse marginmode on startup

This commit is contained in:
Matthias 2024-09-07 09:28:35 +02:00
parent f95cc960e1
commit 704e32b0dc
2 changed files with 16 additions and 2 deletions

View File

@ -15,7 +15,14 @@ from freqtrade.configuration.directory_operations import create_datadir, create_
from freqtrade.configuration.environment_vars import enironment_vars_to_dict
from freqtrade.configuration.load_config import load_file, load_from_files
from freqtrade.constants import Config
from freqtrade.enums import NON_UTIL_MODES, TRADE_MODES, CandleType, RunMode, TradingMode
from freqtrade.enums import (
NON_UTIL_MODES,
TRADE_MODES,
CandleType,
MarginMode,
RunMode,
TradingMode,
)
from freqtrade.exceptions import OperationalException
from freqtrade.loggers import setup_logging
from freqtrade.misc import deep_merge_dicts, parse_db_uri_for_logging
@ -389,6 +396,7 @@ class Configuration:
config.get("trading_mode", "spot") or "spot"
)
config["trading_mode"] = TradingMode(config.get("trading_mode", "spot") or "spot")
config["margin_mode"] = MarginMode(config.get("margin_mode", "") or "")
self._args_to_config(
config, argname="candle_types", logstring="Detected --candle-types: {}"
)

View File

@ -22,6 +22,7 @@ from freqtrade.edge import Edge
from freqtrade.enums import (
ExitCheckTuple,
ExitType,
MarginMode,
RPCMessageType,
SignalDirection,
State,
@ -108,6 +109,7 @@ class FreqtradeBot(LoggingMixin):
PairLocks.timeframe = self.config["timeframe"]
self.trading_mode: TradingMode = self.config.get("trading_mode", TradingMode.SPOT)
self.margin_mode: MarginMode = self.config.get("margin_mode", MarginMode.NONE)
self.last_process: Optional[datetime] = None
# RPC runs in separate threads, can start handling external commands just after
@ -2216,7 +2218,11 @@ class FreqtradeBot(LoggingMixin):
# TODO: should shorting/leverage be supported by Edge,
# then this will need to be fixed.
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss, initial=True)
if order.ft_order_side == trade.entry_side or (trade.amount > 0 and trade.is_open):
if (
order.ft_order_side == trade.entry_side
or (trade.amount > 0 and trade.is_open)
or self.margin_mode == MarginMode.CROSS
):
# Must also run for partial exits
# TODO: Margin will need to use interest_rate as well.
# interest_rate = self.exchange.get_interest_rate()