From 29e582c6d961397b8eaf184e6b446064c0ce8bfe Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Tue, 5 Oct 2021 01:42:46 -0600 Subject: [PATCH] Fixed time format for schedule and update_funding_fees conf is mocked better --- freqtrade/freqtradebot.py | 7 +++++-- tests/test_freqtradebot.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index c7cb16a14..8307dd185 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, timezone +from datetime import datetime, time, timezone from math import isclose from threading import Lock from typing import Any, Dict, List, Optional @@ -112,7 +112,7 @@ class FreqtradeBot(LoggingMixin): if self.trading_mode == TradingMode.FUTURES: for time_slot in self.exchange.funding_fee_times: - schedule.every().day.at(time_slot).do(self.update_funding_fees()) + schedule.every().day.at(str(time(time_slot))).do(self.update_funding_fees) self.wallets.update() def notify_status(self, msg: str) -> None: @@ -195,6 +195,9 @@ class FreqtradeBot(LoggingMixin): if self.get_free_open_trades(): self.enter_positions() + if self.trading_mode == TradingMode.FUTURES: + schedule.run_pending() + Trade.commit() def process_stopped(self) -> None: diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 5eb59981e..0e849f5ad 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -7,6 +7,7 @@ from copy import deepcopy from math import isclose from unittest.mock import ANY, MagicMock, PropertyMock import time_machine +import schedule import arrow import pytest @@ -4284,15 +4285,17 @@ def test_get_valid_price(mocker, default_conf_usdt) -> None: @pytest.mark.parametrize('exchange,trading_mode,calls', [ ("ftx", TradingMode.SPOT, 0), ("ftx", TradingMode.MARGIN, 0), - ("binance", TradingMode.FUTURES, 1), - ("kraken", TradingMode.FUTURES, 2), - ("ftx", TradingMode.FUTURES, 8), + ("binance", TradingMode.FUTURES, 2), + ("kraken", TradingMode.FUTURES, 3), + ("ftx", TradingMode.FUTURES, 9), ]) def test_update_funding_fees(mocker, default_conf, exchange, trading_mode, calls): patch_RPCManager(mocker) - patch_exchange(mocker) + patch_exchange(mocker, id=exchange) mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_funding_fees', return_value=True) + default_conf['trading_mode'] = trading_mode + default_conf['collateral'] = 'isolated' freqtrade = get_patched_freqtradebot(mocker, default_conf) with time_machine.travel("2021-09-01 00:00:00 +00:00") as t: @@ -4314,5 +4317,6 @@ def test_update_funding_fees(mocker, default_conf, exchange, trading_mode, calls # ) t.move_to("2021-09-01 08:00:00 +00:00") + schedule.run_pending() assert freqtrade.update_funding_fees.call_count == calls