diff --git a/cbpro/authenticated_client.py b/cbpro/authenticated_client.py index 0c2dc329..090135c4 100644 --- a/cbpro/authenticated_client.py +++ b/cbpro/authenticated_client.py @@ -173,6 +173,45 @@ def get_account_holds(self, account_id, **kwargs): endpoint = '/accounts/{}/holds'.format(account_id) return self._send_paginated_message(endpoint, params=kwargs) + def get_profiles(self, **kwargs): + """List Profiles + + List all account profiles (also known as portfolios). + + Returns: + [ + { + "id": "86602c68-306a-4500-ac73-4ce56a91d83c", + "user_id": "5844eceecf7e803e259d0365", + "name": "default", + "active": true, + "is_default": true, + "created_at": "2019-11-18T15:08:40.236309Z" + } + ] + """ + return self._send_message('get', '/profiles') + + def get_profile(self, profile_id, **kwargs): + """Get a Profile + + Get a single profile by profile id. + + Args: + profile_id(str): The profile id to get + + Returns: + { + "id": "86602c68-306a-4500-ac73-4ce56a91d83c", + "user_id": "5844eceecf7e803e259d0365", + "name": "default", + "active": true, + "is_default": true, + "created_at": "2019-11-18T15:08:40.236309Z" + } + """ + return self._send_message('get', '/profile/' + profile_id) + def place_order(self, product_id, side, order_type, **kwargs): """ Place an order. diff --git a/cbpro/public_client.py b/cbpro/public_client.py index e854a163..74b4bbd3 100644 --- a/cbpro/public_client.py +++ b/cbpro/public_client.py @@ -5,7 +5,10 @@ # For public requests to the Coinbase exchange import requests - +import time +import sys +import traceback +import ast class PublicClient(object): """cbpro public client API. @@ -269,7 +272,7 @@ def _send_message(self, method, endpoint, params=None, data=None): auth=self.auth, timeout=30) return r.json() - def _send_paginated_message(self, endpoint, params=None): + def _send_paginated_message(self, endpoint, params=None, **kwargs): """ Send API message that results in a paginated response. The paginated responses are abstracted away by making API requests on @@ -287,6 +290,7 @@ def _send_paginated_message(self, endpoint, params=None): Args: endpoint (str): Endpoint (to be added to base URL) params (Optional[dict]): HTTP request parameters + sleep_interval (Optional[float]): Number of seconds to sleep between paginated calls Yields: dict: API response objects @@ -295,11 +299,16 @@ def _send_paginated_message(self, endpoint, params=None): if params is None: params = dict() url = self.url + endpoint + while True: r = self.session.get(url, params=params, auth=self.auth, timeout=30) results = r.json() + #The sleep interval keyword argument was sent. + if "sleep_interval" in kwargs.keys(): + time.sleep(kwargs["sleep_interval"]) for result in results: - yield result + if result != "": + yield result # If there are no more pages, we're done. Otherwise update `after` # param to get next page. # If this request included `before` don't get any more pages - the