Skip to content

Commit

Permalink
Merge pull request #18 from acontry/get-trade-by-trade-id
Browse files Browse the repository at this point in the history
Get trade by trade_id
  • Loading branch information
acontry authored Mar 14, 2021
2 parents f68cb62 + fc78e4a commit 8483405
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ dev

- [change here]

0.3.0 (2021-03-13)
++++++++++++++++++

**Improvements**

- Add `trade_id` param to `get_trades`. Allows you to get trades starting from an arbitrary trade, instead of only the most recent trade.

0.2.1 (2020-01-09)
++++++++++++++++++

Expand Down
11 changes: 9 additions & 2 deletions coinbasepro/public_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,17 @@ def get_product_ticker(self, product_id: str) -> Dict[str, Any]:
)
return self._convert_dict(r, field_conversions)

def get_product_trades(self, product_id: str) -> Iterator[Dict[str, Any]]:
def get_product_trades(
self, product_id: str, trade_id: Optional[int] = None
) -> Iterator[Dict[str, Any]]:
"""List the latest trades for a product.
This method returns a generator which may make multiple HTTP
requests while iterating through it.
Args:
product_id: Product.
trade_id: Trade id to start from.
Yields:
Latest trades. Example::
Expand All @@ -223,14 +226,18 @@ def get_product_trades(self, product_id: str) -> Iterator[Dict[str, Any]]:
See `get_products()`.
"""
params = {"after": trade_id + 1} if trade_id else None

field_conversions = {
"time": self._parse_datetime,
"trade_id": int,
"price": Decimal,
"size": Decimal,
}
trades = self._send_paginated_message(
"/products/{}/trades".format(product_id), rate_limiter=self.p_rate_limiter
"/products/{}/trades".format(product_id),
params=params,
rate_limiter=self.p_rate_limiter,
)
return (self._convert_dict(trade, field_conversions) for trade in trades)

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="coinbasepro",
version="0.2.1",
version="0.3.0",
description="A Python interface for the Coinbase Pro API.",
long_description=readme + "\n\n" + history,
long_description_content_type="text/x-rst",
Expand All @@ -32,5 +32,7 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
),
)

0 comments on commit 8483405

Please sign in to comment.