diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index cc317b759..e3662235e 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -231,8 +231,8 @@ class Binance(Exchange): def funding_fee_cutoff(self, d: datetime): ''' - # TODO-lev: Double check that gateio, ftx, and kraken don't also have this - :param d: The open date for a trade - :return: The cutoff open time for when a funding fee is charged + # TODO-lev: Double check that gateio, ftx, and kraken don't also have this + :param d: The open date for a trade + :return: The cutoff open time for when a funding fee is charged ''' return d.minute > 0 or (d.minute == 0 and d.second > 15) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 249cc38e8..cacbe4f7e 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1608,10 +1608,10 @@ class Exchange: @retrier def _get_funding_fees_from_exchange(self, pair: str, since: Union[datetime, int]) -> float: """ - Returns the sum of all funding fees that were exchanged for a pair within a timeframe - :param pair: (e.g. ADA/USDT) - :param since: The earliest time of consideration for calculating funding fees, - in unix time or as a datetime + Returns the sum of all funding fees that were exchanged for a pair within a timeframe + :param pair: (e.g. ADA/USDT) + :param since: The earliest time of consideration for calculating funding fees, + in unix time or as a datetime """ # TODO-lev: Add dry-run handling for this. @@ -1638,17 +1638,17 @@ class Exchange: def fill_leverage_brackets(self): """ - Assigns property _leverage_brackets to a dictionary of information about the leverage - allowed on each pair - Not used if the exchange has a static max leverage value for the account or each pair + Assigns property _leverage_brackets to a dictionary of information about the leverage + allowed on each pair + Not used if the exchange has a static max leverage value for the account or each pair """ return def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float: """ - Returns the maximum leverage that a pair can be traded at - :param pair: The base/quote currency pair being traded - :nominal_value: The total value of the trade in quote currency (collateral + debt) + Returns the maximum leverage that a pair can be traded at + :param pair: The base/quote currency pair being traded + :nominal_value: The total value of the trade in quote currency (collateral + debt) """ market = self.markets[pair] if ( @@ -1668,13 +1668,13 @@ class Exchange: time_in_ratio: Optional[float] = None ) -> float: """ - Calculates a single funding fee - :param size: contract size * number of contracts - :param mark_price: The price of the asset that the contract is based off of - :param funding_rate: the interest rate and the premium - - interest rate: - - premium: varies by price difference between the perpetual contract and mark price - :param time_in_ratio: Not used by most exchange classes + Calculates a single funding fee + :param size: contract size * number of contracts + :param mark_price: The price of the asset that the contract is based off of + :param funding_rate: the interest rate and the premium + - interest rate: + - premium: varies by price difference between the perpetual contract and mark price + :param time_in_ratio: Not used by most exchange classes """ nominal_value = mark_price * size return nominal_value * funding_rate @@ -1687,8 +1687,8 @@ class Exchange: trading_mode: Optional[TradingMode] = None ): """ - Set's the leverage before making a trade, in order to not - have the same leverage on every trade + Set's the leverage before making a trade, in order to not + have the same leverage on every trade """ if self._config['dry_run'] or not self.exchange_has("setLeverage"): # Some exchanges only support one collateral type @@ -1706,8 +1706,8 @@ class Exchange: def funding_fee_cutoff(self, d: datetime): ''' - :param d: The open date for a trade - :return: The cutoff open time for when a funding fee is charged + :param d: The open date for a trade + :return: The cutoff open time for when a funding fee is charged ''' return d.minute > 0 or d.second > 0 @@ -1729,8 +1729,8 @@ class Exchange: @retrier def set_margin_mode(self, pair: str, collateral: Collateral, params: dict = {}): ''' - Set's the margin mode on the exchange to cross or isolated for a specific pair - :param pair: base/quote currency pair (e.g. "ADA/USDT") + Set's the margin mode on the exchange to cross or isolated for a specific pair + :param pair: base/quote currency pair (e.g. "ADA/USDT") ''' if self._config['dry_run'] or not self.exchange_has("setMarginMode"): # Some exchanges only support one collateral type @@ -1753,7 +1753,7 @@ class Exchange: since: int ) -> Dict: """ - Get's the mark price history for a pair + Get's the mark price history for a pair """ try: @@ -1802,11 +1802,11 @@ class Exchange: close_date: Optional[datetime] = None ) -> float: """ - calculates the sum of all funding fees that occurred for a pair during a futures trade - :param pair: The quote/base pair of the trade - :param amount: The quantity of the trade - :param open_date: The date and time that the trade started - :param close_date: The date and time that the trade ended + calculates the sum of all funding fees that occurred for a pair during a futures trade + :param pair: The quote/base pair of the trade + :param amount: The quantity of the trade + :param open_date: The date and time that the trade started + :param close_date: The date and time that the trade ended """ fees: float = 0 @@ -1869,9 +1869,9 @@ class Exchange: since: int, ) -> Dict: ''' - :param pair: quote/base currency pair - :param since: timestamp in ms of the beginning time - :param end: timestamp in ms of the end time + :param pair: quote/base currency pair + :param since: timestamp in ms of the beginning time + :param end: timestamp in ms of the end time ''' if not self.exchange_has("fetchFundingRateHistory"): raise ExchangeError( diff --git a/freqtrade/exchange/kraken.py b/freqtrade/exchange/kraken.py index 8ab29ee90..0e9642ec7 100644 --- a/freqtrade/exchange/kraken.py +++ b/freqtrade/exchange/kraken.py @@ -165,17 +165,17 @@ class Kraken(Exchange): time_in_ratio: Optional[float] = None ) -> float: """ - # ! This method will always error when run by Freqtrade because time_in_ratio is never - # ! passed to _get_funding_fee. For kraken futures to work in dry run and backtesting - # ! functionality must be added that passes the parameter time_in_ratio to - # ! _get_funding_fee when using Kraken - Calculates a single funding fee - :param size: contract size * number of contracts - :param mark_price: The price of the asset that the contract is based off of - :param funding_rate: the interest rate and the premium - - interest rate: - - premium: varies by price difference between the perpetual contract and mark price - :param time_in_ratio: time elapsed within funding period without position alteration + # ! This method will always error when run by Freqtrade because time_in_ratio is never + # ! passed to _get_funding_fee. For kraken futures to work in dry run and backtesting + # ! functionality must be added that passes the parameter time_in_ratio to + # ! _get_funding_fee when using Kraken + Calculates a single funding fee + :param size: contract size * number of contracts + :param mark_price: The price of the asset that the contract is based off of + :param funding_rate: the interest rate and the premium + - interest rate: + - premium: varies by price difference between the perpetual contract and mark price + :param time_in_ratio: time elapsed within funding period without position alteration """ if not time_in_ratio: raise OperationalException( diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index d565879cd..cbf4becbe 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -4718,21 +4718,21 @@ def test_update_funding_fees_schedule(mocker, default_conf, trading_mode, calls, @pytest.mark.parametrize('is_short', [True, False]) def test_update_funding_fees(mocker, default_conf, time_machine, fee, is_short, limit_order_open): ''' - nominal_value = mark_price * size - funding_fee = nominal_value * funding_rate - size = 123 - "LTC/BTC" - time: 0, mark: 3.3, fundRate: 0.00032583, nominal_value: 405.9, fundFee: 0.132254397 - time: 8, mark: 3.2, fundRate: 0.00024472, nominal_value: 393.6, fundFee: 0.096321792 - "ETH/BTC" - time: 0, mark: 2.4, fundRate: 0.0001, nominal_value: 295.2, fundFee: 0.02952 - time: 8, mark: 2.5, fundRate: 0.0001, nominal_value: 307.5, fundFee: 0.03075 - "ETC/BTC" - time: 0, mark: 4.3, fundRate: 0.00031077, nominal_value: 528.9, fundFee: 0.164366253 - time: 8, mark: 4.1, fundRate: 0.00022655, nominal_value: 504.3, fundFee: 0.114249165 - "XRP/BTC" - time: 0, mark: 1.2, fundRate: 0.00049426, nominal_value: 147.6, fundFee: 0.072952776 - time: 8, mark: 1.2, fundRate: 0.00032715, nominal_value: 147.6, fundFee: 0.04828734 + nominal_value = mark_price * size + funding_fee = nominal_value * funding_rate + size = 123 + "LTC/BTC" + time: 0, mark: 3.3, fundRate: 0.00032583, nominal_value: 405.9, fundFee: 0.132254397 + time: 8, mark: 3.2, fundRate: 0.00024472, nominal_value: 393.6, fundFee: 0.096321792 + "ETH/BTC" + time: 0, mark: 2.4, fundRate: 0.0001, nominal_value: 295.2, fundFee: 0.02952 + time: 8, mark: 2.5, fundRate: 0.0001, nominal_value: 307.5, fundFee: 0.03075 + "ETC/BTC" + time: 0, mark: 4.3, fundRate: 0.00031077, nominal_value: 528.9, fundFee: 0.164366253 + time: 8, mark: 4.1, fundRate: 0.00022655, nominal_value: 504.3, fundFee: 0.114249165 + "XRP/BTC" + time: 0, mark: 1.2, fundRate: 0.00049426, nominal_value: 147.6, fundFee: 0.072952776 + time: 8, mark: 1.2, fundRate: 0.00032715, nominal_value: 147.6, fundFee: 0.04828734 ''' # SETUP time_machine.move_to("2021-09-01 00:00:00 +00:00")