From dd81d20da520769092c6def237def87d3095c6f5 Mon Sep 17 00:00:00 2001 From: Pete Date: Wed, 30 Dec 2020 21:11:22 -0500 Subject: [PATCH 1/2] added profile lookup --- cbpro/authenticated_client.py | 52 ++++++++++++++++++++++++++++++ tests/test_authenticated_client.py | 9 ++++++ 2 files changed, 61 insertions(+) diff --git a/cbpro/authenticated_client.py b/cbpro/authenticated_client.py index f330377..e37b675 100644 --- a/cbpro/authenticated_client.py +++ b/cbpro/authenticated_client.py @@ -1047,3 +1047,55 @@ def get_fees(self): } """ return self._send_message('get', '/fees') + + def get_profiles(self, active): + """ List Profiles. + + List your profiles. + + https://docs.pro.coinbase.com/#list-profiles + + Args: + active (bool): active flag + + Returns: + list: List your profiles, profiles are equivalent to portfolios. + + [ + { + "id": "86602c68-306a-4500-ac73-4ce56a91d83c", + "user_id": "5844eceecf7e803e259d0365", + "name": "default", + "active": true, + "is_default": true, + "created_at": "2019-11-18T15:08:40.236309Z" + } + ] + """ + if active is not None: + params = {'active': active} + else: + params = None + return self._send_message('get', '/profiles', params=params) + + def get_profile(self, profile_id): + """ Get a Profile + + Get a single profile by profile id. + + Args: + profile_id (str): profile id + + Returns: + dict: Single Profile + + { + "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/' + profile_id) \ No newline at end of file diff --git a/tests/test_authenticated_client.py b/tests/test_authenticated_client.py index 36ae1be..cd129e0 100644 --- a/tests/test_authenticated_client.py +++ b/tests/test_authenticated_client.py @@ -206,3 +206,12 @@ def test_get_trailing_volume(self, client): def test_get_fees(self, client): r = client.get_fees() assert type(r) is dict + + def test_get_profiles(self, client): + r = client.get_profiles() + assert type(r) is list + + def test_get_profile_by_id(self, client): + # Took the id from the docs as the sample response. + r = client.get_profile('86602c68-306a-4500-ac73-4ce56a91d83c') + assert type(r) is dict From 2c3cab961f51546dfe557d0093dfb6e22db2185e Mon Sep 17 00:00:00 2001 From: Pete Date: Wed, 30 Dec 2020 21:12:58 -0500 Subject: [PATCH 2/2] added final return in file --- cbpro/authenticated_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbpro/authenticated_client.py b/cbpro/authenticated_client.py index e37b675..d022545 100644 --- a/cbpro/authenticated_client.py +++ b/cbpro/authenticated_client.py @@ -1098,4 +1098,4 @@ def get_profile(self, profile_id): "created_at": "2019-11-18T15:08:40.236309Z" } """ - return self._send_message('get', '/profiles/' + profile_id) \ No newline at end of file + return self._send_message('get', '/profiles/' + profile_id)