diff --git a/client/python/upbit/authentication.py b/client/python/upbit/authentication.py index ad4801f..ddfdec1 100644 --- a/client/python/upbit/authentication.py +++ b/client/python/upbit/authentication.py @@ -31,11 +31,13 @@ def matches(self, url): return MAPPER not in url def apply(self, request): - request.headers['User-Agent'] = "ujhin's Upbit SDKs" + payload = self.generate_payload(request) + + request.headers['User-Agent' ] = "ujhin's Upbit SDKs" request.headers['Accept-Encoding'] = 'gzip, deflate' - request.headers['Accept'] = '*/*' - request.headers['Connection'] = 'keep-alive' - request.headers['Authorization'] = self.generate_payload(request) + request.headers['Accept' ] = '*/*' + request.headers['Connection' ] = 'keep-alive' + request.headers['Authorization' ] = payload return request def generate_payload(self, request): @@ -51,11 +53,11 @@ def generate_payload(self, request): if params: query = self.generate_query(params) - h = hashlib.sha512() - h.update(query.encode()) - query_hash = h.hexdigest() + sha512 = hashlib.sha512() + sha512.update(query.encode()) + query_hash = sha512.hexdigest() - payload['query_hash'] = query_hash + payload['query_hash' ] = query_hash payload['query_hash_alg'] = 'SHA512' jwt_token = jwt.encode(payload, self.secret_key) diff --git a/client/python/upbit/client.py b/client/python/upbit/client.py index 38a9f98..ad9086e 100644 --- a/client/python/upbit/client.py +++ b/client/python/upbit/client.py @@ -31,13 +31,13 @@ def __init__( **kwargs ).SWGClient - self.APIKey = models.APIKey(self.__client) - self.Account = models.Account(self.__client) - self.Candle = models.Candle(self.__client) - self.Deposit = models.Deposit(self.__client) - self.Market = models.Market(self.__client) - self.Order = models.Order(self.__client) - self.Trade = models.Trade(self.__client) + self.APIKey = models.APIKey(self.__client) + self.Account = models.Account(self.__client) + self.Candle = models.Candle(self.__client) + self.Deposit = models.Deposit(self.__client) + self.Market = models.Market(self.__client) + self.Order = models.Order(self.__client) + self.Trade = models.Trade(self.__client) self.Withdraw = models.Withdraw(self.__client) def __str__(self): diff --git a/client/python/upbit/models.py b/client/python/upbit/models.py index ab3857b..30c8343 100644 --- a/client/python/upbit/models.py +++ b/client/python/upbit/models.py @@ -139,7 +139,7 @@ def Candle_minutes(self, **kwargs) -> dict: :type to: str :param count: 캔들 개수 (최대 200개까지 요청 가능) (optional) - :type count: number + :type count: int """ future = self.__client.Candle.Candle_minutes(**kwargs) @@ -160,7 +160,7 @@ def Candle_days(self, **kwargs) -> dict: :type to: str :param count: 캔들 개수 (optional) - :type count: number + :type count: int :param convertingPriceUnit: 종가 환산 화폐 단위 (생략 가능, KRW로 명시할 시 원화 환산 가격을 반환.) `convertingPriceUnit` 파라미터의 경우, 원화 마켓이 아닌 다른 마켓(ex. BTC, ETH)의 일봉 요청 시 @@ -187,7 +187,7 @@ def Candle_weeks(self, **kwargs) -> dict: :type to: str :param count: 캔들 개수 (optional) - :type count: number + :type count: int """ future = self.__client.Candle.Candle_weeks(**kwargs) @@ -208,7 +208,7 @@ def Candle_month(self, **kwargs) -> dict: :type to: str :param count: 캔들 개수 (optional) - :type count: number + :type count: int """ future = self.__client.Candle.Candle_month(**kwargs) @@ -269,7 +269,7 @@ def Deposit_generate_coin_address(self, **kwargs) -> dict: :param currency: Currency 코드 - :type currency: string + :type currency: str """ future = self.__client.Deposit.Deposit_generate_coin_address(**kwargs) @@ -282,13 +282,13 @@ def Deposit_info(self, **kwargs) -> dict: ## 개별 입금 조회 :param uuid: 입금 UUID (optional) - :type uuid: string + :type uuid: str :param txid: 입금 TXID (optional) - :type txid: string + :type txid: str :param currency: Currency 코드 (optional) - :type currency: string + :type currency: str """ future = self.__client.Deposit.Deposit_info(**kwargs) @@ -319,10 +319,10 @@ def Deposit_info_all(self, **kwargs) -> dict: :type txids: list :param limit: 개수 제한 (default: 100, max: 100) (optional) - :type limit: number + :type limit: int :param page: 페이지 수, default: 1 (optional) - :type page: number + :type page: int :param order_by: 정렬 방식 (optional) - asc : 오름차순 @@ -431,10 +431,10 @@ def Order_info_all(self, **kwargs) -> dict: :type identifiers: array :param page: 페이지 수, default: 1 (optional) - :type page: number + :type page: int :param limit: 요청 개수, default: 100 (optional) - :type limit: number + :type limit: int :param order_by: 정렬 방식 (optional) - asc : 오름차순 @@ -505,10 +505,10 @@ def Order_cancel(self, **kwargs) -> dict: [NOTE] `uuid` 혹은 `identifier` 둘 중 하나의 값이 반드시 포함되어야 합니다. :param uuid: 취소할 주문의 UUID (optional) - :type uuid: string + :type uuid: str :param identifier: 조회용 사용자 지정 값 (optional) - :type identifier: string + :type identifier: str """ future = self.__client.Order.Order_cancel(**kwargs) @@ -553,7 +553,7 @@ def Trade_ticks(self, **kwargs) -> dict: :type to: str :param count: 체결 개수 (optional) - :type count: number + :type count: int :param cursor: 페이지네이션 커서 (sequentialId) `sequential_id` 필드는 체결의 유일성 판단을 위한 근거로 쓰일 수 있습니다. @@ -562,7 +562,7 @@ def Trade_ticks(self, **kwargs) -> dict: :param daysAgo: 최근 체결 날짜 기준 7일 이내의 이전 데이터 조회 가능. 비워서 요청 시 가장 최근 체결 날짜 반환. (범위: 1 ~ 7) (optional) - :type daysAgo: number + :type daysAgo: int """ future = self.__client.Trade.Trade_ticks(**kwargs) @@ -611,7 +611,7 @@ def Withdraw_coin(self, **kwargs) -> dict: :type address: str :param secondary_address: 2차 출금 주소 (필요한 코인에 한해서) (optional) - :type secondary_address: string + :type secondary_address: str :param transaction_type: 출금 유형 (optional) - default : 일반출금 @@ -648,7 +648,7 @@ def Withdraw_info_all(self, **kwargs) -> dict: ## 출금 리스트를 조회한다. :param currency: Currency 코드 (optional) - :type currency: string + :type currency: str :param state: 출금 상태 (optional) - submitting : 처리 중 @@ -659,7 +659,7 @@ def Withdraw_info_all(self, **kwargs) -> dict: - processing : 처리 중 - done : 완료 - canceled : 취소됨 - :type state: string + :type state: str :param uuids: 출금 UUID의 목록 (optional) :type uuids: list @@ -668,10 +668,10 @@ def Withdraw_info_all(self, **kwargs) -> dict: :type txids: list :param limit: 개수 제한 (default: 100, max: 100) (optional) - :type limit: number + :type limit: int :param page: 페이지 수, default: 1 (optional) - :type page: number + :type page: int :param order_by: 정렬 방식 (optional) - asc : 오름차순 diff --git a/client/python/upbit/pkginfo.py b/client/python/upbit/pkginfo.py index 5d28df7..8e5c37b 100644 --- a/client/python/upbit/pkginfo.py +++ b/client/python/upbit/pkginfo.py @@ -29,7 +29,7 @@ def _get_versions(package_name): PACKAGE_NAME = 'upbit-client' OPEN_API_VERSION = '1.1.7' -CURRENT_VERSION = OPEN_API_VERSION+'.5' +CURRENT_VERSION = OPEN_API_VERSION+'.6' RELEASED_VERSION = _get_versions(PACKAGE_NAME) LATEST_VERSION = RELEASED_VERSION[0] @@ -37,8 +37,8 @@ def _get_versions(package_name): if LATEST_VERSION != CURRENT_VERSION: logging.basicConfig(format="[%(levelname)s] %(message)s") - logging.warning(f""" - {PACKAGE_NAME} is currently a newer version: {LATEST_VERSION}\n - Please update to the latest version using the pip command: - `pip install --upgrade {PACKAGE_NAME}` - """) + logging.warning( + f"{PACKAGE_NAME} is currently a newer version: {LATEST_VERSION}\n" + f"Please update to the latest version using the pip command:" + f"`pip install --upgrade {PACKAGE_NAME}`" + ) diff --git a/client/python/upbit/websocket.py b/client/python/upbit/websocket.py index 237b4f3..358bb55 100644 --- a/client/python/upbit/websocket.py +++ b/client/python/upbit/websocket.py @@ -8,6 +8,9 @@ WEBSOCKET_URI = "wss://api.upbit.com/websocket/v1" +FIELD_TYPES = ['ticker', 'trade', 'orderbook'] +FIELD_FORMATS = ['SIMPLE', 'DEFAULT'] + class UpbitWebSocket: """ @@ -58,6 +61,14 @@ def connect( ping_interval: Union[int, float] = None, ping_timeout: Union[int, float] = None ): + """ + :param ping_interval: ping 간격 제한 + :type ping_interval: Union[int, float] + + :param ping_timeout: ping 시간 초과 제한 + :type ping_timeout: Union[int, float] + """ + self.Connection = websockets.connect( uri=self.URI, ping_interval=ping_interval, @@ -107,7 +118,7 @@ def generate_type_field( field = {} - if type in ['ticker', 'trade', 'orderbook']: + if type in FIELD_TYPES: field["type"] = type else: raise ValueError("'type' is not available") @@ -147,7 +158,7 @@ def generate_payload( payload.extend(type_fields) fmt = format.upper() - fmt = fmt if fmt in ['SIMPLE', 'DEFAULT'] else 'DEFAULT' + fmt = fmt if fmt in FIELD_FORMATS else 'DEFAULT' payload.append({"format": fmt}) return json.dumps(payload)