From 795d51b68ca7c3b90b8d44b01f93043e81fd560c Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sat, 9 Oct 2021 11:27:26 -0600 Subject: [PATCH] Switched scheduler to get funding fees every hour for any exchange --- freqtrade/freqtradebot.py | 17 +++-------------- tests/test_freqtradebot.py | 19 +++++++------------ 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 9b8018515..d389750dd 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -4,7 +4,7 @@ Freqtrade is the main module of this bot. It contains the class Freqtrade() import copy import logging import traceback -from datetime import datetime, time, timedelta, timezone +from datetime import datetime, time, timezone, timedelta from math import isclose from threading import Lock from typing import Any, Dict, List, Optional @@ -116,21 +116,10 @@ class FreqtradeBot(LoggingMixin): self.update_funding_fees() self.wallets.update() - for time_slot in self.exchange.funding_fee_times: - t = str(time(self.utc_hour_to_local(time_slot))) + for time_slot in range(0, 24): + t = str(time(time_slot)) schedule.every().day.at(t).do(update) - def utc_hour_to_local(self, hour): - local_timezone = datetime.now( - timezone.utc).astimezone().tzinfo - local_time = datetime.now(local_timezone) - offset = local_time.utcoffset().total_seconds() - td = timedelta(seconds=offset) - t = datetime.strptime(f'26 Sep 2021 {hour}:00:00', '%d %b %Y %H:%M:%S') - utc = t + td - print(hour, utc) - return int(utc.strftime("%H").lstrip("0") or 0) - def notify_status(self, msg: str) -> None: """ Public method for users of this class (worker, etc.) to send notifications diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 2353c9f14..57ab363dd 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -4281,26 +4281,21 @@ def test_get_valid_price(mocker, default_conf_usdt) -> None: assert valid_price_at_min_alwd < proposed_price -@pytest.mark.parametrize('exchange,trading_mode,calls,t1,t2', [ - ("ftx", TradingMode.SPOT, 0, "2021-09-01 00:00:00", "2021-09-01 08:00:00"), - ("ftx", TradingMode.MARGIN, 0, "2021-09-01 00:00:00", "2021-09-01 08:00:00"), - ("binance", TradingMode.FUTURES, 1, "2021-09-01 00:00:01", "2021-09-01 08:00:00"), - ("kraken", TradingMode.FUTURES, 2, "2021-09-01 00:00:01", "2021-09-01 08:00:00"), - ("ftx", TradingMode.FUTURES, 8, "2021-09-01 00:00:01", "2021-09-01 08:00:00"), - ("binance", TradingMode.FUTURES, 2, "2021-08-31 23:59:59", "2021-09-01 08:00:01"), - ("kraken", TradingMode.FUTURES, 3, "2021-08-31 23:59:59", "2021-09-01 08:00:01"), - ("ftx", TradingMode.FUTURES, 9, "2021-08-31 23:59:59", "2021-09-01 08:00:01"), +@pytest.mark.parametrize('trading_mode,calls,t1,t2', [ + (TradingMode.SPOT, 0, "2021-09-01 00:00:00", "2021-09-01 08:00:00"), + (TradingMode.MARGIN, 0, "2021-09-01 00:00:00", "2021-09-01 08:00:00"), + (TradingMode.FUTURES, 8, "2021-09-01 00:00:01", "2021-09-01 08:00:00"), + (TradingMode.FUTURES, 9, "2021-08-31 23:59:59", "2021-09-01 08:00:01"), ]) -def test_update_funding_fees(mocker, default_conf, exchange, trading_mode, calls, time_machine, +def test_update_funding_fees(mocker, default_conf, trading_mode, calls, time_machine, t1, t2): time_machine.move_to(f"{t1} +00:00") patch_RPCManager(mocker) - patch_exchange(mocker, id=exchange) + patch_exchange(mocker) mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_funding_fees', return_value=True) default_conf['trading_mode'] = trading_mode default_conf['collateral'] = 'isolated' - default_conf['exchange']['name'] = exchange freqtrade = get_patched_freqtradebot(mocker, default_conf) time_machine.move_to(f"{t2} +00:00")