Skip to content

Commit

Permalink
Resolve "Add processBefore parameter to kraken.futures.Trade.{`ca…
Browse files Browse the repository at this point in the history
…ncel_order`,`edit_order`,`create_order`,`create_batch_order`}" (#192)
  • Loading branch information
btschwertfeger committed Mar 12, 2024
1 parent 305ad1b commit 901b3ad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
24 changes: 23 additions & 1 deletion kraken/futures/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def get_fills(
def create_batch_order(
self: Trade,
batchorder_list: list[dict],
processBefore: Optional[str] = None,
*,
extra_params: Optional[dict] = None,
) -> dict:
Expand All @@ -133,6 +134,8 @@ def create_batch_order(
:param batchorder_list: List of order instructions (see example below -
or the linked official Kraken documentation)
:type batchorder_list: list[dict]
:param processBefore: Process before timestamp otherwise reject
:type processBefore: str, optional
:return: Information about the submitted request
:rtype: dict
Expand Down Expand Up @@ -223,10 +226,14 @@ def create_batch_order(
}
"""
batchorder: dict = {"batchOrder": batchorder_list}
params = {"json": f"{batchorder}"}
if processBefore:
params["processBefore"] = processBefore

return self._request( # type: ignore[return-value]
method="POST",
uri="/derivatives/api/v3/batchorder",
post_params={"json": f"{batchorder}"},
post_params=params,
auth=True,
extra_params=extra_params,
)
Expand Down Expand Up @@ -335,6 +342,7 @@ def cancel_order(
self: Trade,
order_id: Optional[str] = None,
cliOrdId: Optional[str] = None,
processBefore: Optional[str] = None,
*,
extra_params: Optional[dict] = None,
) -> dict:
Expand All @@ -351,6 +359,8 @@ def cancel_order(
:type order_id: str, optional
:param cliOrdId: The client defined order id
:type cliOrdId: str, optional
:param processBefore: Process before timestamp otherwise reject
:type processBefore: str, optional
:raises ValueError: If both ``order_id`` and ``cliOrdId`` are not set
:return: Success or failure
:rtype: dict
Expand All @@ -377,6 +387,8 @@ def cancel_order(
params["order_id"] = order_id
elif defined(cliOrdId):
params["cliOrdId"] = cliOrdId
elif defined(processBefore):
params["processBefore"] = processBefore
else:
raise ValueError("Either order_id or cliOrdId must be set!")

Expand All @@ -395,6 +407,7 @@ def edit_order(
limitPrice: Optional[str | float] = None,
size: Optional[str | float] = None,
stopPrice: Optional[str | float] = None,
processBefore: Optional[str] = None,
*,
extra_params: Optional[dict] = None,
) -> dict:
Expand All @@ -416,6 +429,8 @@ def edit_order(
:type size: str | float, optional
:param stopPrice: The stop price
:type stopPrice: str | float, optional
:param processBefore: Process before timestamp otherwise reject
:type processBefore: str, optional
:raises ValueError: If both ``orderId`` and ``cliOrdId`` are not set
:return: Success or failure
:rtype: dict
Expand Down Expand Up @@ -453,6 +468,8 @@ def edit_order(
params["size"] = size
if defined(stopPrice):
params["stopPrice"] = stopPrice
if defined(processBefore):
params["processBefore"] = processBefore

return self._request( # type: ignore[return-value]
method="POST",
Expand Down Expand Up @@ -524,6 +541,7 @@ def create_order( # pylint: disable=too-many-arguments # noqa: PLR0913, PLR0917
triggerSignal: Optional[str] = None,
trailingStopDeviationUnit: Optional[str] = None,
trailingStopMaxDeviation: Optional[str] = None,
processBefore: Optional[str] = None,
*,
extra_params: Optional[dict] = None,
) -> dict:
Expand Down Expand Up @@ -561,6 +579,8 @@ def create_order( # pylint: disable=too-many-arguments # noqa: PLR0913, PLR0917
:type trailingStopDeviationUnit: str, optional
:param trailingStopMaxDeviation: See referenced Kraken documentation
:type trailingStopMaxDeviation: str, optional
:param processBefore: Process before timestamp otherwise reject
:type processBefore: str, optional
:return: Success or failure
:rtype: dict
Expand Down Expand Up @@ -721,6 +741,8 @@ def create_order( # pylint: disable=too-many-arguments # noqa: PLR0913, PLR0917
params["trailingStopDeviationUnit"] = trailingStopDeviationUnit
if defined(trailingStopMaxDeviation):
params["trailingStopMaxDeviation"] = trailingStopMaxDeviation
if defined(processBefore):
params["processBefore"] = processBefore

return self._request( # type: ignore[return-value]
method="POST",
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ ignore-names = [
"TIMEOUT",
"URL",
"HEADERS",
"processBefore",
]

[tool.ruff.lint.pylint]
Expand Down Expand Up @@ -547,6 +548,7 @@ good-names = [
"TIMEOUT",
"URL",
"HEADERS",
"processBefore",
]

# Good variable names regexes, separated by a comma. If names match any regex,
Expand Down
6 changes: 5 additions & 1 deletion tests/futures/test_futures_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_create_order(futures_demo_trade) -> None:
limitPrice=1,
stopPrice=10,
reduceOnly=True,
processBefore="3033-11-08T19:56:35.441899Z",
)

# FIXME: why are these commented out?
Expand Down Expand Up @@ -204,6 +205,7 @@ def test_create_batch_order(futures_demo_trade) -> None:
"cliOrdId": "my_client_id",
},
],
processBefore="3033-11-08T19:56:35.441899Z",
),
)

Expand All @@ -227,6 +229,7 @@ def test_edit_order(futures_demo_trade) -> None:
cliOrdId="685d5a1a-23eb-450c-bf17-1e4ab5c6fe8a",
size=111.0,
stopPrice=1000,
processBefore="3033-11-08T19:56:35.441899Z",
),
)

Expand All @@ -251,7 +254,8 @@ def test_cancel_order(futures_demo_trade) -> None:
"""
assert is_success(
futures_demo_trade.cancel_order(
cliOrdId="685d5a1a-23eb-450c-bf17-1e4ab5c6fe8a",
cliOrdId="my_another_client_id",
processBefore="3033-11-08T19:56:35.441899Z",
),
)
assert is_success(
Expand Down

0 comments on commit 901b3ad

Please sign in to comment.