From d2d0fef416bdb15369f055106af633ce4e70e01e Mon Sep 17 00:00:00 2001 From: teleprint-me <77757836+teleprint-me@users.noreply.github.com> Date: Thu, 6 Jan 2022 16:29:03 -0500 Subject: [PATCH] CoinbasePro.plug Patch for 2.3.0 --- coinbase_pro/client.py | 5 +++-- docs/01-Quickstart.md | 24 ++++++++++++++++++++++-- docs/04-Client.md | 4 +++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/coinbase_pro/client.py b/coinbase_pro/client.py index 7892490..76b6e4b 100644 --- a/coinbase_pro/client.py +++ b/coinbase_pro/client.py @@ -213,8 +213,9 @@ def key(self) -> str: def name(self): return "coinbase_pro" - def plug(self, name: str, value: object): - setattr(self, name, value) + def plug(self, cls: object, name: str): + instance = cls(self.messenger) + setattr(self, name, instance) def get_messenger(settings: dict = None) -> Messenger: diff --git a/docs/01-Quickstart.md b/docs/01-Quickstart.md index 00009cf..d17266e 100644 --- a/docs/01-Quickstart.md +++ b/docs/01-Quickstart.md @@ -493,7 +493,7 @@ We should get the same result as before when we execute the sample code. ## Subscriber and CoinbasePro.plug -The `Subscriber` and `CoinbasePro` class allow you to create your own extensible classes. If we find there is not a class or method that supports a particular pattern or solution, then we can create out own instead and easily attach it to a `client` instance. +The `Subscriber` and `CoinbasePro` classes allow you to create your own extensible classes. If we find there is not a class or method that supports a particular pattern or solution, then we can create out own instead and easily attach it to a `client` instance. ```python #!/usr/bin/env python @@ -520,12 +520,32 @@ class History(Subscriber): client = get_client(get_settings("settings.json")["box"]) -client.plug("history", History(client.messenger)) +client.plug(History, "history") responses = client.history.list_({"product_id": "BTC-USD", "limit": 25}) print("[History]") pprint(responses[0][0]) ``` +Expected Output + +```sh +$ python cbot +[History] +{'created_at': '2022-01-06T20:16:07.397858Z', + 'fee': '0.4849978179585000', + 'liquidity': 'T', + 'order_id': '7319a3a3-2f2c-452f-9792-2d78fc5969fb', + 'price': '44185.71000000', + 'product_id': 'BTC-USD', + 'profile_id': 'fcada388-d6f6-47fe-8826-5afbceaf197c', + 'settled': True, + 'side': 'buy', + 'size': '0.00219527', + 'trade_id': 37319261, + 'usd_volume': '96.9995635917000000', + 'user_id': '5ee38d9688d076112365883f'} +``` + _Note: The `CoinbasePro.plug` method is currently experimental and should improve over time. Changes should be expected as the methods implementation is improved._ ## Notes diff --git a/docs/04-Client.md b/docs/04-Client.md index 1f0ccc8..5e6b963 100644 --- a/docs/04-Client.md +++ b/docs/04-Client.md @@ -541,11 +541,13 @@ A property that returns the client label. ### CoinbasePro.plug ```python -CoinbasePro.plug(name: str, value: object) +CoinbasePro.plug(cls: object, name: str) ``` A method used to attach 3rd party classes to extend the clients functionality. +_Note: This method is experimental and is subject to change._ + ## get_messenger ```python