From edfc3377c54ff9f732fdaa13b59fc37cac5b611d Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Mon, 1 Nov 2021 01:09:11 -0600 Subject: [PATCH] Updated exchange._get_funding_fee_dates to use new method funding_fee_cutoff --- freqtrade/exchange/binance.py | 9 +++++++++ freqtrade/exchange/exchange.py | 15 +++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index d23f84e7b..cc317b759 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -1,6 +1,7 @@ """ Binance exchange subclass """ import json import logging +from datetime import datetime from pathlib import Path from typing import Dict, List, Optional, Tuple @@ -227,3 +228,11 @@ class Binance(Exchange): f"{arrow.get(since_ms // 1000).isoformat()}.") return await super()._async_get_historic_ohlcv( pair=pair, timeframe=timeframe, since_ms=since_ms, is_new_pair=is_new_pair) + + def funding_fee_cutoff(self, d: datetime): + ''' + # TODO-lev: Double check that gateio, ftx, and kraken don't also have this + :param d: The open date for a trade + :return: The cutoff open time for when a funding fee is charged + ''' + return d.minute > 0 or (d.minute == 0 and d.second > 15) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 479a788a8..3e82dd626 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1702,17 +1702,24 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(e) from e - def _get_funding_fee_dates(self, d1, d2): - d1_hours = d1.hour + 1 if d1.minute > 0 or (d1.minute == 0 and d1.second > 15) else d1.hour + def funding_fee_cutoff(self, d: datetime): + ''' + :param d: The open date for a trade + :return: The cutoff open time for when a funding fee is charged + ''' + return d.minute > 0 or d.second > 0 + + def _get_funding_fee_dates(self, d1: datetime, d2: datetime): + d1_hours = d1.hour + 1 if self.funding_fee_cutoff(d1) else d1.hour d1 = datetime(d1.year, d1.month, d1.day, d1_hours) d2 = datetime(d2.year, d2.month, d2.day, d2.hour) results = [] d3 = d1 - while d3 < d2: - d3 += timedelta(hours=1) + while d3 <= d2: if d3.hour in self.funding_fee_times: results.append(d3) + d3 += timedelta(hours=1) return results