-
Notifications
You must be signed in to change notification settings - Fork 28
feat(spot): add cl_ord_id to create_order and edit_order endpoints #416
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -96,6 +96,7 @@ def create_order( # pylint: disable=too-many-branches,too-many-arguments # noqa | |||||
| close_price2: str | float | None = None, | ||||||
| deadline: str | None = None, | ||||||
| userref: int | None = None, | ||||||
| cl_ord_id: str | None = None, | ||||||
| *, | ||||||
| truncate: bool = False, | ||||||
| reduce_only: bool | None = False, | ||||||
|
|
@@ -190,6 +191,8 @@ def create_order( # pylint: disable=too-many-branches,too-many-arguments # noqa | |||||
| :type validate: bool, optional | ||||||
| :param userref: User reference id for example to group orders | ||||||
| :type userref: int, optional | ||||||
| :param cl_ord_id: Client order id (optional) | ||||||
| :type cl_ord_id: str, optional | ||||||
| :raises ValueError: If input is not correct | ||||||
| :return: The transaction id | ||||||
| :rtype: dict | ||||||
|
|
@@ -400,6 +403,8 @@ def create_order( # pylint: disable=too-many-branches,too-many-arguments # noqa | |||||
| params["deadline"] = deadline | ||||||
| if defined(userref): | ||||||
| params["userref"] = userref | ||||||
| if defined(cl_ord_id): | ||||||
| params["cl_ord_id"] = cl_ord_id | ||||||
| if defined(displayvol): | ||||||
| params["displayvol"] = str(displayvol) | ||||||
|
|
||||||
|
|
@@ -456,6 +461,7 @@ def create_order_batch( | |||||
| ... "timeinforce": "GTC", | ||||||
| ... "type": "buy", | ||||||
| ... "userref": 16861348843, | ||||||
| ... "cl_ord_id": "my-client-order-id-1", | ||||||
| ... "volume": 1, | ||||||
| ... }, | ||||||
| ... { | ||||||
|
|
@@ -464,6 +470,7 @@ def create_order_batch( | |||||
| ... "timeinforce": "GTC", | ||||||
| ... "type": "sell", | ||||||
| ... "userref": 16861348843, | ||||||
| ... "cl_ord_id": "my-client-order-id-2", | ||||||
| ... "volume": 2, | ||||||
| ... }, | ||||||
| ... ], | ||||||
|
|
@@ -491,8 +498,19 @@ def create_order_batch( | |||||
| extra_params=extra_params, | ||||||
| ) | ||||||
|
|
||||||
| def amend_order( | ||||||
| def amend_order( # pylint: disable=too-many-arguments # noqa: PLR0913, PLR0917 | ||||||
| self: Trade, | ||||||
| txid: str | None = None, | ||||||
| cl_ord_id: str | None = None, | ||||||
| order_qty: str | float | None = None, | ||||||
| display_qty: str | float | None = None, | ||||||
| limit_price: str | float | None = None, | ||||||
| trigger_price: str | float | None = None, | ||||||
| pair: str | None = None, | ||||||
| post_only: bool | None = None, | ||||||
| deadline: str | None = None, | ||||||
| nonce: int | None = None, | ||||||
| validate: bool = False, | ||||||
| *, | ||||||
| extra_params: dict | None = None, | ||||||
| ) -> dict: | ||||||
|
|
@@ -504,22 +522,69 @@ def amend_order( | |||||
|
|
||||||
| - https://docs.kraken.com/api/docs/rest-api/amend-order | ||||||
|
|
||||||
| :param txid: The txid of the order to edit | ||||||
| :type txid: str, optional | ||||||
| :param cl_ord_id: Client order id (optional) | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| :type cl_ord_id: str, optional | ||||||
| :param order_qty: Set a new order quantity | ||||||
| :type order_qty: str | float, optional | ||||||
| :param display_qty: Set a new display quantity | ||||||
| :type display_qty: str | float, optional | ||||||
| :param limit_price: Set a new limit price | ||||||
| :type limit_price: str | float, optional | ||||||
| :param trigger_price: Set a new trigger price | ||||||
| :type trigger_price: str | float, optional | ||||||
| :param pair: Pair of the order, required on amends for non-crypto orders | ||||||
| :type pair: str, optional | ||||||
| :param post_only: Set post-only flag | ||||||
| :type post_only: bool, optional | ||||||
| :param deadline: RFC3339 timestamp | ||||||
| :type deadline: str, optional | ||||||
| :param nonce: Nonce used in construction of API-Sign header | ||||||
| :type nonce: int, optional | ||||||
| :param validate: Validate the order without placing on the market (default: ``False``) | ||||||
| :type validate: bool, optional | ||||||
| :raises ValueError: If both ``txid`` and ``cl_ord_id`` are not set | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not having
Suggested change
|
||||||
| :return: Success or failure | ||||||
| :rtype: dict | ||||||
|
|
||||||
| .. code-block:: python | ||||||
| :linenos: | ||||||
| :caption: Spot Trade: Amend order | ||||||
|
|
||||||
| >>> from kraken.spot import Trade | ||||||
| >>> trade = Trade(key="api-key", secret="secret-key") | ||||||
| >>> trade.amend_order( | ||||||
| ... extra_params={ | ||||||
| ... "txid": "OVM3PT-56ACO-53SM2T", | ||||||
| ... "limit_price": "105636.9", | ||||||
| ... } | ||||||
| ... txid="OVM3PT-56ACO-53SM2T", | ||||||
| ... limit_price="105636.9" | ||||||
| ... ) | ||||||
| """ | ||||||
| params: dict = {"validate": validate} | ||||||
| if defined(txid): | ||||||
| params["txid"] = txid | ||||||
| if defined(cl_ord_id): | ||||||
| params["cl_ord_id"] = cl_ord_id | ||||||
| if defined(order_qty): | ||||||
| params["order_qty"] = str(order_qty) | ||||||
| if defined(display_qty): | ||||||
| params["display_qty"] = str(display_qty) | ||||||
| if defined(limit_price): | ||||||
| params["limit_price"] = str(limit_price) | ||||||
| if defined(trigger_price): | ||||||
| params["trigger_price"] = str(trigger_price) | ||||||
| if defined(pair): | ||||||
| params["pair"] = pair | ||||||
| if defined(post_only): | ||||||
| params["post_only"] = post_only | ||||||
| if defined(deadline): | ||||||
| params["deadline"] = deadline | ||||||
| if defined(nonce): | ||||||
| params["nonce"] = nonce | ||||||
|
|
||||||
| return self.request( # type: ignore[return-value] | ||||||
| "POST", | ||||||
| uri="/0/private/AmendOrder", | ||||||
| params=params, | ||||||
| extra_params=extra_params, | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -632,21 +697,24 @@ def edit_order( # pylint: disable=too-many-arguments # noqa: PLR0913, PLR0917 | |||||
| @ensure_string("txid") | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked up the docs and it seems like So lets swap these out:
Suggested change
|
||||||
| def cancel_order( | ||||||
| self: Trade, | ||||||
| txid: str, | ||||||
| txid: str | None = None, | ||||||
| cl_ord_id: str | None = None, | ||||||
| *, | ||||||
| extra_params: dict | None = None, | ||||||
| ) -> dict: | ||||||
| """ | ||||||
| Cancel a specific order by ``txid``. Instead of a transaction id | ||||||
| a user reference id can be passed. | ||||||
| a user reference id or client order id can be passed. | ||||||
|
|
||||||
| Requires the ``Cancel/close orders`` permission in | ||||||
| the API key settings. | ||||||
|
|
||||||
| - https://docs.kraken.com/api/docs/rest-api/cancel-order | ||||||
|
|
||||||
| :param txid: Transaction id or comma delimited list of user reference ids to cancel. | ||||||
| :type txid: str | ||||||
| :param txid: Transaction id, client order id, or comma delimited list of user reference ids to cancel. | ||||||
| :type txid: str, optional | ||||||
| :param cl_ord_id: Client order id (optional) | ||||||
| :type cl_ord_id: str, optional | ||||||
| :return: Success or failure - Number of closed orders | ||||||
| :rtype: dict | ||||||
|
|
||||||
|
|
@@ -659,10 +727,17 @@ def cancel_order( | |||||
| >>> trade.cancel_order(txid="OAUHYR-YCVK6-P22G6P") | ||||||
| { 'count': 1 } | ||||||
| """ | ||||||
| params: dict = {} | ||||||
| if defined(txid): | ||||||
| params["txid"] = txid | ||||||
| if defined(cl_ord_id): | ||||||
| params["cl_ord_id"] = cl_ord_id | ||||||
|
|
||||||
|
|
||||||
| return self.request( # type: ignore[return-value] | ||||||
| method="POST", | ||||||
| uri="/0/private/CancelOrder", | ||||||
| params={"txid": txid}, | ||||||
| params=params, | ||||||
| extra_params=extra_params, | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -742,7 +817,7 @@ def cancel_order_batch( | |||||
| extra_params: dict | None = None, | ||||||
| ) -> dict: | ||||||
| """ | ||||||
| Cancel a a list of orders by ``txid`` or ``userref`` | ||||||
| Cancel a list of orders by ``txid``, ``userref`` or ``cl_ord_id``. | ||||||
|
|
||||||
| Requires the ``Cancel/close orders`` permission in | ||||||
| the API key settings. | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The optional is given by the type declaration and not necessary at this place.
(Similar to other places; please address)