Skip to content

Commit 94d6833

Browse files
committed
add spot websocket api
1 parent c8d51ee commit 94d6833

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

huobi/spot/ws/account.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from huobi.utils.ws import Ws
2+
from huobi.host import HOST_SPOT
3+
import json
4+
5+
6+
class Account():
7+
def __init__(self, access_key: str, secret_key: str, host: str = HOST_SPOT):
8+
self.__access_key = access_key
9+
self.__secret_key = secret_key
10+
self.__host = host
11+
self.__path = "/ws/v2"
12+
self.__sub_dict = {}
13+
14+
def sub(self, data: dict, call_back_fun) -> Ws:
15+
id = data['ch']
16+
ws = Ws(self.__host, self.__path, data, call_back_fun, self.__access_key, self.__secret_key)
17+
ws.connect()
18+
self.__sub_dict[id] = ws
19+
return ws
20+
21+
def unsub(self, data: dict) -> Ws:
22+
id = data['ch']
23+
if id not in self.__sub_dict:
24+
return None
25+
ws = self.__sub_dict[id]
26+
ws.send_msg(data)
27+
return ws

huobi/spot/ws/market.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from huobi.utils.ws import Ws
2+
from huobi.host import HOST_SPOT
3+
import json
4+
5+
6+
class Market():
7+
def __init__(self, host: str = HOST_SPOT):
8+
self.__host = host
9+
self.__path = "/ws"
10+
self.__mbp_path = "/feed"
11+
12+
def sub(self, data: dict, call_back_fun) -> Ws:
13+
ws = Ws(self.__host, self.__path, data, call_back_fun)
14+
ws.connect()
15+
return ws
16+
17+
def req(self, data: dict, call_back_fun) -> Ws:
18+
ws = Ws(self.__host, self.__path, None, call_back_fun)
19+
ws.connect()
20+
ws.send_msg(data)
21+
return
22+
23+
def sub_mbp(self, data: dict, call_back_fun) -> Ws:
24+
'''
25+
just for Market By Price
26+
'''
27+
ws = Ws(self.__host, self.__mbp_path, data, call_back_fun)
28+
ws.connect()
29+
return ws
30+
31+
def req_mbp(self, data: dict, call_back_fun) -> Ws:
32+
'''
33+
just for Market By Price
34+
'''
35+
ws = Ws(self.__host, self.__mbp_path, None, call_back_fun)
36+
ws.connect()
37+
ws.send_msg(data)
38+
return ws

0 commit comments

Comments
 (0)