Remove unused method _get_funding_fee

This commit is contained in:
Matthias 2022-01-08 11:16:56 +01:00
parent ef3a1ea8f2
commit c6c97efed3
2 changed files with 26 additions and 33 deletions

View File

@ -1829,25 +1829,6 @@ class Exchange:
else: else:
return 1.0 return 1.0
def _get_funding_fee(
self,
size: float,
funding_rate: float,
mark_price: float,
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
"""
nominal_value = mark_price * size
return nominal_value * funding_rate
@retrier @retrier
def _set_leverage( def _set_leverage(
self, self,
@ -1956,7 +1937,8 @@ class Exchange:
mark_rates: DataFrame, mark_rates: DataFrame,
amount: float, amount: float,
open_date: datetime, open_date: datetime,
close_date: Optional[datetime] = None close_date: Optional[datetime] = None,
time_in_ratio: Optional[float] = None
) -> float: ) -> float:
""" """
calculates the sum of all funding fees that occurred for a pair during a futures trade calculates the sum of all funding fees that occurred for a pair during a futures trade
@ -1965,6 +1947,7 @@ class Exchange:
:param amount: The quantity of the trade :param amount: The quantity of the trade
:param open_date: The date and time that the trade started :param open_date: The date and time that the trade started
:param close_date: The date and time that the trade ended :param close_date: The date and time that the trade ended
:param time_in_ratio: Not used by most exchange classes
""" """
fees: float = 0 fees: float = 0

View File

@ -1,8 +1,10 @@
""" Kraken exchange subclass """ """ Kraken exchange subclass """
import logging import logging
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
import ccxt import ccxt
from pandas import DataFrame
from freqtrade.enums import Collateral, TradingMode from freqtrade.enums import Collateral, TradingMode
from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException, from freqtrade.exceptions import (DDosProtection, InsufficientFundsError, InvalidOrderException,
@ -157,11 +159,13 @@ class Kraken(Exchange):
params['leverage'] = leverage params['leverage'] = leverage
return params return params
def _get_funding_fee( def _calculate_funding_fees(
self, self,
size: float, funding_rates: DataFrame,
funding_rate: float, mark_rates: DataFrame,
mark_price: float, amount: float,
open_date: datetime,
close_date: Optional[datetime] = None,
time_in_ratio: Optional[float] = None time_in_ratio: Optional[float] = None
) -> float: ) -> float:
""" """
@ -169,16 +173,22 @@ class Kraken(Exchange):
# ! passed to _get_funding_fee. For kraken futures to work in dry run and backtesting # ! 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 # ! functionality must be added that passes the parameter time_in_ratio to
# ! _get_funding_fee when using Kraken # ! _get_funding_fee when using Kraken
Calculates a single funding fee calculates the sum of all funding fees that occurred for a pair during a futures trade
:param size: contract size * number of contracts :param funding_rates: Dataframe containing Funding rates (Type FUNDING_RATE)
:param mark_price: The price of the asset that the contract is based off of :param mark_rates: Dataframe containing Mark rates (Type mark_ohlcv_price)
:param funding_rate: the interest rate and the premium :param amount: The quantity of the trade
- interest rate: :param open_date: The date and time that the trade started
- premium: varies by price difference between the perpetual contract and mark price :param close_date: The date and time that the trade ended
:param time_in_ratio: time elapsed within funding period without position alteration :param time_in_ratio: Not used by most exchange classes
""" """
if not time_in_ratio: if not time_in_ratio:
raise OperationalException( raise OperationalException(
f"time_in_ratio is required for {self.name}._get_funding_fee") f"time_in_ratio is required for {self.name}._get_funding_fee")
nominal_value = mark_price * size fees: float = 0
return nominal_value * funding_rate * time_in_ratio
df = funding_rates.merge(mark_rates, on='date', how="inner", suffixes=["_fund", "_mark"])
if not df.empty:
df = df[(df['date'] >= open_date) & (df['date'] <= close_date)]
fees = sum(df['open_fund'] * df['open_mark'] * amount * time_in_ratio)
return fees