From d4e6d09ffe672c95076fbeb4198ca31799963d3f Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Schwertfeger Date: Sat, 25 Jan 2025 16:43:35 +0100 Subject: [PATCH 1/4] Switch to src-layout --- .github/codecov.yml | 2 +- .github/release.yaml | 4 +- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 4 ++ Makefile | 16 +++-- README.md | 2 + doc/conf.py | 8 +-- doc/introduction.rst | 3 +- pyproject.toml | 70 +++++++++++-------- {kraken => src/kraken}/__init__.py | 0 {kraken => src/kraken}/base_api/__init__.py | 0 {kraken => src/kraken}/cli.py | 0 {kraken => src/kraken}/exceptions/__init__.py | 0 {kraken => src/kraken}/futures/__init__.py | 0 {kraken => src/kraken}/futures/funding.py | 0 {kraken => src/kraken}/futures/market.py | 0 {kraken => src/kraken}/futures/trade.py | 0 {kraken => src/kraken}/futures/user.py | 0 .../kraken}/futures/websocket/__init__.py | 0 {kraken => src/kraken}/futures/ws_client.py | 0 {kraken => src/kraken}/nft/__init__.py | 0 {kraken => src/kraken}/nft/market.py | 0 {kraken => src/kraken}/nft/trade.py | 0 {kraken => src/kraken}/spot/__init__.py | 0 {kraken => src/kraken}/spot/earn.py | 0 {kraken => src/kraken}/spot/funding.py | 0 {kraken => src/kraken}/spot/market.py | 0 {kraken => src/kraken}/spot/orderbook.py | 0 {kraken => src/kraken}/spot/trade.py | 0 {kraken => src/kraken}/spot/user.py | 0 .../kraken}/spot/websocket/__init__.py | 0 .../kraken}/spot/websocket/connectors.py | 0 {kraken => src/kraken}/spot/ws_client.py | 0 {kraken => src/kraken}/utils/__init__.py | 0 {kraken => src/kraken}/utils/utils.py | 0 35 files changed, 65 insertions(+), 46 deletions(-) rename {kraken => src/kraken}/__init__.py (100%) rename {kraken => src/kraken}/base_api/__init__.py (100%) rename {kraken => src/kraken}/cli.py (100%) rename {kraken => src/kraken}/exceptions/__init__.py (100%) rename {kraken => src/kraken}/futures/__init__.py (100%) rename {kraken => src/kraken}/futures/funding.py (100%) rename {kraken => src/kraken}/futures/market.py (100%) rename {kraken => src/kraken}/futures/trade.py (100%) rename {kraken => src/kraken}/futures/user.py (100%) rename {kraken => src/kraken}/futures/websocket/__init__.py (100%) rename {kraken => src/kraken}/futures/ws_client.py (100%) rename {kraken => src/kraken}/nft/__init__.py (100%) rename {kraken => src/kraken}/nft/market.py (100%) rename {kraken => src/kraken}/nft/trade.py (100%) rename {kraken => src/kraken}/spot/__init__.py (100%) rename {kraken => src/kraken}/spot/earn.py (100%) rename {kraken => src/kraken}/spot/funding.py (100%) rename {kraken => src/kraken}/spot/market.py (100%) rename {kraken => src/kraken}/spot/orderbook.py (100%) rename {kraken => src/kraken}/spot/trade.py (100%) rename {kraken => src/kraken}/spot/user.py (100%) rename {kraken => src/kraken}/spot/websocket/__init__.py (100%) rename {kraken => src/kraken}/spot/websocket/connectors.py (100%) rename {kraken => src/kraken}/spot/ws_client.py (100%) rename {kraken => src/kraken}/utils/__init__.py (100%) rename {kraken => src/kraken}/utils/utils.py (100%) diff --git a/.github/codecov.yml b/.github/codecov.yml index 75b78950..8e793430 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -19,6 +19,6 @@ coverage: comment: layout: "reach, diff, flags, files" behavior: default - require_changes: true # if false: post the comment even if coverage doesn't change + require_changes: false # if false: post the comment even if coverage doesn't change require_base: no # [yes :: must have a base report to post] require_head: yes # [yes :: must have a head report to post] diff --git a/.github/release.yaml b/.github/release.yaml index 5315a537..86b7c05f 100644 --- a/.github/release.yaml +++ b/.github/release.yaml @@ -24,14 +24,14 @@ changelog: labels: - Bug - bug - - title: Other Changes + - title: Other Changes 📝 labels: - "*" exclude: labels: - dependencies - github_actions - - title: 👒 Dependencies + - title: Dependencies 👒 labels: - dependencies - github_actions diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d9410e09..6d7923c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -91,4 +91,4 @@ repos: - --max-average=A - --max-modules=A - --max-absolute=C - - --exclude=kraken/spot/ws_client.py + - --exclude=src/kraken/spot/ws_client.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a5f85e04..23cab0cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Uncategorized merged pull requests: +- Bump github/codeql-action from 3.28.1 to 3.28.2 [\#341](https://github.com/btschwertfeger/python-kraken-sdk/pull/341) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Bump codecov/codecov-action from 5.1.2 to 5.2.0 [\#340](https://github.com/btschwertfeger/python-kraken-sdk/pull/340) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Update the documentation [\#339](https://github.com/btschwertfeger/python-kraken-sdk/pull/339) ([btschwertfeger](https://github.com/btschwertfeger)) +- Bump step-security/harden-runner from 2.10.3 to 2.10.4 [\#338](https://github.com/btschwertfeger/python-kraken-sdk/pull/338) ([dependabot[bot]](https://github.com/apps/dependabot)) - Bump step-security/harden-runner from 2.10.2 to 2.10.3 [\#337](https://github.com/btschwertfeger/python-kraken-sdk/pull/337) ([dependabot[bot]](https://github.com/apps/dependabot)) - Bump github/codeql-action from 3.28.0 to 3.28.1 [\#336](https://github.com/btschwertfeger/python-kraken-sdk/pull/336) ([dependabot[bot]](https://github.com/apps/dependabot)) diff --git a/Makefile b/Makefile index 1295262b..1e4b155e 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ help: @grep "^##" Makefile | sed -e "s/##//" ## ======= B U I L D I N G ======= -## build Builds the python-kraken-sdk +## build Builds the package ## .PHONY: build build: check-uv @@ -43,7 +43,7 @@ install: check-uv ## .PHONY: dev dev: check-uv - $(UV) pip install -e ".[dev,test]" + $(UV) pip install -e ".[dev,test,examples,jupyter]" ## ======= T E S T I N G ======= ## test Run the unit tests @@ -56,6 +56,11 @@ test: .PHONY: tests tests: test +.PHONY: retest +retest: + @rm .cache/tests/*.log || true + $(PYTEST) $(PYTEST_OPTS) --lf $(TEST_DIR) + ## wip Run tests marked as 'wip' ## .PHONY: wip @@ -119,7 +124,7 @@ clean: .vscode \ dist/ \ doc/_build \ - python_kraken_sdk.egg-info \ + src/python_kraken_sdk.egg-info \ build/ rm -f .coverage \ @@ -127,14 +132,13 @@ clean: *.log \ *.zip \ coverage.xml \ - kraken/_version.py \ + src/kraken/_version.py \ mypy.xml \ pytest.xml \ - python_kraken_sdk-*.whl \ tests/*.zip find tests -name "__pycache__" | xargs rm -rf - find kraken -name "__pycache__" | xargs rm -rf + find src -name "__pycache__" | xargs rm -rf find examples -name "__pycache__" | xargs rm -rf ## check-uv Check if uv is installed diff --git a/README.md b/README.md index a0585765..7c035d5a 100644 --- a/README.md +++ b/README.md @@ -468,6 +468,8 @@ if __name__ == "__main__": calculation is based on timestamps and a sent nonce must always be the highest nonce ever sent of that API key. Having multiple algorithms using the same keys will result in invalid nonce errors. +- Always keep an eye on https://status.kraken.com/ when encountering + connectivity problems. --- diff --git a/doc/conf.py b/doc/conf.py index 09cc52b1..4a1573b2 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -23,9 +23,8 @@ copyright = "2023, Benjamin Thomas Schwertfeger" # noqa: A001 # pylint: disable=redefined-builtin author = "Benjamin Thomas Schwertfeger" -# to import the package -parent_directory: Path = Path("..").resolve() -sys.path.insert(0, str(parent_directory)) +# Add the package to sys.path: +sys.path.insert(0, str(Path("..").resolve())) rst_epilog = "" # Read link all targets from file @@ -69,11 +68,10 @@ def setup(app: Any) -> None: # noqa: ARG001,ANN401 # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = "sphinx_rtd_theme" -html_static_path = ["_static"] +# html_static_path = ["_static"] html_context = { "display_github": True, "github_user": "btschwertfeger", "github_repo": "python-kraken-sdk", "github_version": "master/doc/", } -# html_theme_options = {"rightsidebar": "true", "relbarbgcolor": "black"} diff --git a/doc/introduction.rst b/doc/introduction.rst index 2bd6f6f7..19f53869 100644 --- a/doc/introduction.rst +++ b/doc/introduction.rst @@ -97,9 +97,10 @@ Troubleshooting calculation is based on timestamps and a sent nonce must always be the highest nonce ever sent of that API key. Having multiple algorithms using the same keys will result in invalid nonce errors. +- Always keep an eye on https://status.kraken.com/ when encountering + connectivity problems. - Feel free to open an issue at `python-kraken-sdk/issues`_. - References ---------- diff --git a/pyproject.toml b/pyproject.toml index 931c7140..4c23ded9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,26 +31,24 @@ dependencies = [ ] keywords = ["crypto", "trading", "kraken", "exchange", "api"] classifiers = [ - "License :: OSI Approved :: Apache Software License", "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Topic :: Office/Business :: Financial", - "Topic :: Office/Business :: Financial :: Investment", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Utilities", - "Programming Language :: Python", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", "Framework :: AsyncIO", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: MacOS", "Operating System :: Unix", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Office/Business :: Financial :: Investment", + "Topic :: Office/Business :: Financial", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Utilities", ] -[project.scripts] -kraken = "kraken.cli:cli" - [project.urls] "Homepage" = "https://github.com/btschwertfeger/python-kraken-sdk" "Bug Tracker" = "https://github.com/btschwertfeger/python-kraken-sdk/issues" @@ -66,7 +64,7 @@ dev = [ "sphinx-click", "sphinx-rtd-theme", "nbsphinx", - "ipython", # to visualize notebooks in doc + "ipython", # To visualize Jupyter Notebooks in the documentation # formatting "black", # typing @@ -76,26 +74,31 @@ dev = [ "ruff", ] test = [ - "pytest", + "proxy.py", + "pytest-asyncio", "pytest-cov", "pytest-mock", - "pytest-asyncio", + "pytest-retry", "pytest-timeout", - "proxy.py", + "pytest", ] examples = ["matplotlib", "pandas", "numpy"] jupyter = ["ipykernel"] # python3 -m ipykernel install --user --name=kraken +[project.scripts] +kraken = "kraken.cli:cli" + [tool.setuptools] include-package-data = false +package-dir = { "" = "src" } [tool.setuptools.packages.find] +where = ["src"] include = ["kraken*"] -# excluded anyway because of 'include' -exclude = ["docs*", "tests*", "examples*", "venv", ".env"] +exclude = ["docs*", "tests*", "examples*", ".venv", ".env", ".cache", ".github"] [tool.setuptools_scm] -write_to = "kraken/_version.py" +write_to = "src/kraken/_version.py" version_scheme = "guess-next-dev" local_scheme = "no-local-version" @@ -106,14 +109,12 @@ junit_family = "xunit2" testpaths = ["tests"] [tool.pytest.ini_options] -# filterwarnings = [ -# "ignore:The Kraken websocket API v1 is marked as deprecated*:DeprecationWarning", -# ] -asyncio_mode = "auto" -asyncio_default_fixture_loop_scope = "function" -timeout = 60 # seconds - cache_dir = ".cache/pytest" + +# Retrying tests once, as we're testing against lots of API endpoints, the tests +# are flaky by design. +retries = 1 + markers = [ "wip: Used to run a specific test by hand.", "flaky: Flaky tests", @@ -139,9 +140,18 @@ markers = [ "nft_trade: … NFT Trade endpoint.", ] +asyncio_default_fixture_loop_scope = "function" + +asyncio_mode = "auto" +timeout = 60 # seconds + +# filterwarnings = [ +# "ignore:The Kraken websocket API v1 is marked as deprecated*:DeprecationWarning", +# ] + [tool.coverage.run] -source = ["kraken"] -omit = ["*tests*"] +source = ["."] +omit = ["*tests*", "_version.py"] [tool.coverage.report] exclude_lines = ["coverage: disable", "if TYPE_CHECKING:"] @@ -157,7 +167,7 @@ check-filenames = true python_version = "3.11" # junit_xml = "mypy.xml" -files = ["kraken/**/*.py"] +files = ["src/kraken/**/*.py"] exclude = ["tests/**/*.py"] cache_dir = ".cache/mypy" diff --git a/kraken/__init__.py b/src/kraken/__init__.py similarity index 100% rename from kraken/__init__.py rename to src/kraken/__init__.py diff --git a/kraken/base_api/__init__.py b/src/kraken/base_api/__init__.py similarity index 100% rename from kraken/base_api/__init__.py rename to src/kraken/base_api/__init__.py diff --git a/kraken/cli.py b/src/kraken/cli.py similarity index 100% rename from kraken/cli.py rename to src/kraken/cli.py diff --git a/kraken/exceptions/__init__.py b/src/kraken/exceptions/__init__.py similarity index 100% rename from kraken/exceptions/__init__.py rename to src/kraken/exceptions/__init__.py diff --git a/kraken/futures/__init__.py b/src/kraken/futures/__init__.py similarity index 100% rename from kraken/futures/__init__.py rename to src/kraken/futures/__init__.py diff --git a/kraken/futures/funding.py b/src/kraken/futures/funding.py similarity index 100% rename from kraken/futures/funding.py rename to src/kraken/futures/funding.py diff --git a/kraken/futures/market.py b/src/kraken/futures/market.py similarity index 100% rename from kraken/futures/market.py rename to src/kraken/futures/market.py diff --git a/kraken/futures/trade.py b/src/kraken/futures/trade.py similarity index 100% rename from kraken/futures/trade.py rename to src/kraken/futures/trade.py diff --git a/kraken/futures/user.py b/src/kraken/futures/user.py similarity index 100% rename from kraken/futures/user.py rename to src/kraken/futures/user.py diff --git a/kraken/futures/websocket/__init__.py b/src/kraken/futures/websocket/__init__.py similarity index 100% rename from kraken/futures/websocket/__init__.py rename to src/kraken/futures/websocket/__init__.py diff --git a/kraken/futures/ws_client.py b/src/kraken/futures/ws_client.py similarity index 100% rename from kraken/futures/ws_client.py rename to src/kraken/futures/ws_client.py diff --git a/kraken/nft/__init__.py b/src/kraken/nft/__init__.py similarity index 100% rename from kraken/nft/__init__.py rename to src/kraken/nft/__init__.py diff --git a/kraken/nft/market.py b/src/kraken/nft/market.py similarity index 100% rename from kraken/nft/market.py rename to src/kraken/nft/market.py diff --git a/kraken/nft/trade.py b/src/kraken/nft/trade.py similarity index 100% rename from kraken/nft/trade.py rename to src/kraken/nft/trade.py diff --git a/kraken/spot/__init__.py b/src/kraken/spot/__init__.py similarity index 100% rename from kraken/spot/__init__.py rename to src/kraken/spot/__init__.py diff --git a/kraken/spot/earn.py b/src/kraken/spot/earn.py similarity index 100% rename from kraken/spot/earn.py rename to src/kraken/spot/earn.py diff --git a/kraken/spot/funding.py b/src/kraken/spot/funding.py similarity index 100% rename from kraken/spot/funding.py rename to src/kraken/spot/funding.py diff --git a/kraken/spot/market.py b/src/kraken/spot/market.py similarity index 100% rename from kraken/spot/market.py rename to src/kraken/spot/market.py diff --git a/kraken/spot/orderbook.py b/src/kraken/spot/orderbook.py similarity index 100% rename from kraken/spot/orderbook.py rename to src/kraken/spot/orderbook.py diff --git a/kraken/spot/trade.py b/src/kraken/spot/trade.py similarity index 100% rename from kraken/spot/trade.py rename to src/kraken/spot/trade.py diff --git a/kraken/spot/user.py b/src/kraken/spot/user.py similarity index 100% rename from kraken/spot/user.py rename to src/kraken/spot/user.py diff --git a/kraken/spot/websocket/__init__.py b/src/kraken/spot/websocket/__init__.py similarity index 100% rename from kraken/spot/websocket/__init__.py rename to src/kraken/spot/websocket/__init__.py diff --git a/kraken/spot/websocket/connectors.py b/src/kraken/spot/websocket/connectors.py similarity index 100% rename from kraken/spot/websocket/connectors.py rename to src/kraken/spot/websocket/connectors.py diff --git a/kraken/spot/ws_client.py b/src/kraken/spot/ws_client.py similarity index 100% rename from kraken/spot/ws_client.py rename to src/kraken/spot/ws_client.py diff --git a/kraken/utils/__init__.py b/src/kraken/utils/__init__.py similarity index 100% rename from kraken/utils/__init__.py rename to src/kraken/utils/__init__.py diff --git a/kraken/utils/utils.py b/src/kraken/utils/utils.py similarity index 100% rename from kraken/utils/utils.py rename to src/kraken/utils/utils.py From 5e0070e17f893fb5516e12a783c8d296caf13672 Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Schwertfeger Date: Sat, 25 Jan 2025 17:26:06 +0100 Subject: [PATCH 2/4] Cleanup --- .github/workflows/_test_futures_private.yaml | 4 +- Makefile | 23 +++++---- pyproject.toml | 49 ++++++++++---------- src/kraken/base_api/__init__.py | 13 ++++++ src/kraken/futures/ws_client.py | 7 +++ src/kraken/spot/websocket/__init__.py | 7 +++ tests/futures/test_futures_user.py | 9 ---- 7 files changed, 68 insertions(+), 44 deletions(-) diff --git a/.github/workflows/_test_futures_private.yaml b/.github/workflows/_test_futures_private.yaml index fc92912f..7c2914e7 100644 --- a/.github/workflows/_test_futures_private.yaml +++ b/.github/workflows/_test_futures_private.yaml @@ -89,7 +89,7 @@ jobs: FUTURES_SECRET_KEY: ${{ secrets.FUTURES_SECRET_KEY }} FUTURES_SANDBOX_KEY: ${{ secrets.FUTURES_SANDBOX_KEY }} FUTURES_SANDBOX_SECRET: ${{ secrets.FUTURES_SANDBOX_SECRET }} - run: pytest -vv -m "futures and futures_auth and not futures_websocket and not flaky" tests + run: pytest -vv -m "futures and futures_auth and not futures_websocket" tests - name: Testing Futures websocket client env: @@ -97,4 +97,4 @@ jobs: FUTURES_SECRET_KEY: ${{ secrets.FUTURES_SECRET_KEY }} FUTURES_SANDBOX_KEY: ${{ secrets.FUTURES_SANDBOX_KEY }} FUTURES_SANDBOX_SECRET: ${{ secrets.FUTURES_SANDBOX_SECRET }} - run: pytest -vv -m "futures and futures_auth and futures_websocket and not flaky" tests + run: pytest -vv -m "futures and futures_auth and futures_websocket" tests diff --git a/Makefile b/Makefile index 1e4b155e..9ab8ca48 100644 --- a/Makefile +++ b/Makefile @@ -11,18 +11,22 @@ PYTEST_OPTS := -vv --junit-xml=pytest.xml PYTEST_COV_OPTS := $(PYTEST_OPTS) --cov --cov-report=xml:coverage.xml --cov-report=term TEST_DIR := tests -## ======= H E L P ======= +## ======= M A K E F I L E - T A R G E T S ===================================== +## help Show this help message +## .PHONY: help help: @grep "^##" Makefile | sed -e "s/##//" -## ======= B U I L D I N G ======= +## ======= B U I L D I N G ===================================================== ## build Builds the package ## .PHONY: build build: check-uv $(UV) build . +## rebuild Rebuild the package +## .PHONY: rebuild rebuild: clean build @@ -32,7 +36,7 @@ rebuild: clean build doc: cd doc && make html -## ======= I N S T A L L A T I O N ======= +## ======= I N S T A L L A T I O N ============================================= ## install Install the package ## .PHONY: install @@ -45,7 +49,7 @@ install: check-uv dev: check-uv $(UV) pip install -e ".[dev,test,examples,jupyter]" -## ======= T E S T I N G ======= +## ======= T E S T I N G ======================================================= ## test Run the unit tests ## .PHONY: test @@ -56,6 +60,8 @@ test: .PHONY: tests tests: test +## retest Run tests that failed in the last run +## .PHONY: retest retest: @rm .cache/tests/*.log || true @@ -68,7 +74,7 @@ wip: @rm .cache/tests/*.log || true $(PYTEST) -m "wip" -vv $(TEST_DIR) -## coverage Run all tests and generate the coverage report +## coverage Run all tests and generate the coverage report ## .PHONY: coverage coverage: @@ -81,14 +87,15 @@ coverage: doctest: cd docs && make doctest -## ======= M I S C E L A N I O U S ======= +## ======= M I S C E L A N I O U S ============================================= ## pre-commit Run the pre-commit targets ## .PHONY: pre-commit pre-commit: @pre-commit run -a -## ruff Run ruff without fix +## ruff Run ruff without fix +## .PHONY: ruff ruff: $(UVX) ruff check --preview . @@ -141,7 +148,7 @@ clean: find src -name "__pycache__" | xargs rm -rf find examples -name "__pycache__" | xargs rm -rf -## check-uv Check if uv is installed +## check-uv Check if uv is installed ## .PHONY: check-uv check-uv: diff --git a/pyproject.toml b/pyproject.toml index 4c23ded9..8fdf35dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,37 +114,36 @@ cache_dir = ".cache/pytest" # Retrying tests once, as we're testing against lots of API endpoints, the tests # are flaky by design. retries = 1 +retry_delay = 1 # seconds +timeout = 60 # seconds +asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" markers = [ "wip: Used to run a specific test by hand.", "flaky: Flaky tests", - "spot: … Spot endpoint.", - "spot_auth: … authenticated Spot endpoint.", - "spot_earn: … Spot Earn endpoint.", - "spot_trade: … Spot Trade endpoint.", - "spot_user: … Spot User endpoint.", - "spot_market: … Spot Market endpoint.", - "spot_funding: … Spot Funding endpoint.", - "spot_websocket: … Spot Websocket client + Spot Orderbook client.", - "spot_orderbook: … Spot Orderbook client.", - "futures: … Futures endpoint.", - "futures_auth: … authenticated Futures endpoint.", - "futures_market: … Futures Market endpoint.", - "futures_user: … Futures User endpoint.", - "futures_trade: … Futures Trade endpoint.", - "futures_funding: … Futures Funding endpoint.", - "futures_websocket: … Futures Websocket endpoint.", - "nft: … NFT endpoint.", - "nft_auth: … authenticated NFT endpoint.", - "nft_market: … NFT Market endpoint.", - "nft_trade: … NFT Trade endpoint.", + "spot: Spot endpoint.", + "spot_auth: Private Spot endpoint.", + "spot_earn: Spot Earn endpoint.", + "spot_trade: Spot Trade endpoint.", + "spot_user: Spot User endpoint.", + "spot_market: Spot Market endpoint.", + "spot_funding: Spot Funding endpoint.", + "spot_websocket: Spot Websocket client + Spot Orderbook client.", + "spot_orderbook: Spot Orderbook client.", + "futures: Futures endpoint.", + "futures_auth: Private Futures endpoint.", + "futures_market: Futures Market endpoint.", + "futures_user: Futures User endpoint.", + "futures_trade: Futures Trade endpoint.", + "futures_funding: Futures Funding endpoint.", + "futures_websocket: Futures Websocket endpoint.", + "nft: NFT endpoint.", + "nft_auth: Private NFT endpoint.", + "nft_market: NFT Market endpoint.", + "nft_trade: NFT Trade endpoint.", ] -asyncio_default_fixture_loop_scope = "function" - -asyncio_mode = "auto" -timeout = 60 # seconds - # filterwarnings = [ # "ignore:The Kraken websocket API v1 is marked as deprecated*:DeprecationWarning", # ] diff --git a/src/kraken/base_api/__init__.py b/src/kraken/base_api/__init__.py index e51d0f1e..0f28bc9c 100644 --- a/src/kraken/base_api/__init__.py +++ b/src/kraken/base_api/__init__.py @@ -24,6 +24,7 @@ if TYPE_CHECKING: from collections.abc import Awaitable, Callable, Coroutine from typing import Final +import warnings Self = TypeVar("Self") @@ -663,6 +664,12 @@ async def __check_response_data( # pylint: disable=invalid-overridden-method async def async_close(self: SpotAsyncClient) -> None: """Closes the aiohttp session""" + warnings.warn( + "The 'async_close' function is deprecated and will be replaced by" + " 'close' in a future release.", + DeprecationWarning, + stacklevel=2, + ) await self.__session.close() async def __aenter__(self: Self) -> Self: @@ -1144,6 +1151,12 @@ async def __check_response_data( # pylint: disable=invalid-overridden-method async def async_close(self: FuturesAsyncClient) -> None: """Closes the aiohttp session""" + warnings.warn( + "The 'async_close' function is deprecated and will be replaced by" + " 'close' in a future release.", + DeprecationWarning, + stacklevel=2, + ) await self.__session.close() async def __aenter__(self: Self) -> Self: diff --git a/src/kraken/futures/ws_client.py b/src/kraken/futures/ws_client.py index de97a169..1443aead 100644 --- a/src/kraken/futures/ws_client.py +++ b/src/kraken/futures/ws_client.py @@ -22,6 +22,7 @@ if TYPE_CHECKING: from collections.abc import Callable from typing import Any +import warnings Self = TypeVar("Self") @@ -155,6 +156,12 @@ async def start(self: FuturesWSClient) -> None: async def stop(self: FuturesWSClient) -> None: """Method to stop the websocket connection.""" + warnings.warn( + "The 'stop' function is deprecated and will be replaced by" + " 'close' in a future release.", + DeprecationWarning, + stacklevel=2, + ) if self._conn: await self._conn.stop() diff --git a/src/kraken/spot/websocket/__init__.py b/src/kraken/spot/websocket/__init__.py index 27e19e5e..e55c0464 100644 --- a/src/kraken/spot/websocket/__init__.py +++ b/src/kraken/spot/websocket/__init__.py @@ -10,6 +10,7 @@ from __future__ import annotations import logging +import warnings from asyncio import sleep as async_sleep from typing import TYPE_CHECKING, Any, TypeVar @@ -139,6 +140,12 @@ async def start(self: SpotWSClientBase) -> None: async def stop(self: SpotWSClientBase) -> None: """Method to stop the websocket connection.""" + warnings.warn( + "The 'stop' function is deprecated and will be replaced by" + " 'close' in a future release.", + DeprecationWarning, + stacklevel=2, + ) if self._pub_conn: await self._pub_conn.stop() if self._priv_conn: diff --git a/tests/futures/test_futures_user.py b/tests/futures/test_futures_user.py index f04041e2..db053bd0 100644 --- a/tests/futures/test_futures_user.py +++ b/tests/futures/test_futures_user.py @@ -60,7 +60,6 @@ def test_get_notifications(futures_auth_user: User) -> None: assert is_success(futures_auth_user.get_notifications()) -@pytest.mark.flaky @pytest.mark.futures @pytest.mark.futures_auth @pytest.mark.futures_user @@ -75,8 +74,6 @@ def test_get_account_log(futures_auth_user: User) -> None: ) -# FIXME: They often encounter 500 status_codes - maybe an error in Kraken's API -@pytest.mark.flaky @pytest.mark.futures @pytest.mark.futures_auth @pytest.mark.futures_user @@ -96,8 +93,6 @@ def test_get_account_log_csv(futures_auth_user: User) -> None: file.write(chunk) -# FIXME: They often encounter 500 status_codes - maybe an error in Kraken's API -@pytest.mark.flaky @pytest.mark.futures @pytest.mark.futures_auth @pytest.mark.futures_user @@ -116,8 +111,6 @@ def test_get_execution_events(futures_auth_user: User) -> None: assert "elements" in result -# FIXME: They often encounter 500 status_codes - maybe an error in Kraken's API -@pytest.mark.flaky @pytest.mark.futures @pytest.mark.futures_auth @pytest.mark.futures_user @@ -155,8 +148,6 @@ def test_get_open_positions(futures_auth_user: User) -> None: assert is_success(futures_auth_user.get_open_positions()) -# FIXME: They often encounter 500 status_codes - maybe an error in Kraken's API -@pytest.mark.flaky @pytest.mark.futures @pytest.mark.futures_auth @pytest.mark.futures_user From 6e974422bd0321c8c139c96ab3b3be28395829d1 Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Schwertfeger Date: Sat, 25 Jan 2025 20:34:14 +0100 Subject: [PATCH 3/4] Update tests --- tests/spot/test_spot_orderbook.py | 2 +- tests/spot/test_spot_websocket.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/spot/test_spot_orderbook.py b/tests/spot/test_spot_orderbook.py index 27a91835..e5b728b2 100644 --- a/tests/spot/test_spot_orderbook.py +++ b/tests/spot/test_spot_orderbook.py @@ -45,7 +45,7 @@ async def create_bot() -> None: for expected in ( 'channel": "status"', '"api_version": "v2"', - '"system": "online", "version": "2.', + '"system": "online",', '"type": "update"', ): assert expected in caplog.text diff --git a/tests/spot/test_spot_websocket.py b/tests/spot/test_spot_websocket.py index a66ebc01..361aca97 100644 --- a/tests/spot/test_spot_websocket.py +++ b/tests/spot/test_spot_websocket.py @@ -53,7 +53,7 @@ async def create_client() -> None: for expected in ( 'channel": "status"', '"api_version": "v2"', - '"system": "online", "version": "2.', + '"system": "online",', '"type": "update"', ): assert expected in caplog.text @@ -77,7 +77,7 @@ async def create_client_as_context_manager() -> None: for expected in ( 'channel": "status"', '"api_version": "v2"', - '"system": "online", "version": "2.', + '"system": "online",', '"type": "update"', ): assert expected in caplog.text @@ -496,9 +496,11 @@ async def check_reconnect() -> None: "Recover public subscriptions []: done", "Recover authenticated subscriptions []: done", "Websocket connected!", - '{"channel": "status", "data": [{"api_version": "v2", "connection_id": ', - '"system": "online", "version": ', # "2.0.x" - '"type": "update"}', + '{"channel": "status",', + '"data": [{', + '"api_version": "v2",', + '"connection_id": ', + '"system": "online",', '{"method": "subscribe", "result": {"channel": "ticker", "event_trigger": "trades", "snapshot": true, "symbol": "BTC/USD"}, "success": true,', '"channel": "ticker", "type": "snapshot", "data": [{"symbol": "BTC/USD", ', "got an exception sent 1000 (OK); then received 1000 (OK)", From 172dc771592c5a151cf54d540303feb5f9ba742b Mon Sep 17 00:00:00 2001 From: Benjamin Thomas Schwertfeger Date: Sat, 25 Jan 2025 20:53:53 +0100 Subject: [PATCH 4/4] Run more CI jobs --- .github/workflows/cicd.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 257b96f8..ec7a0fba 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -83,7 +83,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] with: os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} @@ -110,7 +110,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] with: os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} @@ -125,7 +125,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.13"] # not testing 3.12 to reduce CI time with: os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} @@ -143,7 +143,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] with: os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} @@ -158,7 +158,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] with: os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} @@ -175,7 +175,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] with: os: ${{ matrix.os }} python-version: ${{ matrix.python-version }} @@ -190,7 +190,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] with: os: ${{ matrix.os }} python-version: ${{ matrix.python-version }}