Skip to content

Commit 534e83d

Browse files
Resolve "Extract the Kraken* exception classes from kraken.exceptions.KrakenException" (#162)
1 parent a788d3a commit 534e83d

22 files changed

Lines changed: 457 additions & 365 deletions

examples/spot_orderbook_v1.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ class Orderbook(OrderbookClientV1):
5252
:func:`subscribe` function and any other provided utility.
5353
"""
5454

55-
async def on_book_update(self: Orderbook, pair: str, message: list) -> None:
55+
async def on_book_update(
56+
self: Orderbook,
57+
pair: str,
58+
message: list, # noqa: ARG002
59+
) -> None:
5660
"""
5761
This function is called every time the order book of ``pair`` gets
5862
updated.

examples/spot_orderbook_v2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ class Orderbook(OrderbookClientV2):
6161
:func:`subscribe` function and any other provided utility.
6262
"""
6363

64-
async def on_book_update(self: Orderbook, pair: str, message: list) -> None:
64+
async def on_book_update(
65+
self: Orderbook,
66+
pair: str,
67+
message: list, # noqa: ARG002
68+
) -> None:
6569
"""
6670
This function is called every time the order book of ``pair`` gets
6771
updated.

kraken/base_api/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import requests
2222

23-
from kraken.exceptions import KrakenException
23+
from kraken.exceptions import _get_exception
2424

2525
Self = TypeVar("Self")
2626

@@ -90,15 +90,12 @@ class KrakenErrorHandler:
9090
KrakenException based on the error message.
9191
"""
9292

93-
def __init__(self: KrakenErrorHandler) -> None:
94-
self.__kexceptions: KrakenException = KrakenException()
95-
96-
def __get_exception(self: KrakenErrorHandler, msg: str) -> Optional[Any]:
93+
def __get_exception(self: KrakenErrorHandler, data: str) -> Optional[Any]:
9794
"""
9895
Must be called when an error was found in the message, so the corresponding
9996
KrakenException will be returned.
10097
"""
101-
return self.__kexceptions.get_exception(msg)
98+
return _get_exception(data=data)
10299

103100
def check(self: KrakenErrorHandler, data: dict) -> dict | Any:
104101
"""
@@ -118,7 +115,7 @@ def check(self: KrakenErrorHandler, data: dict) -> dict | Any:
118115
if len(data.get("error", [])) == 0 and "result" in data:
119116
return data["result"]
120117

121-
exception = self.__get_exception(data["error"])
118+
exception: Type[Exception] = self.__get_exception(data=data["error"])
122119
if exception:
123120
raise exception(data)
124121
return data
@@ -135,7 +132,7 @@ def check_send_status(self: KrakenErrorHandler, data: dict) -> dict:
135132
:rtype: dict
136133
"""
137134
if "sendStatus" in data and "status" in data["sendStatus"]:
138-
exception: Type[KrakenException] = self.__get_exception(
135+
exception: Type[Exception] = self.__get_exception(
139136
data["sendStatus"]["status"],
140137
)
141138
if exception:
@@ -158,7 +155,7 @@ def check_batch_status(self: KrakenErrorHandler, data: dict) -> dict:
158155
batch_status: list[dict[str, Any]] = data["batchStatus"]
159156
for status in batch_status:
160157
if "status" in status:
161-
exception: Type[KrakenException] = self.__get_exception(
158+
exception: Type[Exception] = self.__get_exception(
162159
status["status"],
163160
)
164161
if exception:
@@ -263,9 +260,10 @@ def _request( # noqa: PLR0913
263260
)
264261

265262
method = method.upper()
266-
data_json: str = ""
267263
if method in ("GET", "DELETE") and params:
268-
data_json = "&".join([f"{key}={params[key]}" for key in sorted(params)])
264+
data_json: str = "&".join(
265+
[f"{key}={params[key]}" for key in sorted(params)],
266+
)
269267
uri += f"?{data_json}".replace(" ", "%20")
270268

271269
headers: dict = {}

0 commit comments

Comments
 (0)