|
1 | 1 | import sys
|
2 | 2 | import pytest
|
| 3 | +import logging |
3 | 4 | from binance import BinanceSocketManager
|
4 | 5 |
|
5 | 6 | pytestmark = [
|
6 | 7 | pytest.mark.skipif(sys.version_info < (3, 8), reason="websockets_proxy Python 3.8+"),
|
7 | 8 | pytest.mark.asyncio
|
8 | 9 | ]
|
9 | 10 |
|
| 11 | +# Configure logger for this module |
| 12 | +logger = logging.getLogger(__name__) |
| 13 | + |
10 | 14 | # Test constants
|
11 |
| -OPTION_SYMBOL = "BTC-250328-40000-P" |
| 15 | +OPTION_SYMBOL = "BTC-250926-40000-P" |
12 | 16 | UNDERLYING_SYMBOL = "BTC"
|
13 |
| -EXPIRATION_DATE = "250328" |
| 17 | +EXPIRATION_DATE = "250926" |
14 | 18 | INTERVAL = "1m"
|
15 | 19 | DEPTH = "20"
|
16 | 20 |
|
17 | 21 | async def test_options_ticker(clientAsync):
|
18 | 22 | """Test options ticker socket"""
|
| 23 | + logger.info(f"Starting options ticker test for symbol: {OPTION_SYMBOL}") |
19 | 24 | bm = BinanceSocketManager(clientAsync)
|
20 | 25 | socket = bm.options_ticker_socket(OPTION_SYMBOL)
|
21 | 26 | async with socket as ts:
|
| 27 | + logger.debug("Waiting for ticker message...") |
22 | 28 | msg = await ts.recv()
|
| 29 | + logger.info(f"Received ticker message: {msg}") |
23 | 30 | assert msg['e'] == '24hrTicker'
|
| 31 | + logger.info("Options ticker test completed successfully") |
24 | 32 | await clientAsync.close_connection()
|
25 | 33 |
|
26 | 34 | async def test_options_ticker_by_expiration(clientAsync):
|
27 | 35 | """Test options ticker by expiration socket"""
|
| 36 | + logger.info(f"Starting options ticker by expiration test for {UNDERLYING_SYMBOL}, expiration: {EXPIRATION_DATE}") |
28 | 37 | bm = BinanceSocketManager(clientAsync)
|
29 | 38 | socket = bm.options_ticker_by_expiration_socket(UNDERLYING_SYMBOL, EXPIRATION_DATE)
|
30 | 39 | async with socket as ts:
|
| 40 | + logger.debug("Waiting for ticker by expiration message...") |
31 | 41 | msg = await ts.recv()
|
| 42 | + logger.info(f"Received {len(msg)} ticker messages") |
32 | 43 | assert len(msg) > 0
|
| 44 | + logger.info("Options ticker by expiration test completed successfully") |
33 | 45 | await clientAsync.close_connection()
|
34 | 46 |
|
35 | 47 | async def test_options_recent_trades(clientAsync):
|
36 | 48 | """Test options recent trades socket"""
|
| 49 | + logger.info(f"Starting options recent trades test for {UNDERLYING_SYMBOL}") |
37 | 50 | bm = BinanceSocketManager(clientAsync)
|
38 | 51 | socket = bm.options_recent_trades_socket(UNDERLYING_SYMBOL)
|
39 | 52 | async with socket as ts:
|
| 53 | + logger.debug("Waiting for trade message...") |
40 | 54 | msg = await ts.recv()
|
| 55 | + logger.info(f"Received trade message: {msg}") |
41 | 56 | assert msg['e'] == 'trade'
|
| 57 | + logger.info("Options recent trades test completed successfully") |
42 | 58 | await clientAsync.close_connection()
|
43 | 59 |
|
44 | 60 | async def test_options_kline(clientAsync):
|
45 | 61 | """Test options kline socket"""
|
| 62 | + logger.info(f"Starting options kline test for {OPTION_SYMBOL}, interval: {INTERVAL}") |
46 | 63 | bm = BinanceSocketManager(clientAsync)
|
47 | 64 | socket = bm.options_kline_socket(OPTION_SYMBOL, INTERVAL)
|
48 | 65 | async with socket as ts:
|
| 66 | + logger.debug("Waiting for kline message...") |
49 | 67 | msg = await ts.recv()
|
| 68 | + logger.info(f"Received kline message: {msg}") |
50 | 69 | assert msg['e'] == 'kline'
|
| 70 | + logger.info("Options kline test completed successfully") |
51 | 71 | await clientAsync.close_connection()
|
52 | 72 |
|
53 | 73 | async def test_options_depth(clientAsync):
|
54 | 74 | """Test options depth socket"""
|
| 75 | + logger.info(f"Starting options depth test for {OPTION_SYMBOL}, depth: {DEPTH}") |
55 | 76 | bm = BinanceSocketManager(clientAsync)
|
56 | 77 | socket = bm.options_depth_socket(OPTION_SYMBOL, DEPTH)
|
57 | 78 | async with socket as ts:
|
| 79 | + logger.debug("Waiting for depth message...") |
58 | 80 | msg = await ts.recv()
|
| 81 | + logger.info(f"Received depth message: {msg}") |
59 | 82 | assert msg['e'] == 'depth'
|
| 83 | + logger.info("Options depth test completed successfully") |
60 | 84 | await clientAsync.close_connection()
|
61 | 85 |
|
62 | 86 | async def test_options_multiplex(clientAsync):
|
63 | 87 | """Test options multiplex socket"""
|
64 |
| - bm = BinanceSocketManager(clientAsync) |
65 | 88 | streams = [
|
66 | 89 | f"{OPTION_SYMBOL}@ticker",
|
67 | 90 | f"{OPTION_SYMBOL}@trade",
|
68 | 91 | ]
|
| 92 | + logger.info(f"Starting options multiplex test with streams: {streams}") |
| 93 | + bm = BinanceSocketManager(clientAsync) |
69 | 94 | socket = bm.options_multiplex_socket(streams)
|
70 | 95 | async with socket as ts:
|
| 96 | + logger.debug("Waiting for multiplex message...") |
71 | 97 | msg = await ts.recv()
|
| 98 | + logger.info(f"Received multiplex message: {msg}") |
72 | 99 | assert 'stream' in msg
|
| 100 | + logger.info("Options multiplex test completed successfully") |
73 | 101 | await clientAsync.close_connection()
|
74 | 102 |
|
75 | 103 | async def test_options_open_interest(clientAsync):
|
76 | 104 | """Test options open interest socket"""
|
| 105 | + logger.info(f"Starting options open interest test for {UNDERLYING_SYMBOL}, expiration: {EXPIRATION_DATE}") |
77 | 106 | bm = BinanceSocketManager(clientAsync)
|
78 | 107 | socket = bm.options_open_interest_socket(UNDERLYING_SYMBOL, EXPIRATION_DATE)
|
79 | 108 | async with socket as ts:
|
| 109 | + logger.debug("Waiting for open interest message...") |
80 | 110 | msg = await ts.recv()
|
| 111 | + logger.info(f"Received open interest message with {len(msg)} items") |
81 | 112 | assert len(msg) > 0
|
| 113 | + logger.info("Options open interest test completed successfully") |
82 | 114 | await clientAsync.close_connection()
|
83 | 115 |
|
84 | 116 | async def test_options_mark_price(clientAsync):
|
85 | 117 | """Test options mark price socket"""
|
| 118 | + logger.info(f"Starting options mark price test for {UNDERLYING_SYMBOL}") |
86 | 119 | bm = BinanceSocketManager(clientAsync)
|
87 | 120 | socket = bm.options_mark_price_socket(UNDERLYING_SYMBOL)
|
88 | 121 | async with socket as ts:
|
| 122 | + logger.debug("Waiting for mark price message...") |
89 | 123 | msg = await ts.recv()
|
| 124 | + logger.info(f"Received mark price message with {len(msg)} items") |
90 | 125 | assert len(msg) > 0
|
| 126 | + logger.info("Options mark price test completed successfully") |
91 | 127 | await clientAsync.close_connection()
|
92 | 128 |
|
93 | 129 | async def test_options_index_price(clientAsync):
|
94 | 130 | """Test options index price socket"""
|
| 131 | + symbol = 'ETHUSDT' |
| 132 | + logger.info(f"Starting options index price test for {symbol}") |
95 | 133 | bm = BinanceSocketManager(clientAsync)
|
96 |
| - socket = bm.options_index_price_socket('ETHUSDT') |
| 134 | + socket = bm.options_index_price_socket(symbol) |
97 | 135 | async with socket as ts:
|
| 136 | + logger.debug("Waiting for index price message...") |
98 | 137 | msg = await ts.recv()
|
| 138 | + logger.info(f"Received index price message: {msg}") |
99 | 139 | assert msg['e'] == 'index'
|
| 140 | + logger.info("Options index price test completed successfully") |
100 | 141 | await clientAsync.close_connection()
|
0 commit comments