wrote get_funding_rate_history method
This commit is contained in:
parent
8060a3c822
commit
2b7fa2721f
@ -1819,9 +1819,12 @@ class Exchange:
|
|||||||
|
|
||||||
return fees
|
return fees
|
||||||
|
|
||||||
def get_funding_rate_history(self, pair: str, start: int, end: int):
|
def get_funding_rate_history(
|
||||||
|
self,
|
||||||
|
start: int,
|
||||||
|
end: int
|
||||||
|
) -> Dict:
|
||||||
'''
|
'''
|
||||||
:param pair: quote/base currency pair
|
|
||||||
:param start: timestamp in ms of the beginning time
|
:param start: timestamp in ms of the beginning time
|
||||||
:param end: timestamp in ms of the end time
|
:param end: timestamp in ms of the end time
|
||||||
'''
|
'''
|
||||||
@ -1832,12 +1835,21 @@ class Exchange:
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fund_history = self._api.fetch_funding_rate_history(
|
funding_history: Dict = {}
|
||||||
pair,
|
for pair, market in self.markets.items():
|
||||||
since=start,
|
if market['swap']:
|
||||||
)
|
response = self._api.fetch_funding_rate_history(
|
||||||
for fund in fund_history:
|
pair,
|
||||||
self.funding_rate_history[pair][fund['timestamp']] = fund['funding_rate']
|
limit=1000,
|
||||||
|
since=start,
|
||||||
|
params={
|
||||||
|
'endTime': end
|
||||||
|
}
|
||||||
|
)
|
||||||
|
funding_history[pair] = {}
|
||||||
|
for fund in response:
|
||||||
|
funding_history[pair][fund['timestamp']] = fund['funding_rate']
|
||||||
|
return funding_history
|
||||||
except ccxt.DDoSProtection as e:
|
except ccxt.DDoSProtection as e:
|
||||||
raise DDosProtection(e) from e
|
raise DDosProtection(e) from e
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
|
@ -33,3 +33,15 @@ class Gateio(Exchange):
|
|||||||
if any(v == 'market' for k, v in order_types.items()):
|
if any(v == 'market' for k, v in order_types.items()):
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f'Exchange {self.name} does not support market orders.')
|
f'Exchange {self.name} does not support market orders.')
|
||||||
|
|
||||||
|
def get_funding_rate_history(
|
||||||
|
self,
|
||||||
|
start: int,
|
||||||
|
end: int
|
||||||
|
) -> Dict:
|
||||||
|
'''
|
||||||
|
:param start: timestamp in ms of the beginning time
|
||||||
|
:param end: timestamp in ms of the end time
|
||||||
|
'''
|
||||||
|
# TODO-lev: Has a max limit into the past of 333 days
|
||||||
|
return super().get_funding_rate_history(start, end)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
This module contains the backtesting logic
|
This module contains the backtesting logic
|
||||||
"""
|
"""
|
||||||
|
import ccxt
|
||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
@ -125,6 +126,11 @@ class Backtesting:
|
|||||||
|
|
||||||
self.progress = BTProgress()
|
self.progress = BTProgress()
|
||||||
self.abort = False
|
self.abort = False
|
||||||
|
|
||||||
|
self.funding_rate_history = getattr(ccxt, self._exchange_name).load_funding_rate_history(
|
||||||
|
self.timerange.startts,
|
||||||
|
self.timerange.stopts
|
||||||
|
)
|
||||||
self.init_backtest()
|
self.init_backtest()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user