From 33482aab83cd69083de7781a2e7ebc81a5391723 Mon Sep 17 00:00:00 2001 From: andrgit Date: Fri, 26 Aug 2022 14:13:34 +0200 Subject: [PATCH 01/14] Add test_exchange_info --- integration_tests/rest/test_exchange_info.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 integration_tests/rest/test_exchange_info.py diff --git a/integration_tests/rest/test_exchange_info.py b/integration_tests/rest/test_exchange_info.py new file mode 100644 index 0000000..be7cc0b --- /dev/null +++ b/integration_tests/rest/test_exchange_info.py @@ -0,0 +1,4 @@ +class TestExchangeInfo: + def test_get_exchange_info(self, client): + exchange_info = client.get_exchange_info() + assert len(exchange_info['symbols']) > 0, "We didn't get exchange information" From 6525b6cf9e3572be5e24d880f834b3c490935d84 Mon Sep 17 00:00:00 2001 From: andrgit Date: Fri, 26 Aug 2022 19:58:38 +0200 Subject: [PATCH 02/14] update test_exchange_info, add second condition --- integration_tests/rest/test_exchange_info.py | 5 +++-- integration_tests/rest/test_klines.py | 0 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 integration_tests/rest/test_klines.py diff --git a/integration_tests/rest/test_exchange_info.py b/integration_tests/rest/test_exchange_info.py index be7cc0b..a58bed1 100644 --- a/integration_tests/rest/test_exchange_info.py +++ b/integration_tests/rest/test_exchange_info.py @@ -1,4 +1,5 @@ class TestExchangeInfo: - def test_get_exchange_info(self, client): + def test_get_exchange_info_symbols(self, client): exchange_info = client.get_exchange_info() - assert len(exchange_info['symbols']) > 0, "We didn't get exchange information" + assert len(exchange_info['symbols']) > 0, "We didn't get exchange information - Symbols " + assert len(exchange_info['rateLimits']) > 0, "We didn't get exchange information - rateLimits" diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py new file mode 100644 index 0000000..e69de29 From f8fc0a5cd314a16bbfacd0b580bad0b39f5441cb Mon Sep 17 00:00:00 2001 From: andrgit Date: Fri, 26 Aug 2022 20:01:07 +0200 Subject: [PATCH 03/14] update test_exchange_info --- integration_tests/rest/test_exchange_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/rest/test_exchange_info.py b/integration_tests/rest/test_exchange_info.py index a58bed1..ec6acfb 100644 --- a/integration_tests/rest/test_exchange_info.py +++ b/integration_tests/rest/test_exchange_info.py @@ -1,5 +1,5 @@ class TestExchangeInfo: - def test_get_exchange_info_symbols(self, client): + def test_get_exchange_info(self, client): exchange_info = client.get_exchange_info() assert len(exchange_info['symbols']) > 0, "We didn't get exchange information - Symbols " assert len(exchange_info['rateLimits']) > 0, "We didn't get exchange information - rateLimits" From acedfab196cc453b19b07b1cbd54d39457e66d1f Mon Sep 17 00:00:00 2001 From: andrgit Date: Sat, 27 Aug 2022 00:28:21 +0200 Subject: [PATCH 04/14] add test klines --- integration_tests/rest/test_klines.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index e69de29..4ef0087 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -0,0 +1,30 @@ +from currencycom import constants +from currencycom.client import CandlesticksChartIntervals + + +class TestKlines: + def test_get_klines_max_limit_interval_minute(self, client): + klines_meta = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals.MINUTE, + limit=constants.CurrencycomConstants.KLINES_MAX_LIMIT) + assert len(klines_meta) > 0, "We didn't get any information about " + assert isinstance(klines_meta[0][0], + int), "We get wrong information from klines(open time), we should get int" + + def test_get_klines_fiften_minutes_min_stock_limit(self, client): + klines_nzd_jpy = client.get_klines(symbol="NZD/JPY_LEVERAGE", + interval=CandlesticksChartIntervals.FIFTEEN_MINUTES) + assert len(klines_nzd_jpy) > 0, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" + assert isinstance(klines_nzd_jpy[0][0], + int), "We get wrong information from klines(open time), we should get int" + + def test_get_klines_week_limit_min(self, client): + klines_nzd_jpy = client.get_klines(symbol="AOS.", interval=CandlesticksChartIntervals.WEEK, + limit=1) + # Here we get only 1 list,with 6 values, Open time, open, high, low, close, volume + assert len(klines_nzd_jpy) == 1, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" + assert isinstance(klines_nzd_jpy[0][0], + int), "We get wrong information from klines(open time), we should get int" + + def test_get_klines_negative_day(self, client): + klines = client.get_klines(symbol="TEST", interval=CandlesticksChartIntervals.DAY) + assert klines['code'] == -1128, "The negative test has problem with klines['code'] == -1128" From 85bffa4293d4f70eaf7415210332502a5d5fb6d6 Mon Sep 17 00:00:00 2001 From: andrgit Date: Sat, 27 Aug 2022 16:00:05 +0200 Subject: [PATCH 05/14] Revert "add test klines" This reverts commit acedfab196cc453b19b07b1cbd54d39457e66d1f. --- integration_tests/rest/test_klines.py | 30 --------------------------- 1 file changed, 30 deletions(-) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index 4ef0087..e69de29 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -1,30 +0,0 @@ -from currencycom import constants -from currencycom.client import CandlesticksChartIntervals - - -class TestKlines: - def test_get_klines_max_limit_interval_minute(self, client): - klines_meta = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals.MINUTE, - limit=constants.CurrencycomConstants.KLINES_MAX_LIMIT) - assert len(klines_meta) > 0, "We didn't get any information about " - assert isinstance(klines_meta[0][0], - int), "We get wrong information from klines(open time), we should get int" - - def test_get_klines_fiften_minutes_min_stock_limit(self, client): - klines_nzd_jpy = client.get_klines(symbol="NZD/JPY_LEVERAGE", - interval=CandlesticksChartIntervals.FIFTEEN_MINUTES) - assert len(klines_nzd_jpy) > 0, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" - assert isinstance(klines_nzd_jpy[0][0], - int), "We get wrong information from klines(open time), we should get int" - - def test_get_klines_week_limit_min(self, client): - klines_nzd_jpy = client.get_klines(symbol="AOS.", interval=CandlesticksChartIntervals.WEEK, - limit=1) - # Here we get only 1 list,with 6 values, Open time, open, high, low, close, volume - assert len(klines_nzd_jpy) == 1, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" - assert isinstance(klines_nzd_jpy[0][0], - int), "We get wrong information from klines(open time), we should get int" - - def test_get_klines_negative_day(self, client): - klines = client.get_klines(symbol="TEST", interval=CandlesticksChartIntervals.DAY) - assert klines['code'] == -1128, "The negative test has problem with klines['code'] == -1128" From aaf0fd6b419aa6a352a43d1b9fde48a493bea715 Mon Sep 17 00:00:00 2001 From: andrgit Date: Sat, 27 Aug 2022 16:01:50 +0200 Subject: [PATCH 06/14] Revert "Revert "add test klines"" This reverts commit 85bffa4293d4f70eaf7415210332502a5d5fb6d6. --- integration_tests/rest/test_klines.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index e69de29..4ef0087 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -0,0 +1,30 @@ +from currencycom import constants +from currencycom.client import CandlesticksChartIntervals + + +class TestKlines: + def test_get_klines_max_limit_interval_minute(self, client): + klines_meta = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals.MINUTE, + limit=constants.CurrencycomConstants.KLINES_MAX_LIMIT) + assert len(klines_meta) > 0, "We didn't get any information about " + assert isinstance(klines_meta[0][0], + int), "We get wrong information from klines(open time), we should get int" + + def test_get_klines_fiften_minutes_min_stock_limit(self, client): + klines_nzd_jpy = client.get_klines(symbol="NZD/JPY_LEVERAGE", + interval=CandlesticksChartIntervals.FIFTEEN_MINUTES) + assert len(klines_nzd_jpy) > 0, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" + assert isinstance(klines_nzd_jpy[0][0], + int), "We get wrong information from klines(open time), we should get int" + + def test_get_klines_week_limit_min(self, client): + klines_nzd_jpy = client.get_klines(symbol="AOS.", interval=CandlesticksChartIntervals.WEEK, + limit=1) + # Here we get only 1 list,with 6 values, Open time, open, high, low, close, volume + assert len(klines_nzd_jpy) == 1, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" + assert isinstance(klines_nzd_jpy[0][0], + int), "We get wrong information from klines(open time), we should get int" + + def test_get_klines_negative_day(self, client): + klines = client.get_klines(symbol="TEST", interval=CandlesticksChartIntervals.DAY) + assert klines['code'] == -1128, "The negative test has problem with klines['code'] == -1128" From 8caff452e74d4f8304d3492f660714ff55b1916a Mon Sep 17 00:00:00 2001 From: andrgit Date: Sat, 27 Aug 2022 16:34:52 +0200 Subject: [PATCH 07/14] Deleted test_exchange_info.py --- integration_tests/rest/test_exchange_info.py | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 integration_tests/rest/test_exchange_info.py diff --git a/integration_tests/rest/test_exchange_info.py b/integration_tests/rest/test_exchange_info.py deleted file mode 100644 index ec6acfb..0000000 --- a/integration_tests/rest/test_exchange_info.py +++ /dev/null @@ -1,5 +0,0 @@ -class TestExchangeInfo: - def test_get_exchange_info(self, client): - exchange_info = client.get_exchange_info() - assert len(exchange_info['symbols']) > 0, "We didn't get exchange information - Symbols " - assert len(exchange_info['rateLimits']) > 0, "We didn't get exchange information - rateLimits" From 21904a30c3fb40b43a85282c742de42085faed71 Mon Sep 17 00:00:00 2001 From: andrgit Date: Sun, 28 Aug 2022 22:16:29 +0200 Subject: [PATCH 08/14] changed line length to 79 chars --- integration_tests/rest/test_klines.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index 4ef0087..dd0bc91 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -3,6 +3,7 @@ class TestKlines: + #TODO cделать ширину строки 79 символов def test_get_klines_max_limit_interval_minute(self, client): klines_meta = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals.MINUTE, limit=constants.CurrencycomConstants.KLINES_MAX_LIMIT) From 94a2f7dcb38148e43500ae41f6bbfd57d8d93898 Mon Sep 17 00:00:00 2001 From: andrgit Date: Mon, 29 Aug 2022 23:13:55 +0200 Subject: [PATCH 09/14] updated test_klines --- integration_tests/rest/test_klines.py | 109 +++++++++++++++++++++----- 1 file changed, 88 insertions(+), 21 deletions(-) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index dd0bc91..7bc564f 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -1,31 +1,98 @@ +from datetime import datetime, timedelta + +import pytest + from currencycom import constants from currencycom.client import CandlesticksChartIntervals class TestKlines: - #TODO cделать ширину строки 79 символов + values = [60, 90, 120, 360, 999, 1000] + old_dates = [datetime(1970, 1, 1, 0, 33), datetime(1965, 3, 1, 16, 48), + datetime(1945, 9, 1, 6, 55)] + def test_get_klines_max_limit_interval_minute(self, client): - klines_meta = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals.MINUTE, - limit=constants.CurrencycomConstants.KLINES_MAX_LIMIT) - assert len(klines_meta) > 0, "We didn't get any information about " - assert isinstance(klines_meta[0][0], - int), "We get wrong information from klines(open time), we should get int" + klines = client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + MINUTE, + limit=constants.CurrencycomConstants. + KLINES_MAX_LIMIT) + assert len(klines) > 0, "We didn't get any information about " + assert isinstance(klines, list) + assert isinstance(klines[0][0], + int), "We get wrong information " \ + "from klines(open time), we should get int" + assert all(isinstance(i, list) for i in klines) def test_get_klines_fiften_minutes_min_stock_limit(self, client): - klines_nzd_jpy = client.get_klines(symbol="NZD/JPY_LEVERAGE", - interval=CandlesticksChartIntervals.FIFTEEN_MINUTES) - assert len(klines_nzd_jpy) > 0, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" - assert isinstance(klines_nzd_jpy[0][0], - int), "We get wrong information from klines(open time), we should get int" + klines = client.get_klines(symbol="NZD/JPY_LEVERAGE", + interval=CandlesticksChartIntervals. + FIFTEEN_MINUTES) + assert len( + klines) > 0, f"We didn't get ant information " \ + f"about klines/candlestick NZD/JPY_LEVERAGE" + assert isinstance(klines, list) + assert isinstance(klines[0][0], + int), "We get wrong information " \ + "from klines(open time), we should get int" + assert all(isinstance(i, list) for i in klines) def test_get_klines_week_limit_min(self, client): - klines_nzd_jpy = client.get_klines(symbol="AOS.", interval=CandlesticksChartIntervals.WEEK, - limit=1) - # Here we get only 1 list,with 6 values, Open time, open, high, low, close, volume - assert len(klines_nzd_jpy) == 1, f"We didn't get ant information about klines/candlestick NZD/JPY_LEVERAGE" - assert isinstance(klines_nzd_jpy[0][0], - int), "We get wrong information from klines(open time), we should get int" - - def test_get_klines_negative_day(self, client): - klines = client.get_klines(symbol="TEST", interval=CandlesticksChartIntervals.DAY) - assert klines['code'] == -1128, "The negative test has problem with klines['code'] == -1128" + klines = client.get_klines(symbol="AOS.", + interval=CandlesticksChartIntervals. + WEEK, + limit=1) + assert len( + klines) == 1, f"We didn't get ant information " \ + f"about klines/candlestick NZD/JPY_LEVERAGE" + assert isinstance(klines[0][0], + int), "We get wrong information " \ + "from klines(open time), we should get int" + assert isinstance(klines, list) + assert all(isinstance(i, list) for i in klines) + + def test_get_klines_negative_symbol(self, client): + klines = client.get_klines(symbol="TEST", + interval=CandlesticksChartIntervals.DAY) + assert klines[ + 'code'] == -1128, "The negative test has problem " \ + "with klines['code'] == -1128" + assert 'Invalid symbol:' in klines['msg'] + + def test_get_klines_negative_limit_minus(self, client): + klines = client.get_klines(symbol="META.", + interval=CandlesticksChartIntervals.HOUR, + limit=-500) + assert klines['code'] == -1128, "The test has problem with -500 limit" + assert klines['msg'] == 'Invalid limit parameter' + + def test_get_klines_negative_limit_float(self, client): + klines = client.get_klines(symbol="META.", + interval=CandlesticksChartIntervals.MINUTE, + limit=400.5) + assert klines['code'] == -1128, "The test has problem with -500 limit" + assert klines['msg'] == 'Combination of parameters invalid' + + def test_get_klines_negative_limit_str(self, client): + with pytest.raises(TypeError): + client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + FIFTEEN_MINUTES, limit='ups') + + def test_get_klines_negative_limit_more_max(self, client): + with pytest.raises(ValueError): + client.get_agg_trades(symbol='EUR/USD_LEVERAGE', limit=1001) + + def test_get_klines_negative_with_interval(self, client): + klines = client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + THIRTY_MINUTES, ) + + @pytest.mark.parametrize('minutes', values) + def test_start_time_in_future(self, client, minutes): + dttm_now_plus = datetime.now() + timedelta(minutes=minutes) + klines = client.get_klines(symbol='EUR/USD_LEVERAGE', + interval=CandlesticksChartIntervals. + FIVE_MINUTES, + start_time=dttm_now_plus) + assert len(klines) == 0 From 7eb545e331c51ba153aa66097fc5fac49eb99a4a Mon Sep 17 00:00:00 2001 From: andrgit Date: Thu, 1 Sep 2022 14:05:18 +0200 Subject: [PATCH 10/14] changed all test,add test interval,limit --- integration_tests/rest/test_klines.py | 129 +++++++++----------------- 1 file changed, 44 insertions(+), 85 deletions(-) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index 7bc564f..1a32818 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -1,3 +1,5 @@ +import sys +import time from datetime import datetime, timedelta import pytest @@ -7,92 +9,49 @@ class TestKlines: - values = [60, 90, 120, 360, 999, 1000] - old_dates = [datetime(1970, 1, 1, 0, 33), datetime(1965, 3, 1, 16, 48), - datetime(1945, 9, 1, 6, 55)] + values = [1, 59, 99, 101, 500, 999, 1000] - def test_get_klines_max_limit_interval_minute(self, client): + def test_klines_check_interval_pos(self, client): klines = client.get_klines(symbol='META.', - interval=CandlesticksChartIntervals. - MINUTE, - limit=constants.CurrencycomConstants. - KLINES_MAX_LIMIT) - assert len(klines) > 0, "We didn't get any information about " - assert isinstance(klines, list) - assert isinstance(klines[0][0], - int), "We get wrong information " \ - "from klines(open time), we should get int" - assert all(isinstance(i, list) for i in klines) - - def test_get_klines_fiften_minutes_min_stock_limit(self, client): - klines = client.get_klines(symbol="NZD/JPY_LEVERAGE", - interval=CandlesticksChartIntervals. - FIFTEEN_MINUTES) - assert len( - klines) > 0, f"We didn't get ant information " \ - f"about klines/candlestick NZD/JPY_LEVERAGE" - assert isinstance(klines, list) - assert isinstance(klines[0][0], - int), "We get wrong information " \ - "from klines(open time), we should get int" - assert all(isinstance(i, list) for i in klines) - - def test_get_klines_week_limit_min(self, client): - klines = client.get_klines(symbol="AOS.", - interval=CandlesticksChartIntervals. - WEEK, - limit=1) - assert len( - klines) == 1, f"We didn't get ant information " \ - f"about klines/candlestick NZD/JPY_LEVERAGE" - assert isinstance(klines[0][0], - int), "We get wrong information " \ - "from klines(open time), we should get int" - assert isinstance(klines, list) - assert all(isinstance(i, list) for i in klines) - - def test_get_klines_negative_symbol(self, client): - klines = client.get_klines(symbol="TEST", - interval=CandlesticksChartIntervals.DAY) - assert klines[ - 'code'] == -1128, "The negative test has problem " \ - "with klines['code'] == -1128" - assert 'Invalid symbol:' in klines['msg'] - - def test_get_klines_negative_limit_minus(self, client): - klines = client.get_klines(symbol="META.", - interval=CandlesticksChartIntervals.HOUR, - limit=-500) - assert klines['code'] == -1128, "The test has problem with -500 limit" - assert klines['msg'] == 'Invalid limit parameter' - - def test_get_klines_negative_limit_float(self, client): - klines = client.get_klines(symbol="META.", interval=CandlesticksChartIntervals.MINUTE, - limit=400.5) - assert klines['code'] == -1128, "The test has problem with -500 limit" - assert klines['msg'] == 'Combination of parameters invalid' - - def test_get_klines_negative_limit_str(self, client): - with pytest.raises(TypeError): - client.get_klines(symbol='META.', - interval=CandlesticksChartIntervals. - FIFTEEN_MINUTES, limit='ups') - - def test_get_klines_negative_limit_more_max(self, client): - with pytest.raises(ValueError): - client.get_agg_trades(symbol='EUR/USD_LEVERAGE', limit=1001) - - def test_get_klines_negative_with_interval(self, client): + limit=10) + + count = 0 + prev_value = None + for op_time in klines: + assert op_time[0] % 60000 == 0 # and + if count > 0: + assert op_time[0] - prev_value == 60000 + prev_value = op_time[0] + count += 1 + + @pytest.mark.parametrize('limit', + [1, 500, 999, 1000]) + def test_get_klines_limits_pos(self, client, limit): + """ + Проверяем количество лимитов и количество полученных значений + """ klines = client.get_klines(symbol='META.', - interval=CandlesticksChartIntervals. - THIRTY_MINUTES, ) - - @pytest.mark.parametrize('minutes', values) - def test_start_time_in_future(self, client, minutes): - dttm_now_plus = datetime.now() + timedelta(minutes=minutes) - klines = client.get_klines(symbol='EUR/USD_LEVERAGE', - interval=CandlesticksChartIntervals. - FIVE_MINUTES, - start_time=dttm_now_plus) - assert len(klines) == 0 + interval=CandlesticksChartIntervals.MINUTE, + limit=limit) + assert len(klines) == limit + + @pytest.mark.parametrize('limit', + [float('inf'), float('-inf'), -1, 0, 1001, + sys.maxsize, -sys.maxsize]) + def test_get_klines_limits_neg(self, client, limit): + """ + Проверяем количество лимитов и количество полученных значений + """ + if limit <= 0: + klines = client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + FIFTEEN_MINUTES, + limit=limit) + assert klines['code'] == -1128 + else: + with pytest.raises(ValueError): + client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + FIFTEEN_MINUTES, + limit=limit) From 58a7388ea645e59703d3d2310c7332f35da77b58 Mon Sep 17 00:00:00 2001 From: andrgit Date: Fri, 2 Sep 2022 23:54:48 +0200 Subject: [PATCH 11/14] refixed functions,made base test,interval test,limit test --- integration_tests/rest/test_klines.py | 71 ++++++++++++++++----------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index 1a32818..4c3e3d7 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -1,7 +1,8 @@ +import functools +import itertools import sys import time from datetime import datetime, timedelta - import pytest from currencycom import constants @@ -11,22 +12,31 @@ class TestKlines: values = [1, 59, 99, 101, 500, 999, 1000] - def test_klines_check_interval_pos(self, client): - klines = client.get_klines(symbol='META.', - interval=CandlesticksChartIntervals.MINUTE, - limit=10) + def test_klines_base_check(self, client): + klines = client.get_klines(symbol='GOOGL.', + interval=CandlesticksChartIntervals + .MINUTE) + assert len(klines) > 0 + assert all(len(i) == 6 for i in klines) - count = 0 - prev_value = None - for op_time in klines: - assert op_time[0] % 60000 == 0 # and - if count > 0: - assert op_time[0] - prev_value == 60000 - prev_value = op_time[0] - count += 1 + @pytest.mark.parametrize("interval, minutes", [ + (CandlesticksChartIntervals.MINUTE, 1), + (CandlesticksChartIntervals.FIVE_MINUTES, 5), + (CandlesticksChartIntervals.FIFTEEN_MINUTES, 15), + (CandlesticksChartIntervals.THIRTY_MINUTES, 30), + (CandlesticksChartIntervals.HOUR, 60), + (CandlesticksChartIntervals.FOUR_HOURS, 240), + (CandlesticksChartIntervals.DAY, 1440), + (CandlesticksChartIntervals.WEEK, 10080), + ]) + def test_klines_check_interval_pos(self, client, interval, minutes): + klines = client.get_klines(symbol='META.', + interval=interval) + assert all(val[0] % 60000 == 0 for val in klines) + assert (klines[i + 1][0] - klines[i][0] == (minutes * 60000) for i in + range(len(klines) - 1)) - @pytest.mark.parametrize('limit', - [1, 500, 999, 1000]) + @pytest.mark.parametrize('limit', [1, 500, 999, 1000]) def test_get_klines_limits_pos(self, client, limit): """ Проверяем количество лимитов и количество полученных значений @@ -37,21 +47,22 @@ def test_get_klines_limits_pos(self, client, limit): assert len(klines) == limit @pytest.mark.parametrize('limit', - [float('inf'), float('-inf'), -1, 0, 1001, - sys.maxsize, -sys.maxsize]) - def test_get_klines_limits_neg(self, client, limit): + [float('inf'), 1001, sys.maxsize]) + def test_get_klines_limits_neg_plus(self, client, limit): """ Проверяем количество лимитов и количество полученных значений """ - if limit <= 0: - klines = client.get_klines(symbol='META.', - interval=CandlesticksChartIntervals. - FIFTEEN_MINUTES, - limit=limit) - assert klines['code'] == -1128 - else: - with pytest.raises(ValueError): - client.get_klines(symbol='META.', - interval=CandlesticksChartIntervals. - FIFTEEN_MINUTES, - limit=limit) + with pytest.raises(ValueError): + client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + FIFTEEN_MINUTES, + limit=limit) + + @pytest.mark.parametrize('limit', + [float('-inf'), -1, 0, -sys.maxsize]) + def test_get_klines_limits_neg_minus(self, client, limit): + klines = client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + FIFTEEN_MINUTES, + limit=limit) + assert klines['code'] == -1128 From 1b0e0ae23cbb45eb97d1310f8f2c0f3f004fde34 Mon Sep 17 00:00:00 2001 From: andrgit Date: Sat, 3 Sep 2022 11:05:13 +0200 Subject: [PATCH 12/14] fix some bugs --- integration_tests/rest/test_klines.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index 4c3e3d7..91aec5b 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -12,7 +12,7 @@ class TestKlines: values = [1, 59, 99, 101, 500, 999, 1000] - def test_klines_base_check(self, client): + def test_base_check(self, client): klines = client.get_klines(symbol='GOOGL.', interval=CandlesticksChartIntervals .MINUTE) @@ -29,17 +29,21 @@ def test_klines_base_check(self, client): (CandlesticksChartIntervals.DAY, 1440), (CandlesticksChartIntervals.WEEK, 10080), ]) - def test_klines_check_interval_pos(self, client, interval, minutes): - klines = client.get_klines(symbol='META.', + def test_check_interval_and_accordance_between_get_klines(self, client, + interval, + minutes): + klines = client.get_klines(symbol='ETH/USD_LEVERAGE', interval=interval) assert all(val[0] % 60000 == 0 for val in klines) assert (klines[i + 1][0] - klines[i][0] == (minutes * 60000) for i in range(len(klines) - 1)) @pytest.mark.parametrize('limit', [1, 500, 999, 1000]) - def test_get_klines_limits_pos(self, client, limit): + def test_check_valid_limits(self, client, limit): """ - Проверяем количество лимитов и количество полученных значений + Позитивный тест + Сравниваем что количество запрашиваемых и полученных значений лимита + равны. """ klines = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals.MINUTE, @@ -48,9 +52,11 @@ def test_get_klines_limits_pos(self, client, limit): @pytest.mark.parametrize('limit', [float('inf'), 1001, sys.maxsize]) - def test_get_klines_limits_neg_plus(self, client, limit): + def test_check_limits_more_max_limit(self, client, limit): """ - Проверяем количество лимитов и количество полученных значений + Негативный тест. + Проверяем что значения превышающие максимальный лимит больше 1000 + не работают. """ with pytest.raises(ValueError): client.get_klines(symbol='META.', @@ -60,7 +66,11 @@ def test_get_klines_limits_neg_plus(self, client, limit): @pytest.mark.parametrize('limit', [float('-inf'), -1, 0, -sys.maxsize]) - def test_get_klines_limits_neg_minus(self, client, limit): + def test_check_limits_less_1(self, client, limit): + """ + Негативный тест. + Проверяем что значения ниже минимального лимита 1 не работают. + """ klines = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals. FIFTEEN_MINUTES, From be87e12925aea185b0dd466b75f97521a1f9adb7 Mon Sep 17 00:00:00 2001 From: andrgit Date: Mon, 5 Sep 2022 10:21:29 +0200 Subject: [PATCH 13/14] Add tests start_time and end_time --- integration_tests/rest/test_klines.py | 40 +++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index 91aec5b..2c0ad94 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -10,6 +10,13 @@ class TestKlines: + date_values = [ + datetime(1970, 1, 3), + datetime(1970, 1, 3, 0, 1), + datetime(2019, 1, 1), + datetime.now() - timedelta(minutes=1), + datetime.now() + ] values = [1, 59, 99, 101, 500, 999, 1000] def test_base_check(self, client): @@ -41,7 +48,8 @@ def test_check_interval_and_accordance_between_get_klines(self, client, @pytest.mark.parametrize('limit', [1, 500, 999, 1000]) def test_check_valid_limits(self, client, limit): """ - Позитивный тест + Positive test + Check get counts Сравниваем что количество запрашиваемых и полученных значений лимита равны. """ @@ -51,12 +59,11 @@ def test_check_valid_limits(self, client, limit): assert len(klines) == limit @pytest.mark.parametrize('limit', - [float('inf'), 1001, sys.maxsize]) + [1001, sys.maxsize]) def test_check_limits_more_max_limit(self, client, limit): """ - Негативный тест. - Проверяем что значения превышающие максимальный лимит больше 1000 - не работают. + Negative test. + Check values > max limit(1000) """ with pytest.raises(ValueError): client.get_klines(symbol='META.', @@ -65,14 +72,31 @@ def test_check_limits_more_max_limit(self, client, limit): limit=limit) @pytest.mark.parametrize('limit', - [float('-inf'), -1, 0, -sys.maxsize]) + [-1, 0, -sys.maxsize]) def test_check_limits_less_1(self, client, limit): """ - Негативный тест. - Проверяем что значения ниже минимального лимита 1 не работают. + Negative test + Check values < min limit(1) """ klines = client.get_klines(symbol='META.', interval=CandlesticksChartIntervals. FIFTEEN_MINUTES, limit=limit) assert klines['code'] == -1128 + + @pytest.mark.parametrize('date_val', date_values) + def test_start_time_valid(self, client, date_val): + klines = client.get_klines(symbol='GOOGL.', + interval=CandlesticksChartIntervals.HOUR, + start_time=date_val) + date_ago_timestamp = date_val.timestamp() + assert all(date[0] / 1000 >= date_ago_timestamp for date in klines) + + @pytest.mark.parametrize('date_val', date_values) + def test_end_time_valid(self, client, date_val): + klines = client.get_klines(symbol='DBK.', + interval=CandlesticksChartIntervals. + FIFTEEN_MINUTES, end_time=date_val) + date_ago_timestamp = date_val.timestamp() + assert all(date[0] / 1000 <= date_ago_timestamp for date in klines) + From 9b0e39436f080091705b7921dc046d16a0c93c47 Mon Sep 17 00:00:00 2001 From: andrgit Date: Mon, 5 Sep 2022 11:42:04 +0200 Subject: [PATCH 14/14] Add tests: wrong_symbol, start_time_in_future,end_time_less_then_start_time --- integration_tests/rest/test_klines.py | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/integration_tests/rest/test_klines.py b/integration_tests/rest/test_klines.py index 2c0ad94..8b85c3d 100644 --- a/integration_tests/rest/test_klines.py +++ b/integration_tests/rest/test_klines.py @@ -100,3 +100,32 @@ def test_end_time_valid(self, client, date_val): date_ago_timestamp = date_val.timestamp() assert all(date[0] / 1000 <= date_ago_timestamp for date in klines) + def test_wrong_symbol(self, client): + klines = client.get_klines(symbol='TEST', + interval=CandlesticksChartIntervals. + THIRTY_MINUTES) + assert 'Invalid symbol' in klines['msg'] + assert klines['code'] == -1128 + + @pytest.mark.parametrize('date_future', + [datetime.now() + timedelta(minutes=1), + datetime(3001, 1, 3)]) + def test_start_time_future(self, client, date_future): + klines = client.get_klines(symbol='META.', + interval=CandlesticksChartIntervals. + FOUR_HOURS, start_time=date_future) + assert len(klines) == 0 + + @pytest.mark.parametrize('seconds', + [1, 214748379, 214748380]) + def test_end_time_less_then_start_time(self, client, seconds): + dttm_start = datetime.now() - timedelta(days=1) + dttm_end = dttm_start - timedelta(seconds=seconds) + klines = client.get_klines( + symbol='EUR/USD_LEVERAGE', + interval=CandlesticksChartIntervals.FIVE_MINUTES, + start_time=dttm_start, + end_time=dttm_end + ) + assert klines['msg'] == 'endTime should be greater than startTime.' + assert klines['code'] == -1128