@@ -26,13 +26,14 @@ class UpbitWebSocket:
2626 def __init__ (
2727 self ,
2828 uri : Union [str ] = None ,
29- ping_inverval : Union [int , float ] = None ,
29+ ping_interval : Union [int , float ] = None ,
3030 ping_timeout : Union [int , float ] = None
3131 ):
32+
3233 self .__uri = uri if uri else WEBSOCKET_URI
33- self .__conn = websockets . connect (
34- uri = self .URI ,
35- ping_interval = ping_inverval ,
34+ self .__conn = None
35+ self .connect (
36+ ping_interval = ping_interval ,
3637 ping_timeout = ping_timeout
3738 )
3839
@@ -47,16 +48,35 @@ def URI(self, uri):
4748 @property
4849 def Connection (self ):
4950 return self .__conn
50-
51+
5152 @Connection .setter
5253 def Connection (self , conn ):
5354 self .__conn = conn
5455
56+ def connect (
57+ self ,
58+ ping_interval : Union [int , float ] = None ,
59+ ping_timeout : Union [int , float ] = None
60+ ):
61+ self .Connection = websockets .connect (
62+ uri = self .URI ,
63+ ping_interval = ping_interval ,
64+ ping_timeout = ping_timeout
65+ )
66+
5567 @staticmethod
5668 def generate_orderbook_codes (
5769 currencies : Union [List [str ]],
5870 counts : Union [List [int ]] = None
5971 ) -> List [str ]:
72+ """
73+ :param currencies: 수신할 `orderbook` field 마켓 코드 리스트
74+ :type currencies: list[str, ...]
75+
76+ :param counts: 각 마켓 코드 리스트의 index에 해당하는 수신할 `orderbook` 갯수
77+ :type counts: list[int, ...]
78+ """
79+
6080 codes = [
6181 f"{ currency } .{ count } "
6282 for currency , count
@@ -84,6 +104,7 @@ def generate_type_field(
84104 :param isOnlyRealtime: 실시간 시세만 제공 여부
85105 :type isOnlyRealtime: bool
86106 """
107+
87108 field = {}
88109
89110 if type in ['ticker' , 'trade' , 'orderbook' ]:
@@ -117,6 +138,7 @@ def generate_payload(
117138 :param ticket: 식별값
118139 :type ticket: str
119140 """
141+
120142 payload = []
121143
122144 ticket = ticket if ticket else str (uuid .uuid4 ())
@@ -135,3 +157,9 @@ async def __aenter__(self) -> websockets.client.WebSocketClientProtocol:
135157
136158 async def __aexit__ (self , exc_type , exc_value , traceback ) -> None :
137159 await self .Connection .__aexit__ (exc_type , exc_value , traceback )
160+
161+ def __str__ (self ):
162+ return self .__repr__ ()
163+
164+ def __repr__ (self ):
165+ return f"UpbitWebSocket({ self .URI } )"
0 commit comments