reverted back exchange.get_funding_fees method
This commit is contained in:
@@ -9,7 +9,7 @@ import logging
|
||||
from copy import deepcopy
|
||||
from datetime import datetime, time, timezone
|
||||
from math import ceil
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
import arrow
|
||||
import ccxt
|
||||
@@ -1525,6 +1525,36 @@ class Exchange:
|
||||
|
||||
return self._api.fetch_funding_rates()
|
||||
|
||||
@retrier
|
||||
def get_funding_fees(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
|
||||
"""
|
||||
|
||||
if not self.exchange_has("fetchFundingHistory"):
|
||||
raise OperationalException(
|
||||
f"fetch_funding_history() has not been implemented on ccxt.{self.name}")
|
||||
|
||||
if type(since) is datetime:
|
||||
since = int(since.strftime('%s'))
|
||||
|
||||
try:
|
||||
funding_history = self._api.fetch_funding_history(
|
||||
pair=pair,
|
||||
since=since
|
||||
)
|
||||
return sum(fee['amount'] for fee in funding_history)
|
||||
except ccxt.DDoSProtection as e:
|
||||
raise DDosProtection(e) from e
|
||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||
raise TemporaryError(
|
||||
f'Could not get funding fees due to {e.__class__.__name__}. Message: {e}') from e
|
||||
except ccxt.BaseError as e:
|
||||
raise OperationalException(e) from e
|
||||
|
||||
|
||||
def hours_to_time(hours: List[int]) -> List[time]:
|
||||
'''
|
||||
|
Reference in New Issue
Block a user