Skip to content

Commit

Permalink
v1.5.0 (#66)
Browse files Browse the repository at this point in the history
* Release v1.5.0
  • Loading branch information
kanugaba-cb authored Aug 21, 2024
1 parent 5338a94 commit 3ecd2d0
Show file tree
Hide file tree
Showing 29 changed files with 568 additions and 449 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# Changelog

## [1.5.0] - 2024-AUG-21

### Added
- `get_all_products` parameter to `get_products` and `get_public_products`
- `aggregation_price_increment` parameter to `get_product_book` and `get_public_product_book`
- Support for API key permissions endpoint with`get_api_key_permissions`
- Support for auto generating unique client_order_id when set to empty string
- Support for Futures Balance Summary Channel in `WSClient`

### Changed
- Heartbeats channel methods no longer require `product_ids`

## [1.4.3] - 2024-JUL-22

### Added
- - `order_ids`, `time_in_forces` and `sort_by` parameters in List Orders
- `trade_ids` and `sort_by` in List Fills
- `order_ids`, `time_in_forces` and `sort_by` parameters in List Orders
- `trade_ids` and `sort_by` in List Fills

### Changed
- `skip_fcm_risk_check` parameter removed from various Orders methods.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ print(dumps(order, indent=2))
```
This code calls the `get_accounts` and `market_order_buy` endpoints.

TIP: Setting `client_order_id` to the empty string will auto generate a unique client_order_id per call.
However, this will remove the intended safeguard of accidentally placing duplicate orders.

Refer to the [Advanced API Reference](https://docs.cdp.coinbase.com/advanced-trade/reference) for detailed information on each exposed endpoint.
Look in the `coinbase.rest` module to see the API hooks that are exposed.

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.4.3"
__version__ = "1.5.0"
5 changes: 2 additions & 3 deletions coinbase/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
# REST Constants
BASE_URL = "api.coinbase.com"
API_PREFIX = "/api/v3/brokerage"
REST_SERVICE = "retail_rest_api_proxy"

# Websocket Constants
WS_BASE_URL = "wss://advanced-trade-ws.coinbase.com"
WS_SERVICE = "public_websocket_api"

WS_RETRY_MAX = 5
WS_RETRY_BASE = 5
Expand All @@ -30,5 +28,6 @@
TICKER_BATCH = "ticker_batch"
LEVEL2 = "level2"
USER = "user"
FUTURES_BALANCE_SUMMARY = "futures_balance_summary"

WS_AUTH_CHANNELS = {USER}
WS_AUTH_CHANNELS = {USER, FUTURES_BALANCE_SUMMARY}
2 changes: 1 addition & 1 deletion coinbase/jwt_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jwt
from cryptography.hazmat.primitives import serialization

from coinbase.constants import BASE_URL, REST_SERVICE, WS_SERVICE
from coinbase.constants import BASE_URL


def build_jwt(key_var, secret_var, uri=None) -> str:
Expand Down
23 changes: 22 additions & 1 deletion coinbase/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@


class RESTClient(RESTBase):
"""
**RESTClient**
_____________________________
Initialize using RESTClient
__________
**Parameters**:
- **api_key | Optional (str)** - The API key
- **api_secret | Optional (str)** - The API key secret
- **key_file | Optional (IO | str)** - Path to API key file or file-like object
- **base_url | (str)** - The base URL for REST requests. Default set to "https://api.coinbase.com"
- **timeout | Optional (int)** - Set timeout in seconds for REST requests
- **verbose | Optional (bool)** - Enables debug logging. Default set to False
"""

from .accounts import get_account, get_accounts
from .convert import commit_convert_trade, create_convert_quote, get_convert_trade
from .data_api import get_api_key_permissions
from .fees import get_transaction_summary
from .futures import (
cancel_pending_futures_sweep,
close_position,
get_current_margin_window,
get_futures_balance_summary,
get_futures_position,
Expand All @@ -20,6 +40,7 @@ class RESTClient(RESTBase):
from .market_data import get_candles, get_market_trades
from .orders import (
cancel_orders,
close_position,
create_order,
edit_order,
get_fills,
Expand Down
28 changes: 28 additions & 0 deletions coinbase/rest/data_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any, Dict, Optional

from coinbase.constants import API_PREFIX


def get_api_key_permissions(
self,
**kwargs,
) -> Dict[str, Any]:
"""
**Get Api Key Permissions**
_____________________________
[GET] https://api.coinbase.com/api/v3/brokerage/key_permissions
__________
**Description:**
Get information about your CDP API key permissions
__________
**Read more on the official documentation:** `Create Convert Quote <https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_getapikeypermissions>`_
"""
endpoint = f"{API_PREFIX}/key_permissions"

return self.get(endpoint, **kwargs)
26 changes: 0 additions & 26 deletions coinbase/rest/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,6 @@
from coinbase.constants import API_PREFIX


def close_position(
self, client_order_id: str, product_id: str, size: Optional[str] = None, **kwargs
) -> Dict[str, Any]:
"""
**Close Position**
_________________
[POST] https://api.coinbase.com/api/v3/brokerage/orders/close_position
__________
**Description:**
Places an order to close any open positions for a specified ``product_id``.
__________
**Read more on the official documentation:** `Close Position
<https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_closeposition>`_
"""
endpoint = f"{API_PREFIX}/orders/close_position"
data = {"client_order_id": client_order_id, "product_id": product_id, "size": size}

return self.post(endpoint, data=data, **kwargs)


def get_futures_balance_summary(self, **kwargs) -> Dict[str, Any]:
"""
**Get Futures Balance Summary**
Expand Down
14 changes: 8 additions & 6 deletions coinbase/rest/market_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@


def get_candles(
self, product_id: str, start: str, end: str, granularity: str, **kwargs
self,
product_id: str,
start: str,
end: str,
granularity: str,
limit: Optional[int] = None,
**kwargs,
) -> Dict[str, Any]:
"""
**Get Product Candles**
Expand All @@ -25,11 +31,7 @@ def get_candles(
"""
endpoint = f"{API_PREFIX}/products/{product_id}/candles"

params = {
"start": start,
"end": end,
"granularity": granularity,
}
params = {"start": start, "end": end, "granularity": granularity, "limit": limit}

return self.get(endpoint, params=params, **kwargs)

Expand Down
Loading

0 comments on commit 3ecd2d0

Please sign in to comment.