22from binance import BinanceSocketManager
33import pytest
44
5+ from binance .async_client import AsyncClient
6+ from .conftest import proxy , api_key , api_secret , testnet
7+
58
69@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "websockets_proxy Python 3.8+" )
710@pytest .mark .asyncio
@@ -13,3 +16,65 @@ async def test_socket_stopped_on_aexit(clientAsync):
1316 ts2 = bm .trade_socket ("BNBBTC" )
1417 assert ts2 is not ts1 , "socket should be removed from _conn on exit"
1518 await clientAsync .close_connection ()
19+
20+
21+ @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "websockets_proxy Python 3.8+" )
22+ @pytest .mark .asyncio
23+ async def test_socket_spot_market_time_unit_microseconds ():
24+ clientAsync = AsyncClient (
25+ api_key , api_secret , https_proxy = proxy , testnet = testnet , time_unit = "MICROSECOND"
26+ )
27+ bm = BinanceSocketManager (clientAsync )
28+ ts1 = bm .symbol_ticker_socket ("BTCUSDT" )
29+ async with ts1 :
30+ trade = await ts1 .recv ()
31+ assert len (str (trade ["E" ])) >= 16 , "Time should be in microseconds (16+ digits)"
32+ await clientAsync .close_connection ()
33+
34+
35+ @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "websockets_proxy Python 3.8+" )
36+ @pytest .mark .asyncio
37+ async def test_socket_spot_market_time_unit_milliseconds ():
38+ clientAsync = AsyncClient (
39+ api_key , api_secret , https_proxy = proxy , testnet = testnet , time_unit = "MILLISECOND"
40+ )
41+ bm = BinanceSocketManager (clientAsync )
42+ ts1 = bm .symbol_ticker_socket ("BTCUSDT" )
43+ async with ts1 :
44+ trade = await ts1 .recv ()
45+ assert len (str (trade ["E" ])) == 13 , "Time should be in milliseconds (13 digits)"
46+ await clientAsync .close_connection ()
47+
48+
49+ @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "websockets_proxy Python 3.8+" )
50+ @pytest .mark .asyncio
51+ async def test_socket_spot_user_data_time_unit_microseconds ():
52+ clientAsync = AsyncClient (
53+ api_key , api_secret , https_proxy = proxy , testnet = testnet , time_unit = "MICROSECOND"
54+ )
55+ bm = BinanceSocketManager (clientAsync )
56+ ts1 = bm .user_socket ()
57+ async with ts1 :
58+ await clientAsync .create_order (
59+ symbol = "LTCUSDT" , side = "BUY" , type = "MARKET" , quantity = 0.1
60+ )
61+ trade = await ts1 .recv ()
62+ assert len (str (trade ["E" ])) >= 16 , "Time should be in microseconds (16+ digits)"
63+ await clientAsync .close_connection ()
64+
65+
66+ @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "websockets_proxy Python 3.8+" )
67+ @pytest .mark .asyncio
68+ async def test_socket_spot_user_data_time_unit_milliseconds ():
69+ clientAsync = AsyncClient (
70+ api_key , api_secret , https_proxy = proxy , testnet = testnet , time_unit = "MILLISECOND"
71+ )
72+ bm = BinanceSocketManager (clientAsync )
73+ ts1 = bm .user_socket ()
74+ async with ts1 :
75+ await clientAsync .create_order (
76+ symbol = "LTCUSDT" , side = "BUY" , type = "MARKET" , quantity = 0.1
77+ )
78+ trade = await ts1 .recv ()
79+ assert len (str (trade ["E" ])) == 13 , "Time should be in milliseconds (13 digits)"
80+ await clientAsync .close_connection ()
0 commit comments