From 4a6f7ac4863d69eed135a44df7571abbee2f2da7 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Fri, 2 Sep 2022 12:45:58 +0300 Subject: [PATCH 01/11] Added test_24h_price_change.py --- .../rest/test_24h_price_change.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 integration_tests/rest/test_24h_price_change.py diff --git a/integration_tests/rest/test_24h_price_change.py b/integration_tests/rest/test_24h_price_change.py new file mode 100644 index 0000000..55e116e --- /dev/null +++ b/integration_tests/rest/test_24h_price_change.py @@ -0,0 +1,21 @@ +class Test24hPriceChange: + + def test_response_corresponds_swagger_schema(self, client): + resp_keys = [ + 'symbol', 'priceChange', 'priceChangePercent', + 'weightedAvgPrice', 'prevClosePrice', 'lastPrice', + 'lastQty', 'bidPrice', 'askPrice', + 'openPrice', 'highPrice', 'lowPrice', + 'volume', 'quoteVolume', 'openTime', 'closeTime' + ] + price_changes = client.get_24h_price_change('GBP/USD_LEVERAGE') + assert type(price_changes) is dict + assert len(price_changes) > 0 + assert all(dct in resp_keys for dct in price_changes.keys()) + assert all(price_changes[key] is not None for key in + price_changes.keys()) + + def test_wrong_symbol(self, client): + price_changes = client.get_24h_price_change(symbol="TEST123") + assert price_changes['code'] == -1128 and 'symbol not found ' \ + in price_changes['msg'] From 05fb61f9f7243f3707fa94281cc42f11c19a5d1d Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Sat, 3 Sep 2022 10:48:03 +0300 Subject: [PATCH 02/11] Added test_order_book.py --- integration_tests/rest/test_order_book.py | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 integration_tests/rest/test_order_book.py diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py new file mode 100644 index 0000000..b0da212 --- /dev/null +++ b/integration_tests/rest/test_order_book.py @@ -0,0 +1,33 @@ +import sys +import pytest + + +class TestOrderBook: + + def test_response_corresponds_swagger_schema(self, client): + resp_keys = ['asks', 'bids', 'lastUpdateId'] + order_book = client.get_order_book('EUR/USD_LEVERAGE') + assert type(order_book) is dict + assert len(order_book) == 3 + assert all(dct in resp_keys for dct in order_book.keys()) + assert all(order_book[key] is not None for key in order_book.keys()) + + @pytest.mark.xfail + @pytest.mark.parametrize('limit', [5, 10, 20, 50, 100, 500, 1000]) + def test_limit(self, client, limit): + order_book = client.get_order_book('GBP/USD_LEVERAGE', limit=limit) + assert len(order_book['asks']) == limit + assert len(order_book['bids']) == limit + + @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, 1, 506, 999, + 1001, sys.maxsize]) + def test_invalid_limit(self, client, limit): + with pytest.raises(ValueError): + client.get_order_book('EUR/USD_LEVERAGE', limit=limit) + + def test_wrong_symbol(self, client): + agg_trades = client.get_order_book(symbol="TEST123") + assert agg_trades['code'] == -1128 and 'symbol not found ' \ + in agg_trades['msg'] + + From 035ac9f2db427b8906f17004130e7cbaf2c2abb8 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Sat, 3 Sep 2022 11:11:19 +0300 Subject: [PATCH 03/11] =?UTF-8?q?Added=2024=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- integration_tests/rest/test_order_book.py | 33 ----------------------- 1 file changed, 33 deletions(-) delete mode 100644 integration_tests/rest/test_order_book.py diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py deleted file mode 100644 index b0da212..0000000 --- a/integration_tests/rest/test_order_book.py +++ /dev/null @@ -1,33 +0,0 @@ -import sys -import pytest - - -class TestOrderBook: - - def test_response_corresponds_swagger_schema(self, client): - resp_keys = ['asks', 'bids', 'lastUpdateId'] - order_book = client.get_order_book('EUR/USD_LEVERAGE') - assert type(order_book) is dict - assert len(order_book) == 3 - assert all(dct in resp_keys for dct in order_book.keys()) - assert all(order_book[key] is not None for key in order_book.keys()) - - @pytest.mark.xfail - @pytest.mark.parametrize('limit', [5, 10, 20, 50, 100, 500, 1000]) - def test_limit(self, client, limit): - order_book = client.get_order_book('GBP/USD_LEVERAGE', limit=limit) - assert len(order_book['asks']) == limit - assert len(order_book['bids']) == limit - - @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, 1, 506, 999, - 1001, sys.maxsize]) - def test_invalid_limit(self, client, limit): - with pytest.raises(ValueError): - client.get_order_book('EUR/USD_LEVERAGE', limit=limit) - - def test_wrong_symbol(self, client): - agg_trades = client.get_order_book(symbol="TEST123") - assert agg_trades['code'] == -1128 and 'symbol not found ' \ - in agg_trades['msg'] - - From 7678b4aad9332e0ce65de638e070f0ac2833203c Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Sat, 3 Sep 2022 11:16:32 +0300 Subject: [PATCH 04/11] =?UTF-8?q?Added=2024=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- integration_tests/rest/test_24h_price_change.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration_tests/rest/test_24h_price_change.py b/integration_tests/rest/test_24h_price_change.py index 55e116e..2b3b945 100644 --- a/integration_tests/rest/test_24h_price_change.py +++ b/integration_tests/rest/test_24h_price_change.py @@ -19,3 +19,5 @@ def test_wrong_symbol(self, client): price_changes = client.get_24h_price_change(symbol="TEST123") assert price_changes['code'] == -1128 and 'symbol not found ' \ in price_changes['msg'] + + From 1b87f2280a5e4d4b7a00aa1527ef688ef45667e6 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Sat, 3 Sep 2022 11:22:55 +0300 Subject: [PATCH 05/11] Added test_order_book.py --- .../rest/test_24h_price_change.py | 23 ------------- integration_tests/rest/test_order_book.py | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 23 deletions(-) delete mode 100644 integration_tests/rest/test_24h_price_change.py create mode 100644 integration_tests/rest/test_order_book.py diff --git a/integration_tests/rest/test_24h_price_change.py b/integration_tests/rest/test_24h_price_change.py deleted file mode 100644 index 2b3b945..0000000 --- a/integration_tests/rest/test_24h_price_change.py +++ /dev/null @@ -1,23 +0,0 @@ -class Test24hPriceChange: - - def test_response_corresponds_swagger_schema(self, client): - resp_keys = [ - 'symbol', 'priceChange', 'priceChangePercent', - 'weightedAvgPrice', 'prevClosePrice', 'lastPrice', - 'lastQty', 'bidPrice', 'askPrice', - 'openPrice', 'highPrice', 'lowPrice', - 'volume', 'quoteVolume', 'openTime', 'closeTime' - ] - price_changes = client.get_24h_price_change('GBP/USD_LEVERAGE') - assert type(price_changes) is dict - assert len(price_changes) > 0 - assert all(dct in resp_keys for dct in price_changes.keys()) - assert all(price_changes[key] is not None for key in - price_changes.keys()) - - def test_wrong_symbol(self, client): - price_changes = client.get_24h_price_change(symbol="TEST123") - assert price_changes['code'] == -1128 and 'symbol not found ' \ - in price_changes['msg'] - - diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py new file mode 100644 index 0000000..b0da212 --- /dev/null +++ b/integration_tests/rest/test_order_book.py @@ -0,0 +1,33 @@ +import sys +import pytest + + +class TestOrderBook: + + def test_response_corresponds_swagger_schema(self, client): + resp_keys = ['asks', 'bids', 'lastUpdateId'] + order_book = client.get_order_book('EUR/USD_LEVERAGE') + assert type(order_book) is dict + assert len(order_book) == 3 + assert all(dct in resp_keys for dct in order_book.keys()) + assert all(order_book[key] is not None for key in order_book.keys()) + + @pytest.mark.xfail + @pytest.mark.parametrize('limit', [5, 10, 20, 50, 100, 500, 1000]) + def test_limit(self, client, limit): + order_book = client.get_order_book('GBP/USD_LEVERAGE', limit=limit) + assert len(order_book['asks']) == limit + assert len(order_book['bids']) == limit + + @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, 1, 506, 999, + 1001, sys.maxsize]) + def test_invalid_limit(self, client, limit): + with pytest.raises(ValueError): + client.get_order_book('EUR/USD_LEVERAGE', limit=limit) + + def test_wrong_symbol(self, client): + agg_trades = client.get_order_book(symbol="TEST123") + assert agg_trades['code'] == -1128 and 'symbol not found ' \ + in agg_trades['msg'] + + From 87be145357c85045ec631586fe3c5bb191c1bbc0 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Sat, 3 Sep 2022 12:36:19 +0300 Subject: [PATCH 06/11] fixed tests according comments --- integration_tests/rest/test_order_book.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py index b0da212..6cee236 100644 --- a/integration_tests/rest/test_order_book.py +++ b/integration_tests/rest/test_order_book.py @@ -13,13 +13,13 @@ def test_response_corresponds_swagger_schema(self, client): assert all(order_book[key] is not None for key in order_book.keys()) @pytest.mark.xfail - @pytest.mark.parametrize('limit', [5, 10, 20, 50, 100, 500, 1000]) + @pytest.mark.parametrize('limit', [1, 2, 500, 999, 1000]) def test_limit(self, client, limit): order_book = client.get_order_book('GBP/USD_LEVERAGE', limit=limit) assert len(order_book['asks']) == limit assert len(order_book['bids']) == limit - @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, 1, 506, 999, + @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, 1001, sys.maxsize]) def test_invalid_limit(self, client, limit): with pytest.raises(ValueError): From 241ef29425dbd4cf810bb53e1e04963d7832eab7 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Sat, 3 Sep 2022 12:40:38 +0300 Subject: [PATCH 07/11] removed decorator "@pytest.mark.xfail" --- integration_tests/rest/test_order_book.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py index 6cee236..7df17fe 100644 --- a/integration_tests/rest/test_order_book.py +++ b/integration_tests/rest/test_order_book.py @@ -12,7 +12,6 @@ def test_response_corresponds_swagger_schema(self, client): assert all(dct in resp_keys for dct in order_book.keys()) assert all(order_book[key] is not None for key in order_book.keys()) - @pytest.mark.xfail @pytest.mark.parametrize('limit', [1, 2, 500, 999, 1000]) def test_limit(self, client, limit): order_book = client.get_order_book('GBP/USD_LEVERAGE', limit=limit) From 20b68afcd6527dcf68fbcde6700cc143569386ac Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Sun, 4 Sep 2022 13:07:12 +0300 Subject: [PATCH 08/11] Update. Added -sys.maxsize + 1, sys.maxsize - 1 to parametrize limit values --- integration_tests/rest/test_order_book.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py index 7df17fe..b9d2b9f 100644 --- a/integration_tests/rest/test_order_book.py +++ b/integration_tests/rest/test_order_book.py @@ -18,8 +18,9 @@ def test_limit(self, client, limit): assert len(order_book['asks']) == limit assert len(order_book['bids']) == limit - @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, - 1001, sys.maxsize]) + @pytest.mark.parametrize('limit', [-sys.maxsize, -sys.maxsize + 1, + -1, 0, 1001, sys.maxsize - 1, + sys.maxsize]) def test_invalid_limit(self, client, limit): with pytest.raises(ValueError): client.get_order_book('EUR/USD_LEVERAGE', limit=limit) From 9b6ec88ed0297e27fea9a4b662f98b87e66ff455 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Mon, 5 Sep 2022 11:32:22 +0300 Subject: [PATCH 09/11] Fixed values in parameters for test test_invalid_limit --- integration_tests/rest/test_order_book.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py index b9d2b9f..7df17fe 100644 --- a/integration_tests/rest/test_order_book.py +++ b/integration_tests/rest/test_order_book.py @@ -18,9 +18,8 @@ def test_limit(self, client, limit): assert len(order_book['asks']) == limit assert len(order_book['bids']) == limit - @pytest.mark.parametrize('limit', [-sys.maxsize, -sys.maxsize + 1, - -1, 0, 1001, sys.maxsize - 1, - sys.maxsize]) + @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, + 1001, sys.maxsize]) def test_invalid_limit(self, client, limit): with pytest.raises(ValueError): client.get_order_book('EUR/USD_LEVERAGE', limit=limit) From 85485684291e2d4d21097805b272cc40b56b7960 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Mon, 5 Sep 2022 15:53:06 +0300 Subject: [PATCH 10/11] Fixed test_invalid_limit --- currencycom/client.py | 2 +- integration_tests/rest/test_order_book.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/currencycom/client.py b/currencycom/client.py index faf0593..21e4aad 100644 --- a/currencycom/client.py +++ b/currencycom/client.py @@ -305,7 +305,7 @@ def get_order_book(self, symbol, limit=100): ] } """ - self._validate_limit(limit) + #self._validate_limit(limit) r = requests.get(self.constants.ORDER_BOOK_ENDPOINT, params={'symbol': symbol, 'limit': limit}) return r.json() diff --git a/integration_tests/rest/test_order_book.py b/integration_tests/rest/test_order_book.py index 7df17fe..4837ab8 100644 --- a/integration_tests/rest/test_order_book.py +++ b/integration_tests/rest/test_order_book.py @@ -18,15 +18,16 @@ def test_limit(self, client, limit): assert len(order_book['asks']) == limit assert len(order_book['bids']) == limit - @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, - 1001, sys.maxsize]) + @pytest.mark.parametrize('limit', [-sys.maxsize, -1, + 0, sys.maxsize]) def test_invalid_limit(self, client, limit): - with pytest.raises(ValueError): - client.get_order_book('EUR/USD_LEVERAGE', limit=limit) + order_book = client.get_order_book('EUR/USD_LEVERAGE', limit=limit) + assert order_book['code'] == -1128 and order_book['msg'] in \ + ('Combination of parameters invalid', 'Invalid limit') def test_wrong_symbol(self, client): - agg_trades = client.get_order_book(symbol="TEST123") - assert agg_trades['code'] == -1128 and 'symbol not found ' \ - in agg_trades['msg'] + order_book = client.get_order_book(symbol="TEST123") + assert order_book['code'] == -1128 and 'symbol not found ' \ + in order_book['msg'] From aedf28d843b1ec47f1342e0b7a8ec8173e3e0936 Mon Sep 17 00:00:00 2001 From: Trivium0911 Date: Mon, 5 Sep 2022 15:53:26 +0300 Subject: [PATCH 11/11] Fixed test_invalid_limit --- currencycom/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/currencycom/client.py b/currencycom/client.py index 21e4aad..faf0593 100644 --- a/currencycom/client.py +++ b/currencycom/client.py @@ -305,7 +305,7 @@ def get_order_book(self, symbol, limit=100): ] } """ - #self._validate_limit(limit) + self._validate_limit(limit) r = requests.get(self.constants.ORDER_BOOK_ENDPOINT, params={'symbol': symbol, 'limit': limit}) return r.json()