cbpro public client API. All requests default to the `product_id` specified at object creation if not otherwise specified. Attributes: url (Optional[str]): API URL. Defaults to cbpro API.
| 8 | |
| 9 | |
| 10 | class PublicClient(object): |
| 11 | """cbpro public client API. |
| 12 | |
| 13 | All requests default to the `product_id` specified at object |
| 14 | creation if not otherwise specified. |
| 15 | |
| 16 | Attributes: |
| 17 | url (Optional[str]): API URL. Defaults to cbpro API. |
| 18 | |
| 19 | """ |
| 20 | |
| 21 | def __init__(self, api_url='https://api.pro.coinbase.com', timeout=30): |
| 22 | """Create cbpro API public client. |
| 23 | |
| 24 | Args: |
| 25 | api_url (Optional[str]): API URL. Defaults to cbpro API. |
| 26 | |
| 27 | """ |
| 28 | self.url = api_url.rstrip('/') |
| 29 | self.auth = None |
| 30 | self.session = requests.Session() |
| 31 | |
| 32 | def get_products(self): |
| 33 | """Get a list of available currency pairs for trading. |
| 34 | |
| 35 | Returns: |
| 36 | list: Info about all currency pairs. Example:: |
| 37 | [ |
| 38 | { |
| 39 | "id": "BTC-USD", |
| 40 | "display_name": "BTC/USD", |
| 41 | "base_currency": "BTC", |
| 42 | "quote_currency": "USD", |
| 43 | "base_min_size": "0.01", |
| 44 | "base_max_size": "10000.00", |
| 45 | "quote_increment": "0.01" |
| 46 | } |
| 47 | ] |
| 48 | |
| 49 | """ |
| 50 | return self._send_message('get', '/products') |
| 51 | |
| 52 | def get_product_order_book(self, product_id, level=1): |
| 53 | """Get a list of open orders for a product. |
| 54 | |
| 55 | The amount of detail shown can be customized with the `level` |
| 56 | parameter: |
| 57 | * 1: Only the best bid and ask |
| 58 | * 2: Top 50 bids and asks (aggregated) |
| 59 | * 3: Full order book (non aggregated) |
| 60 | |
| 61 | Level 1 and Level 2 are recommended for polling. For the most |
| 62 | up-to-date data, consider using the websocket stream. |
| 63 | |
| 64 | **Caution**: Level 3 is only recommended for users wishing to |
| 65 | maintain a full real-time order book using the websocket |
| 66 | stream. Abuse of Level 3 via polling will cause your access to |
| 67 | be limited or blocked. |