Skip to content

Commit

Permalink
Release v1.6.2 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
urischwartz-cb authored Sep 9, 2024
1 parent 06693f3 commit fc54eed
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [1.6.2] - 2024-SEP-09

### Added
- Support for RESTClient to append rate limit response headers to REST response bodies by setting `rate_limit_headers` to `True`.

## [1.6.1] - 2024-SEP-05

### Added
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ market_trades = client.get_market_trades(product_id="BTC-USD", limit=5)
portfolio = client.create_portfolio(name="TestPortfolio")
```

### Rate Limit Response Headers
The Advanced API returns useful rate limit information in the response headers as detailed in our [documentation](https://docs.cdp.coinbase.com/advanced-trade/docs/rest-api-rate-limits#private-endpoints). By initializing the RESTClient with the `rate_limit_headers` field set to True, as shown below, these headers will be appended as fields to the API response body:
```python
client = RESTClient(api_key=api_key, api_secret=api_secret, rate_limit_headers=True)
```

___
## WebSocket API Client
We offer a WebSocket API client that allows you to connect to the [Coinbase Advanced Trade WebSocket API](https://docs.cdp.coinbase.com/advanced-trade/docs/ws-overview).
Expand Down
2 changes: 1 addition & 1 deletion coinbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.6.1"
__version__ = "1.6.2"
5 changes: 5 additions & 0 deletions coinbase/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@
FUTURES_BALANCE_SUMMARY = "futures_balance_summary"

WS_AUTH_CHANNELS = {USER, FUTURES_BALANCE_SUMMARY}

X_RATELIMIT_LIMIT = "x-ratelimit-limit"
X_RATELIMIT_REMAINING = "x-ratelimit-remaining"
X_RATELIMIT_RESET = "x-ratelimit-reset"
RATE_LIMIT_HEADERS = {X_RATELIMIT_LIMIT, X_RATELIMIT_REMAINING, X_RATELIMIT_RESET}
22 changes: 20 additions & 2 deletions coinbase/rest/rest_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

from coinbase import jwt_generator
from coinbase.api_base import APIBase, get_logger
from coinbase.constants import API_ENV_KEY, API_SECRET_ENV_KEY, BASE_URL, USER_AGENT
from coinbase.constants import (
API_ENV_KEY,
API_SECRET_ENV_KEY,
BASE_URL,
RATE_LIMIT_HEADERS,
USER_AGENT,
)

logger = get_logger("coinbase.RESTClient")

Expand Down Expand Up @@ -54,6 +60,7 @@ def __init__(
base_url=BASE_URL,
timeout: Optional[int] = None,
verbose: Optional[bool] = False,
rate_limit_headers: Optional[bool] = False,
):
super().__init__(
api_key=api_key,
Expand All @@ -63,6 +70,7 @@ def __init__(
timeout=timeout,
verbose=verbose,
)
self.rate_limit_headers = rate_limit_headers
self.session = requests.Session()
if verbose:
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -221,7 +229,17 @@ def send_request(self, http_method, url_path, params, headers, data=None):

logger.debug(f"Raw response: {response.json()}")

return response.json()
response_data = response.json()

if self.rate_limit_headers:
response_headers = dict(response.headers)
specific_headers = {
key: response_headers.get(key, None) for key in RATE_LIMIT_HEADERS
}

response_data = {**response_data, **specific_headers}

return response_data

def set_headers(self, method, path):
"""
Expand Down

0 comments on commit fc54eed

Please sign in to comment.