|
6 | 6 |
|
7 | 7 | from http import HTTPStatus |
8 | 8 | import requests |
9 | | -from gdax import exceptions |
| 9 | +from cbpro import exceptions |
10 | 10 |
|
11 | 11 |
|
12 | 12 | class PublicClient(object): |
@@ -46,45 +46,39 @@ def _is_http_server_error(self, code): |
46 | 46 |
|
47 | 47 | def _determine_response(self, response): |
48 | 48 | """ |
49 | | - Determines if GDAX response is success or error |
| 49 | + Determines if CBPRO response is success or error |
50 | 50 | If success, returns response json |
51 | | - If error, raises appropriate GdaxException |
| 51 | + If error, raises appropriate CbproException |
52 | 52 | """ |
53 | 53 | if self._is_http_success(response.status_code): |
54 | 54 | return response.json() |
55 | 55 | elif self._is_http_client_error(response.status_code): |
56 | 56 | body = response.json() |
57 | 57 | message = body.get('message') |
58 | 58 | if response.status_code == HTTPStatus.BAD_REQUEST: |
59 | | - raise exceptions.InvalidGdaxRequest(message, |
| 59 | + raise exceptions.InvalidCbproRequest(message, |
60 | 60 | HTTPStatus.BAD_REQUEST) |
61 | 61 | elif response.status_code == HTTPStatus.UNAUTHORIZED: |
62 | | - raise exceptions.UnauthorizedGdaxRequest(message, |
| 62 | + raise exceptions.UnauthorizedCbproRequest(message, |
63 | 63 | HTTPStatus.UNAUTHORIZED) |
64 | 64 | elif response.status_code == HTTPStatus.FORBIDDEN: |
65 | | - raise exceptions.ForbiddenGdaxRequest(message, |
| 65 | + raise exceptions.ForbiddenCbproRequest(message, |
66 | 66 | HTTPStatus.FORBIDDEN) |
67 | 67 | elif response.status_code == HTTPStatus.NOT_FOUND: |
68 | | - raise exceptions.NotFoundGdaxRequest(message, |
| 68 | + raise exceptions.NotFoundCbproRequest(message, |
69 | 69 | HTTPStatus.NOT_FOUND) |
70 | 70 | elif response.status_code == HTTPStatus.TOO_MANY_REQUESTS: |
71 | | - raise exceptions.GdaxRateLimitRequest(message, |
| 71 | + raise exceptions.CbproRateLimitRequest(message, |
72 | 72 | HTTPStatus.TOO_MANY_REQUESTS) |
73 | 73 | else: # Other 4XX response not yet mapped |
74 | | - raise exceptions.UnknownGdaxClientRequest(message, |
| 74 | + raise exceptions.UnknownCbproClientRequest(message, |
75 | 75 | response.status_code) |
76 | 76 |
|
77 | 77 | elif self._is_http_server_error(response.status_code): |
78 | 78 | body = response.json() |
79 | | - raise exceptions.InternalErrorGdaxRequest(body.get('message'), |
| 79 | + raise exceptions.InternalErrorCbproRequest(body.get('message'), |
80 | 80 | HTTPStatus.INTERNAL_SERVER_ERROR) |
81 | 81 |
|
82 | | - def _get(self, path, params=None): |
83 | | - """Perform get request""" |
84 | | - |
85 | | - r = requests.get(self.url + path, params=params, timeout=self.timeout) |
86 | | - return self._determine_response(r) |
87 | | - |
88 | 82 | def get_products(self): |
89 | 83 | """Get a list of available currency pairs for trading. |
90 | 84 |
|
@@ -323,7 +317,7 @@ def _send_message(self, method, endpoint, params=None, data=None): |
323 | 317 | url = self.url + endpoint |
324 | 318 | r = self.session.request(method, url, params=params, data=data, |
325 | 319 | auth=self.auth, timeout=30) |
326 | | - return r.json() |
| 320 | + return self._determine_response(r) |
327 | 321 |
|
328 | 322 | def _send_paginated_message(self, endpoint, params=None): |
329 | 323 | """ Send API message that results in a paginated response. |
@@ -353,7 +347,7 @@ def _send_paginated_message(self, endpoint, params=None): |
353 | 347 | url = self.url + endpoint |
354 | 348 | while True: |
355 | 349 | r = self.session.get(url, params=params, auth=self.auth, timeout=30) |
356 | | - results = r.json() |
| 350 | + results = self._determine_response(r) |
357 | 351 | for result in results: |
358 | 352 | yield result |
359 | 353 | # If there are no more pages, we're done. Otherwise update `after` |
|
0 commit comments