Skip to content

Commit

Permalink
v1.2.1 (#38)
Browse files Browse the repository at this point in the history
* Release v1.2.1

* Update CHANGELOG.md
  • Loading branch information
davidMkCb authored Mar 27, 2024
1 parent 58f62cc commit 36578b9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [1.2.1] - 2024-MAR-27

### Added
- `retail_portfolio_id` to all `preview_order` methods

### Changed
- Requests now made via request.Sessions() to reduce latency by reusing existing HTTP connection
- Timestamp no longer needed for websocket signing

## [1.2.0] - 2024-MAR-11

### Added
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.2.0"
__version__ = "1.2.1"
38 changes: 38 additions & 0 deletions coinbase/rest/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ def preview_order(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1205,6 +1206,7 @@ def preview_order(
"skip_fcm_risk_check": skip_fcm_risk_check,
"leverage": leverage,
"margin_type": margin_type,
"retail_portfolio_id": retail_portfolio_id,
}

return self.post(endpoint, data=data, **kwargs)
Expand All @@ -1223,6 +1225,7 @@ def preview_market_order(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1261,6 +1264,7 @@ def preview_market_order(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1275,6 +1279,7 @@ def preview_market_order_buy(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1305,6 +1310,7 @@ def preview_market_order_buy(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1319,6 +1325,7 @@ def preview_market_order_sell(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1349,6 +1356,7 @@ def preview_market_order_sell(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1366,6 +1374,7 @@ def preview_limit_order_ioc(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1400,6 +1409,7 @@ def preview_limit_order_ioc(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1415,6 +1425,7 @@ def preview_limit_order_ioc_buy(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1446,6 +1457,7 @@ def preview_limit_order_ioc_buy(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1461,6 +1473,7 @@ def preview_limit_order_ioc_sell(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1492,6 +1505,7 @@ def preview_limit_order_ioc_sell(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1510,6 +1524,7 @@ def preview_limit_order_gtc(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1548,6 +1563,7 @@ def preview_limit_order_gtc(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1564,6 +1580,7 @@ def preview_limit_order_gtc_buy(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1596,6 +1613,7 @@ def preview_limit_order_gtc_buy(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1612,6 +1630,7 @@ def preview_limit_order_gtc_sell(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1644,6 +1663,7 @@ def preview_limit_order_gtc_sell(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1663,6 +1683,7 @@ def preview_limit_order_gtd(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1702,6 +1723,7 @@ def preview_limit_order_gtd(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1719,6 +1741,7 @@ def preview_limit_order_gtd_buy(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1752,6 +1775,7 @@ def preview_limit_order_gtd_buy(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1769,6 +1793,7 @@ def preview_limit_order_gtd_sell(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1802,6 +1827,7 @@ def preview_limit_order_gtd_sell(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1821,6 +1847,7 @@ def preview_stop_limit_order_gtc(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1860,6 +1887,7 @@ def preview_stop_limit_order_gtc(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1877,6 +1905,7 @@ def preview_stop_limit_order_gtc_buy(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1910,6 +1939,7 @@ def preview_stop_limit_order_gtc_buy(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1927,6 +1957,7 @@ def preview_stop_limit_order_gtc_sell(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -1960,6 +1991,7 @@ def preview_stop_limit_order_gtc_sell(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -1980,6 +2012,7 @@ def preview_stop_limit_order_gtd(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -2020,6 +2053,7 @@ def preview_stop_limit_order_gtd(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -2038,6 +2072,7 @@ def preview_stop_limit_order_gtd_buy(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -2072,6 +2107,7 @@ def preview_stop_limit_order_gtd_buy(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)

Expand All @@ -2090,6 +2126,7 @@ def preview_stop_limit_order_gtd_sell(
skip_fcm_risk_check: Optional[bool] = False,
leverage: Optional[str] = None,
margin_type: Optional[str] = None,
retail_portfolio_id: Optional[str] = None,
**kwargs,
) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -2124,5 +2161,6 @@ def preview_stop_limit_order_gtd_sell(
skip_fcm_risk_check=skip_fcm_risk_check,
leverage=leverage,
margin_type=margin_type,
retail_portfolio_id=retail_portfolio_id,
**kwargs,
)
3 changes: 2 additions & 1 deletion coinbase/rest/rest_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __init__(
timeout=timeout,
verbose=verbose,
)
self.session = requests.Session()
if verbose:
logger.setLevel(logging.DEBUG)

Expand Down Expand Up @@ -218,7 +219,7 @@ def send_request(self, http_method, url_path, params, headers, data=None):

logger.debug(f"Sending {http_method} request to {url}")

response = requests.request(
response = self.session.request(
http_method,
url,
params=params,
Expand Down
1 change: 0 additions & 1 deletion coinbase/websocket/websocket_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ def _build_subscription_message(
"product_ids": product_ids,
"channel": channel,
"jwt": jwt_generator.build_ws_jwt(self.api_key, self.api_secret),
"timestamp": int(time.time()),
}

def _ensure_websocket_not_open(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/rest/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ def test_preview_order(self):
skip_fcm_risk_check=False,
leverage="5",
margin_type="CROSS",
retail_portfolio_id="portfolio_id_1",
)

captured_request = m.request_history[0]
Expand All @@ -906,6 +907,7 @@ def test_preview_order(self):
"skip_fcm_risk_check": False,
"leverage": "5",
"margin_type": "CROSS",
"retail_portfolio_id": "portfolio_id_1",
},
)
self.assertEqual(preview, expected_response)
Expand Down

0 comments on commit 36578b9

Please sign in to comment.