forked from dydxprotocol/dydx-v3-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsockets_example.py
More file actions
38 lines (26 loc) · 857 Bytes
/
websockets_example.py
File metadata and controls
38 lines (26 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Example for connecting to private WebSockets with an existing account.
Usage: python -m examples.websockets
"""
import asyncio
import json
import websockets
from dydx3.helpers.request_helpers import generate_now_iso
from dydx3.constants import WS_HOST_SEPOLIA
now_iso_string = generate_now_iso()
req = {
"type": "subscribe",
"channel": "v3_accounts",
"accountNumber": "0",
"apiKey": "51b77d77d5de0132f3b3bb897ab2c438",
"passphrase": "passphrase",
"timestamp": now_iso_string,
"signature": "signature",
}
async def main():
async with websockets.connect(WS_HOST_SEPOLIA+"/accounts") as websocket:
await websocket.send(json.dumps(req))
print(f"> {req}")
while True:
res = await websocket.recv()
print(f"< {res}")
asyncio.get_event_loop().run_until_complete(main())