From 25fa6bee74fe8025bed8b4e2a9ef8b5184a9c0df Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 24 Jan 2023 07:21:16 +0100 Subject: [PATCH] Override get_funding_fees for bybit --- docs/exchanges.md | 2 ++ freqtrade/exchange/bybit.py | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/exchanges.md b/docs/exchanges.md index d2a2862e3..bbed3cef0 100644 --- a/docs/exchanges.md +++ b/docs/exchanges.md @@ -260,6 +260,8 @@ The configuration parameter `exchange.unknown_fee_rate` can be used to specify t Futures trading on bybit is currently supported for USDT markets, and will use isolated futures mode. Users with unified accounts (there's no way back) can create a subaccount which will start as "non-unified", and can therefore use isolated futures. +As bybit doesn't provide funding rate history, the dry-run calculation is used for live trades as well. + ## All exchanges Should you experience constant errors with Nonce (like `InvalidNonce`), it is best to regenerate the API keys. Resetting Nonce is difficult and it's usually easier to regenerate the API keys. diff --git a/freqtrade/exchange/bybit.py b/freqtrade/exchange/bybit.py index 9cef27591..a99f3656c 100644 --- a/freqtrade/exchange/bybit.py +++ b/freqtrade/exchange/bybit.py @@ -173,13 +173,20 @@ class Bybit(Exchange): raise OperationalException( "Freqtrade only supports isolated futures for leverage trading") - def _get_funding_fees_from_exchange(self, pair: str, since: Union[datetime, int]) -> float: + def get_funding_fees( + self, pair: str, amount: float, is_short: bool, open_date: datetime) -> float: """ - Returns the sum of all funding fees that were exchanged for a pair within a timeframe - Dry-run handling happens as part of _calculate_funding_fees. - :param pair: (e.g. ADA/USDT) - :param since: The earliest time of consideration for calculating funding fees, - in unix time or as a datetime + Fetch funding fees, either from the exchange (live) or calculates them + based on funding rate/mark price history + :param pair: The quote/base pair of the trade + :param is_short: trade direction + :param amount: Trade amount + :param open_date: Open date of the trade + :return: funding fee since open_date + :raises: ExchangeError if something goes wrong. """ - # TODO: Workaround for bybit, which has no funding-fees - return 0 + # Bybit does not provide "applied" funding fees per position. + if self.trading_mode == TradingMode.FUTURES: + return self._fetch_and_calculate_funding_fees( + pair, amount, is_short, open_date) + return 0.0