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

Switch to src-layout #342

Merged
merged 4 commits into from
Jan 25, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
btschwertfeger committed Jan 25, 2025
commit 5e0070e17f893fb5516e12a783c8d296caf13672
4 changes: 2 additions & 2 deletions .github/workflows/_test_futures_private.yaml
Original file line number Diff line number Diff line change
@@ -89,12 +89,12 @@ 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:
FUTURES_API_KEY: ${{ secrets.FUTURES_API_KEY }}
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
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
49 changes: 24 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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",
# ]
13 changes: 13 additions & 0 deletions src/kraken/base_api/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 7 additions & 0 deletions src/kraken/futures/ws_client.py
Original file line number Diff line number Diff line change
@@ -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()

7 changes: 7 additions & 0 deletions src/kraken/spot/websocket/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
9 changes: 0 additions & 9 deletions tests/futures/test_futures_user.py
Original file line number Diff line number Diff line change
@@ -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
Loading
Oops, something went wrong.