This repository was archived by the owner on Jul 16, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathticker.py
More file actions
Latest commit
50 lines (37 loc) · 1.15 KB
/
Copy pathticker.py
File metadata and controls
50 lines (37 loc) · 1.15 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
# !/usr/bin/env python
# coding: utf-8
"""
Example of subscribe tickers
"""
importasyncio
importlogging
fromgate_wsimportConfiguration, Connection, WebSocketResponse
fromgate_ws.spotimportSpotTickerChannel
logger=logging.getLogger(__name__)
asyncdefcallback(conn: Connection, response: WebSocketResponse):
ifresponse.error:
conn.close()
raiseresponse.error
result=response.result
logger.debug("received update: %s", result)
assertisinstance(result, dict)
if__name__=="__main__":
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s: %(message)s")
loop=asyncio.new_event_loop()
asyncio.set_event_loop(loop)
cfg=Configuration(event_loop=loop)
conn=Connection(cfg)
channel=SpotTickerChannel(conn, callback)
channel.subscribe(["BTC_USDT"])
tasks: set[asyncio.Task] = {
loop.create_task(conn.run()),
}
try:
loop.run_forever()
exceptKeyboardInterrupt:
fortaskintasks:
task.cancel()
group=asyncio.gather(*tasks, return_exceptions=True)
loop.run_until_complete(group)
finally:
loop.close()