44#
55# For public requests to the Coinbase exchange
66
7+ from http import HTTPStatus
78import requests
89from gdax import exceptions
910
1011
11- HTTP_200_OK = 200
12- HTTP_300_MULTIPLE_CHOICES = 300
13- HTTP_400_BAD_REQUEST = 400
14- HTTP_401_UNAUTHORIZED = 401
15- HTTP_403_FORBIDDEN = 403
16- HTTP_404_NOT_FOUND = 404
17- HTTP_500_INTERNAL_SERVER_ERROR = 500
18-
1912
2013class PublicClient (object ):
2114 """cbpro public client API.
@@ -42,15 +35,15 @@ def __init__(self, api_url='https://api.pro.coinbase.com', timeout=30):
4235
4336 def _is_http_success (self , code ):
4437 # type: (int) -> bool
45- return code >= HTTP_200_OK and code < HTTP_300_MULTIPLE_CHOICES
38+ return code >= HTTPStatus . OK and code < HTTPStatus . MULTIPLE_CHOICES
4639
4740 def _is_http_client_error (self , code ):
4841 # type: (int) -> bool
49- return code >= HTTP_400_BAD_REQUEST and code < HTTP_500_INTERNAL_SERVER_ERROR
42+ return code >= HTTPStatus . BAD_REQUEST and code < HTTPStatus . INTERNAL_SERVER_ERROR
5043
5144 def _is_http_server_error (self , code ):
5245 # type: (int) -> bool
53- return code >= HTTP_500_INTERNAL_SERVER_ERROR
46+ return code >= HTTPStatus . INTERNAL_SERVER_ERROR
5447
5548 def _determine_response (self , response ):
5649 """
@@ -63,26 +56,26 @@ def _determine_response(self, response):
6356 elif self ._is_http_client_error (response .status_code ):
6457 body = response .json ()
6558 message = body .get ('message' )
66- if response .status_code == HTTP_400_BAD_REQUEST :
59+ if response .status_code == HTTPStatus . BAD_REQUEST :
6760 raise exceptions .InvalidGdaxRequest (message ,
68- HTTP_400_BAD_REQUEST )
69- elif response .status_code == HTTP_401_UNAUTHORIZED :
61+ HTTPStatus . BAD_REQUEST )
62+ elif response .status_code == HTTPStatus . UNAUTHORIZED :
7063 raise exceptions .UnauthorizedGdaxRequest (message ,
71- HTTP_401_UNAUTHORIZED )
72- elif response .status_code == HTTP_403_FORBIDDEN :
64+ HTTPStatus . UNAUTHORIZED )
65+ elif response .status_code == HTTPStatus . FORBIDDEN :
7366 raise exceptions .ForbiddenGdaxRequest (message ,
74- HTTP_403_FORBIDDEN )
75- elif response .status_code == HTTP_404_NOT_FOUND :
67+ HTTPStatus . FORBIDDEN )
68+ elif response .status_code == HTTPStatus . NOT_FOUND :
7669 raise exceptions .NotFoundGdaxRequest (message ,
77- HTTP_404_NOT_FOUND )
70+ HTTPStatus . NOT_FOUND )
7871 else : # Other 4XX response not yet mapped
7972 raise exceptions .UnknownGdaxClientRequest (message ,
8073 response .status_code )
8174
8275 elif self ._is_http_server_error (response .status_code ):
8376 body = response .json ()
8477 raise exceptions .InternalErrorGdaxRequest (body .get ('message' ),
85- HTTP_500_INTERNAL_SERVER_ERROR )
78+ HTTPStatus . INTERNAL_SERVER_ERROR )
8679
8780 def _get (self , path , params = None ):
8881 """Perform get request"""
0 commit comments