Skip to content

Commit

Permalink
Resolve "Rename KrakenBaseSpotAPI to KrakenSpotBaseAPI and `Krake…
Browse files Browse the repository at this point in the history
…nBaseFuturesAPI` to `KrakenFuturesBaseAPI`" (#159)
  • Loading branch information
btschwertfeger committed Mar 12, 2024
1 parent 8c3c904 commit 5ed40f4
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions docs/src/base_api/base_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions kraken/base_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -186,7 +186,7 @@ class KrakenBaseSpotAPI:
API_V: str = "/0"

def __init__(
self: KrakenBaseSpotAPI,
self: KrakenSpotBaseAPI,
key: str = "",
secret: str = "",
url: str = "",
Expand All @@ -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,
Expand Down Expand Up @@ -337,7 +337,7 @@ def _request( # noqa: PLR0913
)

def _get_kraken_signature(
self: KrakenBaseSpotAPI,
self: KrakenSpotBaseAPI,
url_path: str,
data: str,
nonce: int,
Expand Down Expand Up @@ -365,7 +365,7 @@ def _get_kraken_signature(
).decode()

def __check_response_data(
self: KrakenBaseSpotAPI,
self: KrakenSpotBaseAPI,
response: requests.Response,
*,
return_raw: bool = False,
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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 = "",
Expand All @@ -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,
Expand Down Expand Up @@ -598,7 +598,7 @@ def _request( # noqa: PLR0913
)

def _get_kraken_futures_signature(
self: KrakenBaseFuturesAPI,
self: KrakenFuturesBaseAPI,
endpoint: str,
data: str,
nonce: str,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions kraken/futures/funding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kraken/futures/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kraken/futures/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kraken/futures/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

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

Self = TypeVar("Self")


class User(KrakenBaseFuturesAPI):
class User(KrakenFuturesBaseAPI):
"""
Class that implements the Kraken Futures user client
Expand Down
6 changes: 3 additions & 3 deletions kraken/futures/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -137,7 +137,7 @@ def __init__(
)

@property
def key(self: KrakenBaseFuturesAPI) -> str:
def key(self: KrakenFuturesBaseAPI) -> str:
"""Returns the API key"""
return self.__key

Expand Down
4 changes: 2 additions & 2 deletions kraken/spot/funding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions kraken/spot/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions kraken/spot/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions kraken/spot/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kraken/spot/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kraken/spot/websocket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/futures/test_futures_base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@

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

from .helper import is_success


@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()
)
Expand Down
10 changes: 5 additions & 5 deletions tests/spot/test_spot_base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@

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

from .helper import is_not_error


@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,
Expand Down

0 comments on commit 5ed40f4

Please sign in to comment.