>>> import coinbasepro as cbp
>>> client = cbp.PublicClient()
# datetime and Decimal are among the return types in the dict returned
# by this call:
>>> client.get_product_ticker('BTC-USD')
{'trade_id': 2845680,
'price': Decimal('2496.69000000'),
'size': Decimal('0.00100000'),
'time': datetime.datetime(2019, 3, 20, 23, 53, 59, 596000),
'bid': Decimal('2496.69'), 'ask': Decimal('2496.7'),
'volume': Decimal('771.51495215')}
>>> import itertools
# get_product_trades is a generator
>>> client.get_product_trades('BTC-USD')
<generator object PublicClient.get_product_trades.<locals>.<genexpr> at 0x1098d6f68>
# Get 2 most recent trades. For many trade requests (>100), multiple
# HTTP requests will be made under the hood.
>>> list(itertools.islice(client.get_product_trades('BTC-USD'), 2))
[{'time': datetime.datetime(2019, 3, 21, 0, 2, 45, 609000),
'trade_id': 2845779,
'price': Decimal('2463.38000000'),
'size': Decimal('0.00100000'),
'side': 'buy'},
{'time': datetime.datetime(2019, 3, 21, 0, 2, 39, 877000),
'trade_id': 2845778,
'price': Decimal('2463.39000000'),
'size': Decimal('0.00100000'),
'side': 'sell'}]
# CBPro API returns raw candles from this call as tuples, which would
# require user to look up value meaning in API docs. This python API
# returns candles as a list of dicts, similar to other API endpoints.
# Get first candle:
>>> client.get_product_historic_rates('BTC-USD')[0]
{'time': datetime.datetime(2019, 3, 21, 0, 6),
'low': Decimal('2463.3'),
'high': Decimal('2463.31'),
'open': Decimal('2463.3'),
'close': Decimal('2463.31'),
'volume': Decimal('0.006')}
# Example function prototype in API
def get_product_ticker(self, product_id: str) -> Dict[str, Any]: