Skip to content

Commit

Permalink
Release v1.7.0 (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidMkCb authored Oct 16, 2024
1 parent fc54eed commit 81b0e1c
Show file tree
Hide file tree
Showing 43 changed files with 2,182 additions and 271 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.7.0] - 2024-OCT-16

### Added
- Custom response types to REST endpoints
- Dot-notation and auto-completing fields for defined objects

## [1.6.2] - 2024-SEP-09

### Added
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Welcome to the official Coinbase Advanced API Python SDK. This python project was created to allow coders to easily plug into the [Coinbase Advanced API](https://docs.cdp.coinbase.com/advanced-trade/docs/welcome).
This SDK also supports easy connection to the [Coinbase Advanced Trade WebSocket API](https://docs.cdp.coinbase.com/advanced-trade/docs/ws-overview).

Coinbase Advanced Trade offers a comprehensive API for traders, providing access to real-time market data, order management, and execution. Elevate your trading strategies and develop sophisticated solutions using our powerful tools and features.

For thorough documentation of all available functions, refer to the following link: https://coinbase.github.io/coinbase-advanced-py

___
Expand Down Expand Up @@ -80,6 +82,20 @@ However, this will remove the intended safeguard of accidentally placing duplica
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.

### Custom Response Objects
Endpoints will return corresponding, custom class objects. This allows you to retrieve response object fields using dot-notation. Here is an example of how you can access a product's price via the Get Product endpoint:
```python
product = client.get_product("BTC-USD")
print(product.price)
```
Dot-notation is only available for fields that are defined. Although all higher-level fields have been defined, not every nested field has. Fields that are not defined are still accessible using standard bracket notation.

For example, we make a call to List Accounts. We take the first account from the defined `accounts` field and access the defined `available_balance` field. Despite its nested fields not being explicitly defined and inaccessible via dot-notation, we can still access them manually using bracket notation, like:
```python
accounts = client.get_accounts()
print(accounts.accounts[0].available_balance['value'])
```

### Passing in additional parameters
Use `kwargs` to pass in any additional parameters. For example:
```python
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.2"
__version__ = "1.7.0"
2 changes: 1 addition & 1 deletion coinbase/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RESTClient(RESTBase):
- **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
- **rate_limit_headers | Optional (bool)** - Enables rate limit headers. Default set to False
"""

Expand Down
9 changes: 5 additions & 4 deletions coinbase/rest/accounts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Optional

from coinbase.constants import API_PREFIX
from coinbase.rest.types.accounts_types import GetAccountResponse, ListAccountsResponse


def get_accounts(
Expand All @@ -9,7 +10,7 @@ def get_accounts(
cursor: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
) -> ListAccountsResponse:
"""
**List Accounts**
_________________
Expand All @@ -33,10 +34,10 @@ def get_accounts(
"retail_portfolio_id": retail_portfolio_id,
}

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


def get_account(self, account_uuid: str, **kwargs) -> Dict[str, Any]:
def get_account(self, account_uuid: str, **kwargs) -> GetAccountResponse:
"""
**Get Account**
Expand All @@ -55,4 +56,4 @@ def get_account(self, account_uuid: str, **kwargs) -> Dict[str, Any]:
"""
endpoint = f"{API_PREFIX}/accounts/{account_uuid}"

return self.get(endpoint, **kwargs)
return GetAccountResponse(self.get(endpoint, **kwargs))
17 changes: 11 additions & 6 deletions coinbase/rest/convert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Any, Dict, Optional

from coinbase.constants import API_PREFIX
from coinbase.rest.types.convert_types import (
CommitConvertTradeResponse,
CreateConvertQuoteResponse,
GetConvertTradeResponse,
)


def create_convert_quote(
Expand All @@ -11,7 +16,7 @@ def create_convert_quote(
user_incentive_id: Optional[str] = None,
code_val: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
) -> CreateConvertQuoteResponse:
"""
**Create Convert Quote**
________________________
Expand Down Expand Up @@ -49,12 +54,12 @@ def create_convert_quote(
if filtered_trade_incentive_metadata:
data["trade_incentive_metadata"] = filtered_trade_incentive_metadata

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


def get_convert_trade(
self, trade_id: str, from_account: str, to_account: str, **kwargs
) -> Dict[str, Any]:
) -> GetConvertTradeResponse:
"""
**Get Convert Trade**
_____________________
Expand All @@ -78,12 +83,12 @@ def get_convert_trade(
"to_account": to_account,
}

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


def commit_convert_trade(
self, trade_id: str, from_account: str, to_account: str, **kwargs
) -> Dict[str, Any]:
) -> CommitConvertTradeResponse:
"""
**Commit Convert Trade**
________________________
Expand All @@ -107,4 +112,4 @@ def commit_convert_trade(
"to_account": to_account,
}

return self.post(endpoint, data=data, **kwargs)
return CommitConvertTradeResponse(self.post(endpoint, data=data, **kwargs))
5 changes: 3 additions & 2 deletions coinbase/rest/data_api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import Any, Dict, Optional

from coinbase.constants import API_PREFIX
from coinbase.rest.types.data_api_types import GetAPIKeyPermissionsResponse


def get_api_key_permissions(
self,
**kwargs,
) -> Dict[str, Any]:
) -> GetAPIKeyPermissionsResponse:
"""
**Get Api Key Permissions**
_____________________________
Expand All @@ -25,4 +26,4 @@ def get_api_key_permissions(
"""
endpoint = f"{API_PREFIX}/key_permissions"

return self.get(endpoint, **kwargs)
return GetAPIKeyPermissionsResponse(self.get(endpoint, **kwargs))
5 changes: 3 additions & 2 deletions coinbase/rest/fees.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Optional

from coinbase.constants import API_PREFIX
from coinbase.rest.types.fees_types import GetTransactionSummaryResponse


def get_transaction_summary(
Expand All @@ -9,7 +10,7 @@ def get_transaction_summary(
contract_expiry_type: Optional[str] = None,
product_venue: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
) -> GetTransactionSummaryResponse:
"""
**Get Transactions Summary**
_____________________________
Expand All @@ -34,4 +35,4 @@ def get_transaction_summary(
"product_venue": product_venue,
}

return self.get(endpoint, params=params, **kwargs)
return GetTransactionSummaryResponse(self.get(endpoint, params=params, **kwargs))
51 changes: 33 additions & 18 deletions coinbase/rest/futures.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from typing import Any, Dict, Optional

from coinbase.constants import API_PREFIX
from coinbase.rest.types.futures_types import (
CancelPendingFuturesSweepResponse,
GetCurrentMarginWindowResponse,
GetFuturesBalanceSummaryResponse,
GetFuturesPositionResponse,
GetIntradayMarginSettingResponse,
ListFuturesPositionsResponse,
ListFuturesSweepsResponse,
ScheduleFuturesSweepResponse,
SetIntradayMarginSettingResponse,
)


def get_futures_balance_summary(self, **kwargs) -> Dict[str, Any]:
def get_futures_balance_summary(self, **kwargs) -> GetFuturesBalanceSummaryResponse:
"""
**Get Futures Balance Summary**
_______________________________
Expand All @@ -23,10 +34,10 @@ def get_futures_balance_summary(self, **kwargs) -> Dict[str, Any]:
"""
endpoint = f"{API_PREFIX}/cfm/balance_summary"

return self.get(endpoint, **kwargs)
return GetFuturesBalanceSummaryResponse(self.get(endpoint, **kwargs))


def list_futures_positions(self, **kwargs) -> Dict[str, Any]:
def list_futures_positions(self, **kwargs) -> ListFuturesPositionsResponse:
"""
**List Futures Positions**
__________________________
Expand All @@ -46,10 +57,10 @@ def list_futures_positions(self, **kwargs) -> Dict[str, Any]:
"""
endpoint = f"{API_PREFIX}/cfm/positions"

return self.get(endpoint, **kwargs)
return ListFuturesPositionsResponse(self.get(endpoint, **kwargs))


def get_futures_position(self, product_id: str, **kwargs) -> Dict[str, Any]:
def get_futures_position(self, product_id: str, **kwargs) -> GetFuturesPositionResponse:
"""
**Get Futures Position**
_________________________
Expand All @@ -69,10 +80,12 @@ def get_futures_position(self, product_id: str, **kwargs) -> Dict[str, Any]:
"""
endpoint = f"{API_PREFIX}/cfm/positions/{product_id}"

return self.get(endpoint, **kwargs)
return GetFuturesPositionResponse(self.get(endpoint, **kwargs))


def schedule_futures_sweep(self, usd_amount: str, **kwargs) -> Dict[str, Any]:
def schedule_futures_sweep(
self, usd_amount: str, **kwargs
) -> ScheduleFuturesSweepResponse:
"""
**Schedule Futures Sweep**
__________________________
Expand All @@ -94,10 +107,10 @@ def schedule_futures_sweep(self, usd_amount: str, **kwargs) -> Dict[str, Any]:

data = {"usd_amount": usd_amount}

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


def list_futures_sweeps(self, **kwargs) -> Dict[str, Any]:
def list_futures_sweeps(self, **kwargs) -> ListFuturesSweepsResponse:
"""
**List Futures Sweeps**
_______________________
Expand All @@ -117,10 +130,10 @@ def list_futures_sweeps(self, **kwargs) -> Dict[str, Any]:
"""
endpoint = f"{API_PREFIX}/cfm/sweeps"

return self.get(endpoint, **kwargs)
return ListFuturesSweepsResponse(self.get(endpoint, **kwargs))


def cancel_pending_futures_sweep(self, **kwargs) -> Dict[str, Any]:
def cancel_pending_futures_sweep(self, **kwargs) -> CancelPendingFuturesSweepResponse:
"""
**Cancel Pending Futures Sweep**
________________________________
Expand All @@ -140,10 +153,10 @@ def cancel_pending_futures_sweep(self, **kwargs) -> Dict[str, Any]:
"""
endpoint = f"{API_PREFIX}/cfm/sweeps"

return self.delete(endpoint, **kwargs)
return CancelPendingFuturesSweepResponse(self.delete(endpoint, **kwargs))


def get_intraday_margin_setting(self, **kwargs) -> Dict[str, Any]:
def get_intraday_margin_setting(self, **kwargs) -> GetIntradayMarginSettingResponse:
"""
**Get Intraday Margin Setting**
_______________________________
Expand All @@ -163,12 +176,12 @@ def get_intraday_margin_setting(self, **kwargs) -> Dict[str, Any]:
"""
endpoint = f"{API_PREFIX}/cfm/intraday/margin_setting"

return self.get(endpoint, **kwargs)
return GetIntradayMarginSettingResponse(self.get(endpoint, **kwargs))


def get_current_margin_window(
self, margin_profile_type: str, **kwargs
) -> Dict[str, Any]:
) -> GetCurrentMarginWindowResponse:
"""
**Get Current Margin Window**
________________________________
Expand All @@ -191,10 +204,12 @@ def get_current_margin_window(

params = {"margin_profile_type": margin_profile_type}

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


def set_intraday_margin_setting(self, setting: str, **kwargs) -> Dict[str, Any]:
def set_intraday_margin_setting(
self, setting: str, **kwargs
) -> SetIntradayMarginSettingResponse:
"""
**Set Intraday Margin Setting**
________________________________
Expand All @@ -217,4 +232,4 @@ def set_intraday_margin_setting(self, setting: str, **kwargs) -> Dict[str, Any]:

data = {"setting": setting}

return self.post(endpoint, data=data, **kwargs)
return SetIntradayMarginSettingResponse(self.post(endpoint, data=data, **kwargs))
12 changes: 8 additions & 4 deletions coinbase/rest/market_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Any, Dict, Optional

from coinbase.constants import API_PREFIX
from coinbase.rest.types.product_types import (
GetMarketTradesResponse,
GetProductCandlesResponse,
)


def get_candles(
Expand All @@ -11,7 +15,7 @@ def get_candles(
granularity: str,
limit: Optional[int] = None,
**kwargs,
) -> Dict[str, Any]:
) -> GetProductCandlesResponse:
"""
**Get Product Candles**
__________
Expand All @@ -33,7 +37,7 @@ def get_candles(

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

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


def get_market_trades(
Expand All @@ -43,7 +47,7 @@ def get_market_trades(
start: Optional[str] = None,
end: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
) -> GetMarketTradesResponse:
"""
**Get Market Trades**
_____________________
Expand All @@ -65,4 +69,4 @@ def get_market_trades(

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

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

0 comments on commit 81b0e1c

Please sign in to comment.