Switched scheduler to get funding fees every hour for any exchange

This commit is contained in:
Sam Germain 2021-10-09 11:27:26 -06:00
parent 39be675f1f
commit 795d51b68c
2 changed files with 10 additions and 26 deletions

View File

@ -4,7 +4,7 @@ Freqtrade is the main module of this bot. It contains the class Freqtrade()
import copy import copy
import logging import logging
import traceback import traceback
from datetime import datetime, time, timedelta, timezone from datetime import datetime, time, timezone, timedelta
from math import isclose from math import isclose
from threading import Lock from threading import Lock
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
@ -116,21 +116,10 @@ class FreqtradeBot(LoggingMixin):
self.update_funding_fees() self.update_funding_fees()
self.wallets.update() self.wallets.update()
for time_slot in self.exchange.funding_fee_times: for time_slot in range(0, 24):
t = str(time(self.utc_hour_to_local(time_slot))) t = str(time(time_slot))
schedule.every().day.at(t).do(update) 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: def notify_status(self, msg: str) -> None:
""" """
Public method for users of this class (worker, etc.) to send notifications Public method for users of this class (worker, etc.) to send notifications

View File

@ -4281,26 +4281,21 @@ def test_get_valid_price(mocker, default_conf_usdt) -> None:
assert valid_price_at_min_alwd < proposed_price assert valid_price_at_min_alwd < proposed_price
@pytest.mark.parametrize('exchange,trading_mode,calls,t1,t2', [ @pytest.mark.parametrize('trading_mode,calls,t1,t2', [
("ftx", TradingMode.SPOT, 0, "2021-09-01 00:00:00", "2021-09-01 08:00:00"), (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"), (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"), (TradingMode.FUTURES, 8, "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"), (TradingMode.FUTURES, 9, "2021-08-31 23:59:59", "2021-09-01 08:00:01"),
("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"),
]) ])
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): t1, t2):
time_machine.move_to(f"{t1} +00:00") time_machine.move_to(f"{t1} +00:00")
patch_RPCManager(mocker) patch_RPCManager(mocker)
patch_exchange(mocker, id=exchange) patch_exchange(mocker)
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_funding_fees', return_value=True) mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_funding_fees', return_value=True)
default_conf['trading_mode'] = trading_mode default_conf['trading_mode'] = trading_mode
default_conf['collateral'] = 'isolated' default_conf['collateral'] = 'isolated'
default_conf['exchange']['name'] = exchange
freqtrade = get_patched_freqtradebot(mocker, default_conf) freqtrade = get_patched_freqtradebot(mocker, default_conf)
time_machine.move_to(f"{t2} +00:00") time_machine.move_to(f"{t2} +00:00")