4
4
#
5
5
# For public requests to the GDAX exchange
6
6
7
+ from http import HTTPStatus
7
8
import requests
8
9
from gdax import exceptions
9
10
10
11
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
-
19
12
20
13
class PublicClient (object ):
21
14
"""GDAX public client API.
@@ -40,15 +33,15 @@ def __init__(self, api_url='https://api.gdax.com', timeout=30):
40
33
41
34
def _is_http_success (self , code ):
42
35
# type: (int) -> bool
43
- return code >= HTTP_200_OK and code < HTTP_300_MULTIPLE_CHOICES
36
+ return code >= HTTPStatus . OK and code < HTTPStatus . MULTIPLE_CHOICES
44
37
45
38
def _is_http_client_error (self , code ):
46
39
# type: (int) -> bool
47
- return code >= HTTP_400_BAD_REQUEST and code < HTTP_500_INTERNAL_SERVER_ERROR
40
+ return code >= HTTPStatus . BAD_REQUEST and code < HTTPStatus . INTERNAL_SERVER_ERROR
48
41
49
42
def _is_http_server_error (self , code ):
50
43
# type: (int) -> bool
51
- return code >= HTTP_500_INTERNAL_SERVER_ERROR
44
+ return code >= HTTPStatus . INTERNAL_SERVER_ERROR
52
45
53
46
def _determine_response (self , response ):
54
47
"""
@@ -61,26 +54,26 @@ def _determine_response(self, response):
61
54
elif self ._is_http_client_error (response .status_code ):
62
55
body = response .json ()
63
56
message = body .get ('message' )
64
- if response .status_code == HTTP_400_BAD_REQUEST :
57
+ if response .status_code == HTTPStatus . BAD_REQUEST :
65
58
raise exceptions .InvalidGdaxRequest (message ,
66
- HTTP_400_BAD_REQUEST )
67
- elif response .status_code == HTTP_401_UNAUTHORIZED :
59
+ HTTPStatus . BAD_REQUEST )
60
+ elif response .status_code == HTTPStatus . UNAUTHORIZED :
68
61
raise exceptions .UnauthorizedGdaxRequest (message ,
69
- HTTP_401_UNAUTHORIZED )
70
- elif response .status_code == HTTP_403_FORBIDDEN :
62
+ HTTPStatus . UNAUTHORIZED )
63
+ elif response .status_code == HTTPStatus . FORBIDDEN :
71
64
raise exceptions .ForbiddenGdaxRequest (message ,
72
- HTTP_403_FORBIDDEN )
73
- elif response .status_code == HTTP_404_NOT_FOUND :
65
+ HTTPStatus . FORBIDDEN )
66
+ elif response .status_code == HTTPStatus . NOT_FOUND :
74
67
raise exceptions .NotFoundGdaxRequest (message ,
75
- HTTP_404_NOT_FOUND )
68
+ HTTPStatus . NOT_FOUND )
76
69
else : # Other 4XX response not yet mapped
77
70
raise exceptions .UnknownGdaxClientRequest (message ,
78
71
response .status_code )
79
72
80
73
elif self ._is_http_server_error (response .status_code ):
81
74
body = response .json ()
82
75
raise exceptions .InternalErrorGdaxRequest (body .get ('message' ),
83
- HTTP_500_INTERNAL_SERVER_ERROR )
76
+ HTTPStatus . INTERNAL_SERVER_ERROR )
84
77
85
78
def _get (self , path , params = None ):
86
79
"""Perform get request"""
0 commit comments