33import uuid
44import json
55
6- from typing import Union , List
6+ import typing as t
77
88
99class UpbitWebSocket :
@@ -21,15 +21,15 @@ class UpbitWebSocket:
2121 """
2222
2323 WEBSOCKET_URI = "wss://api.upbit.com/websocket/v1"
24- FIELD_TYPES = ("ticker" , "trade" , "orderbook" )
25- FIELD_FORMATS = ("SIMPLE" , "DEFAULT" )
24+ FIELD_TYPES = ( "ticker" , "trade" , "orderbook" )
25+ FIELD_FORMATS = ( "SIMPLE" , "DEFAULT" )
2626
2727
2828 def __init__ (
2929 self ,
30- uri : Union [ str ] = None ,
31- ping_interval : Union [int , float ] = None ,
32- ping_timeout : Union [int , float ] = None
30+ uri : str = None ,
31+ ping_interval : t . Union [int , float ] = None ,
32+ ping_timeout : t . Union [int , float ] = None
3333 ):
3434
3535 self .__uri = uri if uri else UpbitWebSocket .WEBSOCKET_URI
@@ -59,8 +59,8 @@ def Connection(self, conn):
5959
6060 def connect (
6161 self ,
62- ping_interval : Union [int , float ] = None ,
63- ping_timeout : Union [int , float ] = None
62+ ping_interval : t . Union [int , float ] = None ,
63+ ping_timeout : t . Union [int , float ] = None
6464 ):
6565 """
6666 :param ping_interval: ping 간격 제한
@@ -90,9 +90,9 @@ async def ping(self, decode: str = "utf8"):
9090
9191 @staticmethod
9292 def generate_orderbook_codes (
93- currencies : Union [ List [str ] ],
94- counts : Union [ List [int ] ] = None
95- ) -> List [str ]:
93+ currencies : t . List [str ],
94+ counts : t . List [int ] = None
95+ ) -> t . List [str ]:
9696 """
9797 :param currencies: 수신할 `orderbook` field 마켓 코드 리스트
9898 :type currencies: list[str, ...]
@@ -111,11 +111,11 @@ def generate_orderbook_codes(
111111
112112 @staticmethod
113113 def generate_type_field (
114- type : str ,
115- codes : Union [ List [str ] ],
114+ type : str ,
115+ codes : t . List [str ],
116116 isOnlySnapshot : bool = None ,
117117 isOnlyRealtime : bool = None ,
118- ) -> dict :
118+ ) -> t . Dict [ str , t . Any ] :
119119 """
120120 :param type: 수신할 시세 타입 (현재가: `ticker`, 체결: `trade`, 호가: `orderbook`)
121121 :type type: str
@@ -151,9 +151,9 @@ def generate_type_field(
151151
152152 @staticmethod
153153 def generate_payload (
154- type_fields : Union [ List [dict ]],
155- ticket : str = None ,
156- format : str = ' DEFAULT'
154+ type_fields : t . List [t . Dict [ str , t . Any ]],
155+ ticket : str = None ,
156+ format : str = " DEFAULT"
157157 ) -> str :
158158 """
159159 :param type_fields: Type Fields
@@ -169,13 +169,13 @@ def generate_payload(
169169 payload = []
170170
171171 ticket = ticket if ticket else str (uuid .uuid4 ())
172- payload .append ({ "ticket" : ticket } )
172+ payload .append ( { "ticket" : ticket } )
173173
174174 payload .extend (type_fields )
175175
176176 fmt = format .upper ()
177177 fmt = fmt if fmt in UpbitWebSocket .FIELD_FORMATS else "DEFAULT"
178- payload .append ({ "format" : fmt } )
178+ payload .append ( { "format" : fmt } )
179179
180180 return json .dumps (payload )
181181
0 commit comments