|
1 | 1 | import json |
2 | | -import uuid |
3 | 2 | import base64 |
4 | 3 | from decimal import Decimal |
5 | 4 |
|
|
10 | 9 | import gdax |
11 | 10 | import gdax.orderbook |
12 | 11 |
|
13 | | -from tests.helpers import AsyncContextManagerMock |
14 | | - |
15 | | - |
16 | | -def generate_id(): |
17 | | - return str(uuid.uuid4()) |
| 12 | +from tests.helpers import AsyncContextManagerMock, generate_id |
18 | 13 |
|
19 | 14 |
|
20 | 15 | id1 = generate_id() |
21 | 16 | id2 = generate_id() |
22 | 17 |
|
23 | 18 |
|
24 | 19 | bids1 = [ |
25 | | - ["2525.00", "1.5", generate_id()], |
26 | | - ["2595.52", "100", id2], |
27 | | - ["2595.52", "2", id1], |
28 | | - ["2595.62", "1.41152763", id2], |
29 | | - ["2595.70", "1.5", generate_id()], |
| 20 | + [Decimal("2525.00"), Decimal("1.5"), generate_id()], |
| 21 | + [Decimal("2595.52"), Decimal("100"), id2], |
| 22 | + [Decimal("2595.52"), Decimal("2"), id1], |
| 23 | + [Decimal("2595.62"), Decimal("1.41152763"), id2], |
| 24 | + [Decimal("2595.70"), Decimal("1.5"), generate_id()], |
30 | 25 | ] |
31 | 26 | asks1 = [ |
32 | | - ["2596.74", "0.2", generate_id()], |
33 | | - ["2596.77", "0.07670504", generate_id()], |
34 | | - ["2615.1", "0.011", generate_id()], |
35 | | - ["2620.05", "0.02", id1], |
36 | | - ["2620.1", "100", generate_id()], |
37 | | - ["2620.18", "0.01", id1], |
38 | | - ["2620.18", "0.02", id2], |
| 27 | + [Decimal("2596.74"), Decimal("0.2"), generate_id()], |
| 28 | + [Decimal("2596.77"), Decimal("0.07670504"), generate_id()], |
| 29 | + [Decimal("2615.1"), Decimal("0.011"), generate_id()], |
| 30 | + [Decimal("2620.05"), Decimal("0.02"), id1], |
| 31 | + [Decimal("2620.1"), Decimal("100"), generate_id()], |
| 32 | + [Decimal("2620.18"), Decimal("0.01"), id1], |
| 33 | + [Decimal("2620.18"), Decimal("0.02"), id2], |
39 | 34 | ] |
40 | 35 | sequence = 3419033239 |
41 | 36 | test_book = { |
@@ -154,8 +149,8 @@ async def test_basic_init(self, mock_book, mock_connect): |
154 | 149 |
|
155 | 150 | assert orderbook.get_current_book(product_id) == { |
156 | 151 | "sequence": 3419033239, |
157 | | - "bids": [[Decimal(r[0]), Decimal(r[1]), r[2]] for r in bids1], |
158 | | - "asks": [[Decimal(r[0]), Decimal(r[1]), r[2]] for r in asks1], |
| 152 | + "bids": bids1, |
| 153 | + "asks": asks1, |
159 | 154 | } |
160 | 155 |
|
161 | 156 | assert orderbook.get_ask(product_id) == Decimal('2596.74') |
@@ -300,6 +295,7 @@ async def test_logfile(self, mock_book, mock_connect): |
300 | 295 | async def test_orderbook_advanced(self, mock_book, mock_connect): |
301 | 296 | # TODO: split test by message type |
302 | 297 | product_id = 'BTC-USD' |
| 298 | + mock_book.return_value = test_book |
303 | 299 | mock_connect.return_value.aenter.receive_str = CoroutineMock() |
304 | 300 | mock_connect.return_value.aenter.send_json = CoroutineMock() |
305 | 301 | messages_expected = [ |
@@ -333,7 +329,7 @@ async def test_orderbook_advanced(self, mock_book, mock_connect): |
333 | 329 | { |
334 | 330 | "type": "done", |
335 | 331 | "side": "sell", |
336 | | - "order_id": asks1[1][0], |
| 332 | + "order_id": asks1[1][2], |
337 | 333 | "reason": "canceled", |
338 | 334 | "product_id": product_id, |
339 | 335 | # no price specified |
@@ -380,7 +376,6 @@ async def test_orderbook_advanced(self, mock_book, mock_connect): |
380 | 376 | json.dumps(message_expected) |
381 | 377 | for message_expected in messages_expected |
382 | 378 | ] |
383 | | - mock_book.return_value = test_book |
384 | 379 | async with gdax.orderbook.OrderBook(product_id) as orderbook: |
385 | 380 | # ignore because of sequence number |
386 | 381 | current_book = orderbook.get_current_book(product_id) |
|
0 commit comments