-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwebsockets.py
More file actions
49 lines (29 loc) · 1002 Bytes
/
Copy pathwebsockets.py
File metadata and controls
49 lines (29 loc) · 1002 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
39
40
41
42
43
44
45
46
47
48
import os
import sys
import asyncio
root = os.path.dirname(os.path.dirname((os.path.abspath(__file__))))
sys.path.append(root + '/')
from hyperliquid import HyperliquidWs
# ********** on Windows, uncomment below **********
# if sys.platform == 'win32':
# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
async def my_watch_ticker_my(exchange, symbol):
while (True):
result = await exchange.watch_ticker(symbol)
print(result)
async def my_watch_orderbook(exchange, symbol):
while (True):
result = await exchange.watch_order_book(symbol)
print(result)
async def main():
instance = HyperliquidWs({})
await instance.load_markets()
symbol = "BTC/USDC:USDC"
# fetch ticker
ticker = my_watch_ticker_my(instance, symbol)
# fetch orderbook
ob = my_watch_orderbook(instance, symbol)
await asyncio.gather(ticker, ob)
# close after you finish
await instance.close()
asyncio.run(main())