From 3ad742e507cd90306ac8f13359fb0d2b8ae0a767 Mon Sep 17 00:00:00 2001 From: Eugenio Polleri Date: Sat, 20 Mar 2021 20:41:59 +0100 Subject: [PATCH] #428 Added get_single_product --- README.md | 5 +++++ cbpro/public_client.py | 30 ++++++++++++++++++++++++++++++ tests/test_public_client.py | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/README.md b/README.md index 37872be3..bdd4cc23 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ public_client = cbpro.PublicClient() public_client.get_products() ``` +- [get_single_product](https://docs.pro.coinbase.com//#get-single-product) +```python +public_client.get_single_product('BTC-USD') +``` + - [get_product_order_book](https://docs.pro.coinbase.com/#get-product-order-book) ```python # Get the order book at the default level. diff --git a/cbpro/public_client.py b/cbpro/public_client.py index e854a163..893c8dc3 100644 --- a/cbpro/public_client.py +++ b/cbpro/public_client.py @@ -49,6 +49,36 @@ def get_products(self): """ return self._send_message('get', '/products') + def get_single_product(self, product_id): + """Get market data for a specific currency pair. + + Args: + product_id (str): Product + + Returns: + dict: Info about specific currency pairs. Example:: + { + "id": "BTC-USD", + "display_name": "BTC/USD", + "base_currency": "BTC", + "quote_currency": "USD", + "base_increment": "0.00000001", + "quote_increment": "0.01000000", + "base_min_size": "0.00100000", + "base_max_size": "280.00000000", + "min_market_funds": "5", + "max_market_funds": "1000000", + "status": "online", + "status_message": "", + "cancel_only": false, + "limit_only": false, + "post_only": false, + "trading_disabled": false + } + + """ + return self._send_message('get', '/products/{}'.format(product_id)) + def get_product_order_book(self, product_id, level=1): """Get a list of open orders for a product. diff --git a/tests/test_public_client.py b/tests/test_public_client.py index 10d2d1f7..2bb59fe7 100644 --- a/tests/test_public_client.py +++ b/tests/test_public_client.py @@ -22,6 +22,10 @@ def test_get_products(self, client): r = client.get_products() assert type(r) is list + def test_get_single_product(self, client): + r = client.get_single_product("BTC-USD") + assert isinstance(r, dict) + @pytest.mark.parametrize('level', [1, 2, 3, None]) def test_get_product_order_book(self, client, level): r = client.get_product_order_book('BTC-USD', level=level)