Added funding fee calculation methods to exchange classes

This commit is contained in:
Sam Germain
2021-09-08 19:31:04 -06:00
parent cdefd15b28
commit 36b8c87fb6
3 changed files with 58 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
""" Binance exchange subclass """
import logging
from typing import Dict, List
from typing import Dict, List, Optional
import ccxt
from datetime import time
@@ -90,3 +90,23 @@ class Binance(Exchange):
f'Could not place sell order due to {e.__class__.__name__}. Message: {e}') from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
def _get_funding_fee(
self,
contract_size: float,
mark_price: float,
funding_rate: Optional[float],
) -> float:
"""
Calculates a single funding fee
:param contract_size: The amount/quanity
: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: 0.03% daily, BNBUSDT, LINKUSDT, and LTCUSDT are 0%
- premium: varies by price difference between the perpetual contract and mark price
"""
if funding_rate is None:
raise OperationalException("Funding rate cannot be None for Binance._get_funding_fee")
nominal_value = mark_price * contract_size
adjustment = nominal_value * funding_rate
return adjustment