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

Resolve "Add processBefore parameter to kraken.futures.Trade.{cancel_order,edit_order,create_order,create_batch_order}" #192

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
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 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 @@
: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 @@
}
"""
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 @@
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 @@
: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 @@
params["order_id"] = order_id
elif defined(cliOrdId):
params["cliOrdId"] = cliOrdId
elif defined(processBefore):
params["processBefore"] = processBefore

Check warning on line 391 in kraken/futures/trade.py

View check run for this annotation

Codecov / codecov/patch

kraken/futures/trade.py#L391

Added line #L391 was not covered by tests
else:
raise ValueError("Either order_id or cliOrdId must be set!")

Expand All @@ -395,6 +407,7 @@
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 @@
: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 @@
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 @@
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 @@
: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 @@
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
Loading