|
| 1 | +import sys |
| 2 | +import pytest |
| 3 | + |
| 4 | + |
| 5 | +class TestOrderBook: |
| 6 | + |
| 7 | + def test_response_corresponds_swagger_schema(self, client): |
| 8 | + resp_keys = ['asks', 'bids', 'lastUpdateId'] |
| 9 | + order_book = client.get_order_book('EUR/USD_LEVERAGE') |
| 10 | + assert type(order_book) is dict |
| 11 | + assert len(order_book) == 3 |
| 12 | + assert all(dct in resp_keys for dct in order_book.keys()) |
| 13 | + assert all(order_book[key] is not None for key in order_book.keys()) |
| 14 | + |
| 15 | + @pytest.mark.xfail |
| 16 | + @pytest.mark.parametrize('limit', [5, 10, 20, 50, 100, 500, 1000]) |
| 17 | + def test_limit(self, client, limit): |
| 18 | + order_book = client.get_order_book('GBP/USD_LEVERAGE', limit=limit) |
| 19 | + assert len(order_book['asks']) == limit |
| 20 | + assert len(order_book['bids']) == limit |
| 21 | + |
| 22 | + @pytest.mark.parametrize('limit', [-sys.maxsize, -1, 0, 1, 506, 999, |
| 23 | + 1001, sys.maxsize]) |
| 24 | + def test_invalid_limit(self, client, limit): |
| 25 | + with pytest.raises(ValueError): |
| 26 | + client.get_order_book('EUR/USD_LEVERAGE', limit=limit) |
| 27 | + |
| 28 | + def test_wrong_symbol(self, client): |
| 29 | + agg_trades = client.get_order_book(symbol="TEST123") |
| 30 | + assert agg_trades['code'] == -1128 and 'symbol not found ' \ |
| 31 | + in agg_trades['msg'] |
| 32 | + |
| 33 | + |
0 commit comments