Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README, add CHANGELOG, increase test coverage, and cleanup setup.py #7

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ venv.bak/
.dmypy.json
dmypy.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
urischwartz-cb marked this conversation as resolved.
Show resolved Hide resolved
.hypothesis/
.python-version
test.py
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## [1.0.0] - 2023-DEC-18

### Added
- Initial release of the Coinbase Advanced Trading API Python SDK
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Coinbase Advanced Trading API Python SDK
[![PyPI version](https://badge.fury.io/py/coinbase-advanced.svg)](https://badge.fury.io/py/coinbase-advanced)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/license/apache-2-0/)
[![Code Style](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)

Welcome to the official Coinbase Advanced Trading API Python SDK. This python project was created to allow coders to easily plug into the [Coinbase Advanced Trade API](https://docs.cloud.coinbase.com/advanced-trade-api/docs/welcome).

## Installation

To install, please clone this git repo, cd into the root and run:
```bash
pip3 install .
pip3 install coinbase-advanced
```

## Cloud API Keys
Expand Down Expand Up @@ -52,14 +54,13 @@ from json import dumps
accounts = client.get_accounts()
print(dumps(accounts, indent=2))

order = client.market_order_buy("clientOrderId", "BTC-USD", "1")
order = client.market_order_buy(client_order_id="clientOrderId", product_id="BTC-USD", quote_size="1")
print(dumps(order, indent=2))
```
This code calls the `get_accounts` and `market_order_buy` endpoints.

You can refer to the [Advanced Trade API Reference](https://docs.cloud.coinbase.com/advanced-trade-api/reference) for detailed information on each exposed endpoint.
You can look at the following [mapping](Todo--add link here) to see which API hook corresponds to which endpoint.

You can look in the `coinbase.rest` module to see the API hooks that are exposed.

### Passing in additional parameters
You can use `kwargs` to pass in any additional parameters. For example:
Expand All @@ -79,11 +80,11 @@ market_trades = client.get("/api/v3/brokerage/products/BTC-USD/ticker", params={
portfolio = client.post("/api/v3/brokerage/portfolios", data={"name": "TestPortfolio"})
```
Here we are calling the [GetMarketTrades](https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getmarkettrades) and [CreatePortfolio](https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_createportfolio) endpoints through the generic REST functions.
Once again, the built in way to query these through the SDK would be:
Once again, the built-in way to query these through the SDK would be:
```python
market_trades = client.get_market_trades("BTC-USD", 5)
market_trades = client.get_market_trades(product_id="BTC-USD", limit=5)

portfolio = client.create_portfolio("TestPortfolio")
portfolio = client.create_portfolio(name="TestPortfolio")
```

## Authentication
Expand Down Expand Up @@ -117,6 +118,9 @@ jwt = jwt_generator.build_ws_jwt(api_key, api_secret)
```
You can use this JWT to connect to the Websocket API by setting it in the "jwt" field of your subscription requests. See the docs [here](https://docs.cloud.coinbase.com/advanced-trade-api/docs/ws-overview#sending-messages-using-cloud-api-keys) for more details.

## Changelog
For a detailed list of changes, see the [Changelog](CHANGELOG.md).

## Contributing

If you've found a bug within this project, please open an issue on this repo and add the "bug" label to it.
Expand Down
11 changes: 2 additions & 9 deletions coinbase/rest/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def get_accounts(
endpoint = f"{API_PREFIX}/accounts"
params = {"limit": limit, "cursor": cursor}

if kwargs:
params.update(kwargs)

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


def get_account(self, account_uuid: str, **kwargs):
Expand All @@ -28,8 +25,4 @@ def get_account(self, account_uuid: str, **kwargs):
"""
endpoint = f"{API_PREFIX}/accounts/{account_uuid}"

params = {}
if kwargs:
params.update(kwargs)

return self.get(endpoint, params=params)
return self.get(endpoint, **kwargs)
6 changes: 1 addition & 5 deletions coinbase/rest/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ def get_unix_time(self, **kwargs):
"""
endpoint = f"{API_PREFIX}/time"

params = {}
if kwargs:
params.update(kwargs)

return self.get(endpoint, params=params)
return self.get(endpoint, **kwargs)
15 changes: 3 additions & 12 deletions coinbase/rest/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def create_convert_quote(
if filtered_trade_incentive_metadata:
data["trade_incentive_metadata"] = filtered_trade_incentive_metadata

if kwargs:
data.update(kwargs)

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


def get_convert_trade(
Expand All @@ -59,10 +56,7 @@ def get_convert_trade(
"to_account": to_account,
}

if kwargs:
params.update(kwargs)

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


def commit_convert_trade(
Expand All @@ -80,7 +74,4 @@ def commit_convert_trade(
"to_account": to_account,
}

if kwargs:
data.update(kwargs)

return self.post(endpoint, data=data)
return self.post(endpoint, data=data, **kwargs)
5 changes: 1 addition & 4 deletions coinbase/rest/fees.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@ def get_transaction_summary(
"contract_expiry_type": contract_expiry_type,
}

if kwargs:
params.update(kwargs)

return self.get(endpoint, params=params)
return self.get(endpoint, params=params, **kwargs)
10 changes: 2 additions & 8 deletions coinbase/rest/market_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ def get_candles(
"granularity": granularity,
}

if kwargs:
params.update(kwargs)

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


def get_market_trades(
Expand All @@ -42,7 +39,4 @@ def get_market_trades(

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

if kwargs:
params.update(kwargs)

return self.get(endpoint, params=params)
return self.get(endpoint, params=params, **kwargs)
36 changes: 7 additions & 29 deletions coinbase/rest/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ def create_order(
"retail_portfolio_id": retail_portfolio_id,
}

if kwargs:
data.update(kwargs)

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


# Market orders
Expand Down Expand Up @@ -625,11 +622,7 @@ def get_order(self, order_id: str, **kwargs):
"""
endpoint = f"{API_PREFIX}/orders/historical/{order_id}"

params = {}
if kwargs:
params.update(kwargs)

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


def list_orders(
Expand Down Expand Up @@ -671,10 +664,7 @@ def list_orders(
"retail_portfolio_id": retail_portfolio_id,
}

if kwargs:
params.update(kwargs)

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


def get_fills(
Expand Down Expand Up @@ -702,10 +692,7 @@ def get_fills(
"cursor": cursor,
}

if kwargs:
params.update(kwargs)

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


def edit_order(
Expand All @@ -728,10 +715,7 @@ def edit_order(
"price": price,
}

if kwargs:
data.update(kwargs)

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


def preview_edit_order(
Expand All @@ -754,10 +738,7 @@ def preview_edit_order(
"price": price,
}

if kwargs:
data.update(kwargs)

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


def cancel_orders(self, order_ids: List[str], **kwargs):
Expand All @@ -771,7 +752,4 @@ def cancel_orders(self, order_ids: List[str], **kwargs):
"order_ids": order_ids,
}

if kwargs:
data.update(kwargs)

return self.post(endpoint, data=data)
return self.post(endpoint, data=data, **kwargs)
32 changes: 6 additions & 26 deletions coinbase/rest/portfolios.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ def get_portfolios(self, portfolio_type: Optional[str] = None, **kwargs):

params = {"portfolio_type": portfolio_type}

if kwargs:
params.update(kwargs)

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


def create_portfolio(self, name: str, **kwargs):
Expand All @@ -31,10 +28,7 @@ def create_portfolio(self, name: str, **kwargs):
"name": name,
}

if kwargs:
data.update(kwargs)

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


def get_portfolio_breakdown(self, portfolio_uuid: str, **kwargs):
Expand All @@ -45,11 +39,7 @@ def get_portfolio_breakdown(self, portfolio_uuid: str, **kwargs):
"""
endpoint = f"{API_PREFIX}/portfolios/{portfolio_uuid}"

params = {}
if kwargs:
params.update(kwargs)

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


def move_portfolio_funds(
Expand All @@ -76,10 +66,7 @@ def move_portfolio_funds(
"target_portfolio_id": target_portfolio_uuid,
}

if kwargs:
data.update(kwargs)

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


def edit_portfolio(self, portfolio_uuid: str, name: str, **kwargs):
Expand All @@ -94,10 +81,7 @@ def edit_portfolio(self, portfolio_uuid: str, name: str, **kwargs):
"name": name,
}

if kwargs:
data.update(kwargs)

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


def delete_portfolio(self, portfolio_uuid: str, **kwargs):
Expand All @@ -108,8 +92,4 @@ def delete_portfolio(self, portfolio_uuid: str, **kwargs):
"""
endpoint = f"{API_PREFIX}/portfolios/{portfolio_uuid}"

data = {}
if kwargs:
data.update(kwargs)

return self.delete(endpoint, data=data)
return self.delete(endpoint, **kwargs)
21 changes: 4 additions & 17 deletions coinbase/rest/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ def get_products(
"expiring_contract_status": expiring_contract_status,
}

if kwargs:
params.update(kwargs)

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


def get_product(self, product_id: str, **kwargs):
Expand All @@ -43,11 +40,7 @@ def get_product(self, product_id: str, **kwargs):
"""
endpoint = f"{API_PREFIX}/products/{product_id}"

params = {}
if kwargs:
params.update(kwargs)

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


def get_product_book(self, product_id: str, limit: Optional[int] = None, **kwargs):
Expand All @@ -60,10 +53,7 @@ def get_product_book(self, product_id: str, limit: Optional[int] = None, **kwarg

params = {"product_id": product_id, "limit": limit}

if kwargs:
params.update(kwargs)

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


def get_best_bid_ask(self, product_ids: Optional[List[str]] = None, **kwargs):
Expand All @@ -79,7 +69,4 @@ def get_best_bid_ask(self, product_ids: Optional[List[str]] = None, **kwargs):
"product_ids": product_ids,
}

if kwargs:
params.update(kwargs)

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