Updated _get_funding_fee method names, added kraken._get_funding_fee

This commit is contained in:
Sam Germain
2021-11-06 17:12:48 -06:00
parent cb97c6f388
commit 6e912c1053
4 changed files with 52 additions and 17 deletions

View File

@@ -1662,19 +1662,21 @@ class Exchange:
def _get_funding_fee(
self,
contract_size: float,
size: float,
funding_rate: float,
mark_price: float,
time_in_ratio: Optional[float] = None
) -> float:
"""
Calculates a single funding fee
:param contract_size: The amount/quanity
: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 * contract_size
nominal_value = mark_price * size
return nominal_value * funding_rate
@retrier
@@ -1812,7 +1814,7 @@ class Exchange:
funding_rate = funding_rate_history[int(date.timestamp() * 1000)]
mark_price = mark_price_history[int(date.timestamp() * 1000)]
fees += self._get_funding_fee(
contract_size=amount,
size=amount,
mark_price=mark_price,
funding_rate=funding_rate
)

View File

@@ -156,3 +156,25 @@ class Kraken(Exchange):
if leverage > 1.0:
params['leverage'] = leverage
return params
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: time elapsed within funding period without position alteration
"""
if not time_in_ratio:
raise OperationalException(
f"time_in_ratio is required for {self.name}._get_funding_fee")
nominal_value = mark_price * size
return nominal_value * funding_rate * time_in_ratio