From 8b9dfafdf4195591c0571bb5c756c779dd28e188 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Mon, 1 Nov 2021 01:09:57 -0600 Subject: [PATCH] Tests for _get_funding_fee_dates --- tests/exchange/test_exchange.py | 135 +++++++++++++++++++++++++------- 1 file changed, 108 insertions(+), 27 deletions(-) diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index eaf6960c4..b95064f5c 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3307,34 +3307,115 @@ def test__get_funding_fee( assert exchange._get_funding_fee(contract_size, funding_rate, mark_price) == funding_fee -@pytest.mark.parametrize('exchange,d1,d2', [ - ('binance', "2021-09-01 00:00:00", "2021-09-01 08:00:00"), - ('binance', "2021-09-01 00:00:15", "2021-09-01 08:00:00"), - ('binance', "2021-09-01 00:00:16", "2021-09-01 08:00:00"), - ('binance', "2021-09-01 00:00:00", "2021-09-01 07:59:45"), - ('binance', "2021-09-01 00:00:00", "2021-09-01 07:59:44"), - ('binance', "2021-09-01 00:00:00", "2021-09-01 12:00:00"), - ('kraken', "2021-09-01 00:00:00", "2021-09-01 08:00:00"), - ('kraken', "2021-09-01 00:00:15", "2021-09-01 08:00:00"), - ('kraken', "2021-09-01 00:00:16", "2021-09-01 08:00:00"), - ('kraken', "2021-09-01 00:00:00", "2021-09-01 07:59:45"), - ('kraken', "2021-09-01 00:00:00", "2021-09-01 07:59:44"), - ('kraken', "2021-09-01 00:00:00", "2021-09-01 12:00:00"), - ('ftx', "2021-09-01 00:00:00", "2021-09-01 08:00:00"), - ('ftx', "2021-09-01 00:00:15", "2021-09-01 08:00:00"), - ('ftx', "2021-09-01 00:00:16", "2021-09-01 08:00:00"), - ('ftx', "2021-09-01 00:00:00", "2021-09-01 07:59:45"), - ('ftx', "2021-09-01 00:00:00", "2021-09-01 07:59:44"), - ('ftx', "2021-09-01 00:00:00", "2021-09-01 12:00:00"), - ('gateio', "2021-09-01 00:00:00", "2021-09-01 08:00:00"), - ('gateio', "2021-09-01 00:00:15", "2021-09-01 08:00:00"), - ('gateio', "2021-09-01 00:00:16", "2021-09-01 08:00:00"), - ('gateio', "2021-09-01 00:00:00", "2021-09-01 07:59:45"), - ('gateio', "2021-09-01 00:00:00", "2021-09-01 07:59:44"), - ('gateio', "2021-09-01 00:00:00", "2021-09-01 12:00:00"), +@pytest.mark.parametrize('exchange,d1,d2,funding_times', [ + ( + 'binance', + "2021-09-01 00:00:00", + "2021-09-01 08:00:00", + ["2021-09-01 00", "2021-09-01 08"] + ), + ('binance', "2021-09-01 00:00:15", "2021-09-01 08:00:00", ["2021-09-01 00", "2021-09-01 08"]), + ('binance', "2021-09-01 00:00:16", "2021-09-01 08:00:00", ["2021-09-01 08"]), + ('binance', "2021-09-01 00:00:00", "2021-09-01 07:59:59", ["2021-09-01 00"]), + ('binance', "2021-09-01 00:00:00", "2021-09-01 12:00:00", ["2021-09-01 00", "2021-09-01 08"]), + ( + 'binance', + "2021-09-01 00:00:01", + "2021-09-01 08:00:00", + ["2021-09-01 00", "2021-09-01 08"] + ), + ( + 'kraken', + "2021-09-01 00:00:00", + "2021-09-01 08:00:00", + ["2021-09-01 00", "2021-09-01 04", "2021-09-01 08"] + ), + ( + 'kraken', + "2021-09-01 00:00:15", + "2021-09-01 08:00:00", + ["2021-09-01 04", "2021-09-01 08"] + ), + ( + 'kraken', + "2021-09-01 00:00:00", + "2021-09-01 07:59:59", + ["2021-09-01 00", "2021-09-01 04"] + ), + ( + 'kraken', + "2021-09-01 00:00:00", + "2021-09-01 12:00:00", + ["2021-09-01 00", "2021-09-01 04", "2021-09-01 08", "2021-09-01 12"] + ), + ( + 'kraken', + "2021-09-01 00:00:01", + "2021-09-01 08:00:00", + ["2021-09-01 04", "2021-09-01 08"] + ), + ( + 'ftx', + "2021-09-01 00:00:00", + "2021-09-01 08:00:00", + [ + "2021-09-01 00", + "2021-09-01 01", + "2021-09-01 02", + "2021-09-01 03", + "2021-09-01 04", + "2021-09-01 05", + "2021-09-01 06", + "2021-09-01 07", + "2021-09-01 08" + ] + ), + ( + 'ftx', + "2021-09-01 00:00:00", + "2021-09-01 12:00:00", + [ + "2021-09-01 00", + "2021-09-01 01", + "2021-09-01 02", + "2021-09-01 03", + "2021-09-01 04", + "2021-09-01 05", + "2021-09-01 06", + "2021-09-01 07", + "2021-09-01 08", + "2021-09-01 09", + "2021-09-01 10", + "2021-09-01 11", + "2021-09-01 12" + ] + ), + ( + 'ftx', + "2021-09-01 00:00:01", + "2021-09-01 08:00:00", + [ + "2021-09-01 01", + "2021-09-01 02", + "2021-09-01 03", + "2021-09-01 04", + "2021-09-01 05", + "2021-09-01 06", + "2021-09-01 07", + "2021-09-01 08" + ] + ), + ('gateio', "2021-09-01 00:00:00", "2021-09-01 08:00:00", ["2021-09-01 00", "2021-09-01 08"]), + ('gateio', "2021-09-01 00:00:00", "2021-09-01 12:00:00", ["2021-09-01 00", "2021-09-01 08"]), + ('gateio', "2021-09-01 00:00:01", "2021-09-01 08:00:00", ["2021-09-01 08"]), ]) -def test__get_funding_fee_dates(exchange, d1, d2): - return +def test__get_funding_fee_dates(mocker, default_conf, exchange, d1, d2, funding_times): + expected_result = [datetime.strptime(d, '%Y-%m-%d %H') for d in funding_times] + d1 = datetime.strptime(d1, '%Y-%m-%d %H:%M:%S') + d2 = datetime.strptime(d2, '%Y-%m-%d %H:%M:%S') + exchange = get_patched_exchange(mocker, default_conf, id=exchange) + result = exchange._get_funding_fee_dates(d1, d2) + assert result == expected_result def test__get_mark_price_history(mocker, default_conf, mark_ohlcv):