diff --git a/docs/src/base_api/base_api.rst b/docs/src/base_api/base_api.rst index e2e91549..21e1346c 100644 --- a/docs/src/base_api/base_api.rst +++ b/docs/src/base_api/base_api.rst @@ -10,12 +10,12 @@ avoid using them, since these are internals and may change without any warning. They are the base classes for Spot and Futures REST and websocket clients. -.. autoclass:: kraken.base_api.KrakenBaseSpotAPI +.. autoclass:: kraken.base_api.KrakenSpotBaseAPI :members: :show-inheritance: :inherited-members: -.. autoclass:: kraken.base_api.KrakenBaseFuturesAPI +.. autoclass:: kraken.base_api.KrakenFuturesBaseAPI :members: :show-inheritance: :inherited-members: diff --git a/docs/src/introduction.rst b/docs/src/introduction.rst index 3b062a92..a00e10d1 100644 --- a/docs/src/introduction.rst +++ b/docs/src/introduction.rst @@ -24,8 +24,8 @@ and documented. - The output in the examples may differ, as these are only intended as examples and may change in the future. - If a certain endpoint is not reachable, the function - :func:`kraken.base_api.KrakenBaseSpotAPI._request` or - :func:`kraken.base_api.KrakenBaseFuturesAPI._request`, + :func:`kraken.base_api.KrakenSpotBaseAPI._request` or + :func:`kraken.base_api.KrakenFuturesBaseAPI._request`, which is also available in all derived REST clients, can be used to reach an endpoint with the appropriate parameters. Here private content can also be accessed, provided that either the base class or one of the clients has been diff --git a/kraken/base_api/__init__.py b/kraken/base_api/__init__.py index cfa21a1b..efea0824 100644 --- a/kraken/base_api/__init__.py +++ b/kraken/base_api/__init__.py @@ -166,7 +166,7 @@ def check_batch_status(self: KrakenErrorHandler, data: dict) -> dict: return data -class KrakenBaseSpotAPI: +class KrakenSpotBaseAPI: """ This class the the base for all Spot clients, handles un-/signed requests and returns exception handled results. @@ -186,7 +186,7 @@ class KrakenBaseSpotAPI: API_V: str = "/0" def __init__( - self: KrakenBaseSpotAPI, + self: KrakenSpotBaseAPI, key: str = "", secret: str = "", url: str = "", @@ -210,7 +210,7 @@ def __init__( self.__session.headers.update({"User-Agent": "python-kraken-sdk"}) def _request( # noqa: PLR0913 - self: KrakenBaseSpotAPI, + self: KrakenSpotBaseAPI, method: str, uri: str, params: Optional[dict] = None, @@ -337,7 +337,7 @@ def _request( # noqa: PLR0913 ) def _get_kraken_signature( - self: KrakenBaseSpotAPI, + self: KrakenSpotBaseAPI, url_path: str, data: str, nonce: int, @@ -365,7 +365,7 @@ def _get_kraken_signature( ).decode() def __check_response_data( - self: KrakenBaseSpotAPI, + self: KrakenSpotBaseAPI, response: requests.Response, *, return_raw: bool = False, @@ -399,7 +399,7 @@ def __check_response_data( raise Exception(f"{response.status_code} - {response.text}") @property - def return_unique_id(self: KrakenBaseSpotAPI) -> str: + def return_unique_id(self: KrakenSpotBaseAPI) -> str: """Returns a unique uuid string :return: uuid @@ -411,14 +411,14 @@ def __enter__(self: Self) -> Self: return self def __exit__( - self: KrakenBaseSpotAPI, + self: KrakenSpotBaseAPI, *exc: object, **kwargs: dict[str, Any], ) -> None: pass -class KrakenBaseFuturesAPI: +class KrakenFuturesBaseAPI: """ The base class for all Futures clients handles un-/signed requests and returns exception handled results. @@ -440,7 +440,7 @@ class KrakenBaseFuturesAPI: SANDBOX_URL: str = "https://demo-futures.kraken.com" def __init__( - self: KrakenBaseFuturesAPI, + self: KrakenFuturesBaseAPI, key: str = "", secret: str = "", url: str = "", @@ -466,7 +466,7 @@ def __init__( self.__session.headers.update({"User-Agent": "python-kraken-sdk"}) def _request( # noqa: PLR0913 - self: KrakenBaseFuturesAPI, + self: KrakenFuturesBaseAPI, method: str, uri: str, post_params: Optional[dict] = None, @@ -598,7 +598,7 @@ def _request( # noqa: PLR0913 ) def _get_kraken_futures_signature( - self: KrakenBaseFuturesAPI, + self: KrakenFuturesBaseAPI, endpoint: str, data: str, nonce: str, @@ -630,7 +630,7 @@ def _get_kraken_futures_signature( ).decode() def __check_response_data( - self: KrakenBaseFuturesAPI, + self: KrakenFuturesBaseAPI, response: requests.Response, *, return_raw: bool = False, @@ -678,4 +678,4 @@ def __exit__(self, *exc: object, **kwargs: dict[str, Any]) -> None: pass -__all__ = ["defined", "ensure_string", "KrakenBaseSpotAPI", "KrakenBaseFuturesAPI"] +__all__ = ["defined", "ensure_string", "KrakenSpotBaseAPI", "KrakenFuturesBaseAPI"] diff --git a/kraken/futures/funding.py b/kraken/futures/funding.py index 0f9b43c4..7b3380d7 100644 --- a/kraken/futures/funding.py +++ b/kraken/futures/funding.py @@ -9,12 +9,12 @@ from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseFuturesAPI +from kraken.base_api import KrakenFuturesBaseAPI Self = TypeVar("Self") -class Funding(KrakenBaseFuturesAPI): +class Funding(KrakenFuturesBaseAPI): """ Class that implements the Kraken Futures Funding client diff --git a/kraken/futures/market.py b/kraken/futures/market.py index 85eab618..3caf1cbf 100644 --- a/kraken/futures/market.py +++ b/kraken/futures/market.py @@ -10,12 +10,12 @@ from functools import lru_cache from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseFuturesAPI, defined, ensure_string +from kraken.base_api import KrakenFuturesBaseAPI, defined, ensure_string Self = TypeVar("Self") -class Market(KrakenBaseFuturesAPI): +class Market(KrakenFuturesBaseAPI): """ Class that implements the Kraken Futures market client diff --git a/kraken/futures/trade.py b/kraken/futures/trade.py index b61bf0ea..ad7fcff7 100644 --- a/kraken/futures/trade.py +++ b/kraken/futures/trade.py @@ -10,12 +10,12 @@ from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseFuturesAPI, defined +from kraken.base_api import KrakenFuturesBaseAPI, defined Self = TypeVar("Self") -class Trade(KrakenBaseFuturesAPI): +class Trade(KrakenFuturesBaseAPI): """ Class that implements the Kraken Futures trade client diff --git a/kraken/futures/user.py b/kraken/futures/user.py index 613c6b86..c2a4ecec 100644 --- a/kraken/futures/user.py +++ b/kraken/futures/user.py @@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Optional, TypeVar -from kraken.base_api import KrakenBaseFuturesAPI, defined +from kraken.base_api import KrakenFuturesBaseAPI, defined if TYPE_CHECKING: import requests @@ -18,7 +18,7 @@ Self = TypeVar("Self") -class User(KrakenBaseFuturesAPI): +class User(KrakenFuturesBaseAPI): """ Class that implements the Kraken Futures user client diff --git a/kraken/futures/ws_client.py b/kraken/futures/ws_client.py index c78ed28e..c2c8f5c1 100644 --- a/kraken/futures/ws_client.py +++ b/kraken/futures/ws_client.py @@ -15,14 +15,14 @@ from copy import deepcopy from typing import Any, Optional, TypeVar -from kraken.base_api import KrakenBaseFuturesAPI +from kraken.base_api import KrakenFuturesBaseAPI from kraken.exceptions import KrakenException from kraken.futures.websocket import ConnectFuturesWebsocket Self = TypeVar("Self") -class KrakenFuturesWSClient(KrakenBaseFuturesAPI): +class KrakenFuturesWSClient(KrakenFuturesBaseAPI): """ Class to access public and (optional) private/authenticated websocket connection. @@ -137,7 +137,7 @@ def __init__( ) @property - def key(self: KrakenBaseFuturesAPI) -> str: + def key(self: KrakenFuturesBaseAPI) -> str: """Returns the API key""" return self.__key diff --git a/kraken/spot/funding.py b/kraken/spot/funding.py index 70faaac5..afb9f33b 100644 --- a/kraken/spot/funding.py +++ b/kraken/spot/funding.py @@ -10,12 +10,12 @@ from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseSpotAPI, defined +from kraken.base_api import KrakenSpotBaseAPI, defined Self = TypeVar("Self") -class Funding(KrakenBaseSpotAPI): +class Funding(KrakenSpotBaseAPI): """ Class that implements the Spot Funding client. Currently there are no funding endpoints that could be accesses without authentication. diff --git a/kraken/spot/market.py b/kraken/spot/market.py index 64cad4ac..3d81ad70 100644 --- a/kraken/spot/market.py +++ b/kraken/spot/market.py @@ -11,12 +11,12 @@ from functools import lru_cache from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseSpotAPI, defined, ensure_string +from kraken.base_api import KrakenSpotBaseAPI, defined, ensure_string Self = TypeVar("Self") -class Market(KrakenBaseSpotAPI): +class Market(KrakenSpotBaseAPI): """ Class that implements the Kraken Spot Market client. Can be used to access the Kraken Spot market data. diff --git a/kraken/spot/staking.py b/kraken/spot/staking.py index 4dc2f627..da906c93 100644 --- a/kraken/spot/staking.py +++ b/kraken/spot/staking.py @@ -10,12 +10,12 @@ from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseSpotAPI, defined +from kraken.base_api import KrakenSpotBaseAPI, defined Self = TypeVar("Self") -class Staking(KrakenBaseSpotAPI): +class Staking(KrakenSpotBaseAPI): """ Class that implements the Kraken Spot Staking client. Currently there are no staking endpoints that could be accesses without authentication. diff --git a/kraken/spot/trade.py b/kraken/spot/trade.py index 30e58e34..e45c2afa 100644 --- a/kraken/spot/trade.py +++ b/kraken/spot/trade.py @@ -13,13 +13,13 @@ from math import floor from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseSpotAPI, defined, ensure_string +from kraken.base_api import KrakenSpotBaseAPI, defined, ensure_string from kraken.spot.market import Market Self = TypeVar("Self") -class Trade(KrakenBaseSpotAPI): +class Trade(KrakenSpotBaseAPI): """ Class that implements the Kraken Trade Spot client diff --git a/kraken/spot/user.py b/kraken/spot/user.py index c6161567..ffabfa06 100644 --- a/kraken/spot/user.py +++ b/kraken/spot/user.py @@ -11,12 +11,12 @@ from decimal import Decimal from typing import Optional, TypeVar -from kraken.base_api import KrakenBaseSpotAPI, defined, ensure_string +from kraken.base_api import KrakenSpotBaseAPI, defined, ensure_string Self = TypeVar("Self") -class User(KrakenBaseSpotAPI): +class User(KrakenSpotBaseAPI): """ Class that implements the Kraken Spot User client diff --git a/kraken/spot/websocket/__init__.py b/kraken/spot/websocket/__init__.py index 19761cdc..02768a2a 100644 --- a/kraken/spot/websocket/__init__.py +++ b/kraken/spot/websocket/__init__.py @@ -13,7 +13,7 @@ import logging from typing import Any, Callable, Optional, Type, TypeVar -from kraken.base_api import KrakenBaseSpotAPI +from kraken.base_api import KrakenSpotBaseAPI from kraken.spot.websocket.connectors import ( ConnectSpotWebsocketV1, ConnectSpotWebsocketV2, @@ -22,7 +22,7 @@ Self = TypeVar("Self") -class KrakenSpotWSClientBase(KrakenBaseSpotAPI): +class KrakenSpotWSClientBase(KrakenSpotBaseAPI): """ This is the base class for :class:`kraken.spot.KrakenSpotWSClient` and :class:`kraken.spot.KrakenSpotWSClientV2`. It extends the REST API base diff --git a/tests/futures/test_futures_base_api.py b/tests/futures/test_futures_base_api.py index 86b91b19..87ccdbed 100644 --- a/tests/futures/test_futures_base_api.py +++ b/tests/futures/test_futures_base_api.py @@ -8,7 +8,7 @@ import pytest -from kraken.base_api import KrakenBaseFuturesAPI +from kraken.base_api import KrakenFuturesBaseAPI from kraken.exceptions import KrakenException from kraken.futures import Funding, Market, Trade, User @@ -16,21 +16,21 @@ @pytest.mark.futures() -def test_KrakenBaseFuturesAPI_without_exception() -> None: +def test_KrakenFuturesBaseAPI_without_exception() -> None: """ Checks first if the expected error will be raised and than - creates a new KrakenBaseFuturesAPI instance that do not raise + creates a new KrakenFuturesBaseAPI instance that do not raise the custom Kraken exceptions. This new instance than executes the same request and the returned response gets evaluated. """ with pytest.raises(KrakenException.KrakenRequiredArgumentMissingError): - KrakenBaseFuturesAPI( + KrakenFuturesBaseAPI( key="fake", secret="fake", )._request(method="POST", uri="/derivatives/api/v3/sendorder", auth=True) result: dict = ( - KrakenBaseFuturesAPI(key="fake", secret="fake", use_custom_exceptions=False) # type: ignore[union-attr] + KrakenFuturesBaseAPI(key="fake", secret="fake", use_custom_exceptions=False) # type: ignore[union-attr] ._request(method="POST", uri="/derivatives/api/v3/sendorder", auth=True) .json() ) diff --git a/tests/spot/test_spot_base_api.py b/tests/spot/test_spot_base_api.py index 6de772bb..f120afc9 100644 --- a/tests/spot/test_spot_base_api.py +++ b/tests/spot/test_spot_base_api.py @@ -8,7 +8,7 @@ import pytest -from kraken.base_api import KrakenBaseSpotAPI +from kraken.base_api import KrakenSpotBaseAPI from kraken.exceptions import KrakenException from kraken.spot import Funding, Market, Staking, Trade, User @@ -16,20 +16,20 @@ @pytest.mark.spot() -def test_KrakenBaseSpotAPI_without_exception() -> None: +def test_KrakenSpotBaseAPI_without_exception() -> None: """ Checks first if the expected error will be raised and than - creates a new KrakenBaseSpotAPI instance that do not raise + creates a new KrakenSpotBaseAPI instance that do not raise the custom Kraken exceptions. This new instance than executes the same request and the returned response gets evaluated. """ with pytest.raises(KrakenException.KrakenInvalidAPIKeyError): - KrakenBaseSpotAPI( + KrakenSpotBaseAPI( key="fake", secret="fake", )._request(method="POST", uri="/private/AddOrder", auth=True) - assert KrakenBaseSpotAPI( + assert KrakenSpotBaseAPI( key="fake", secret="fake", use_custom_exceptions=False,