Skip to content

Commit ceea218

Browse files
somewhat done with restructuring
1 parent 8d07636 commit ceea218

File tree

8 files changed

+831
-871
lines changed

8 files changed

+831
-871
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ task-tags = ["todo", "TODO", "fixme", "FIXME"]
291291
"S311", # pseudo-random-generator
292292
"SLF001", # private member access
293293
"TID252", # ban relative imports
294+
"PLR0904", # too many public methods
295+
"ANN401", # Use of typing.Any
294296
]
295297

296298
[tool.ruff.lint.flake8-copyright]

tests/futures/conftest.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
FUTURES_EXTENDED_TIMEOUT: int = 30
1919

2020

21-
@pytest.fixture
21+
@pytest.fixture(scope="session")
2222
def futures_api_key() -> str:
2323
"""Returns the Futures API key"""
2424
return FUTURES_API_KEY
2525

2626

27-
@pytest.fixture
27+
@pytest.fixture(scope="session")
2828
def futures_secret_key() -> str:
2929
"""Returns the Futures API secret key"""
3030
return FUTURES_SECRET_KEY
3131

3232

33-
@pytest.fixture
33+
@pytest.fixture(scope="session")
3434
def futures_market() -> Market:
3535
"""
3636
Fixture providing an unauthenticated Futures Market client
@@ -40,7 +40,7 @@ def futures_market() -> Market:
4040
return market
4141

4242

43-
@pytest.fixture
43+
@pytest.fixture(scope="session")
4444
def futures_auth_market() -> Market:
4545
"""
4646
Fixture providing an authenticated Futures Market client.
@@ -50,7 +50,7 @@ def futures_auth_market() -> Market:
5050
return market
5151

5252

53-
@pytest.fixture
53+
@pytest.fixture(scope="session")
5454
def futures_demo_market() -> Market:
5555
"""
5656
Fixture providing an authenticated Futures Market client that
@@ -65,7 +65,7 @@ def futures_demo_market() -> Market:
6565
return market
6666

6767

68-
@pytest.fixture
68+
@pytest.fixture(scope="session")
6969
def futures_user() -> User:
7070
"""
7171
Fixture providing an unauthenticated Futures User client.
@@ -75,7 +75,7 @@ def futures_user() -> User:
7575
return user
7676

7777

78-
@pytest.fixture
78+
@pytest.fixture(scope="session")
7979
def futures_auth_user() -> User:
8080
"""
8181
Fixture providing an authenticated Futures User client.
@@ -85,7 +85,7 @@ def futures_auth_user() -> User:
8585
return user
8686

8787

88-
@pytest.fixture
88+
@pytest.fixture(scope="session")
8989
def futures_demo_user() -> User:
9090
"""
9191
Fixture providing an authenticated Futures User client that
@@ -100,7 +100,7 @@ def futures_demo_user() -> User:
100100
return user
101101

102102

103-
@pytest.fixture
103+
@pytest.fixture(scope="session")
104104
def futures_trade() -> Trade:
105105
"""
106106
Fixture providing an unauthenticated Futures Trade client.
@@ -110,7 +110,7 @@ def futures_trade() -> Trade:
110110
return trade
111111

112112

113-
@pytest.fixture
113+
@pytest.fixture(scope="session")
114114
def futures_auth_trade() -> Trade:
115115
"""
116116
Fixture providing an authenticated Futures Trade client.
@@ -120,7 +120,7 @@ def futures_auth_trade() -> Trade:
120120
return trade
121121

122122

123-
@pytest.fixture
123+
@pytest.fixture(scope="session")
124124
def futures_demo_trade() -> Trade:
125125
"""
126126
Fixture providing an authenticated Futures Trade client that
@@ -135,7 +135,7 @@ def futures_demo_trade() -> Trade:
135135
return trade
136136

137137

138-
@pytest.fixture
138+
@pytest.fixture(scope="session")
139139
def futures_funding() -> Funding:
140140
"""
141141
Fixture providing an unauthenticated Futures Funding client.
@@ -145,7 +145,7 @@ def futures_funding() -> Funding:
145145
return funding
146146

147147

148-
@pytest.fixture
148+
@pytest.fixture(scope="session")
149149
def futures_auth_funding() -> Funding:
150150
"""
151151
Fixture providing an authenticated Futures Funding client.
@@ -155,7 +155,7 @@ def futures_auth_funding() -> Funding:
155155
return funding
156156

157157

158-
@pytest.fixture
158+
@pytest.fixture(scope="session")
159159
def futures_demo_funding() -> Funding:
160160
"""
161161
Fixture providing an authenticated Futures Funding client that

tests/futures/test_futures_base_api.py

Lines changed: 98 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""Module that checks the general Futures Base API class."""
99

1010
from asyncio import run
11+
from typing import Self
1112
from unittest import IsolatedAsyncioTestCase
1213

1314
import pytest
@@ -21,116 +22,121 @@
2122

2223

2324
@pytest.mark.futures
24-
def test_KrakenFuturesBaseAPI_without_exception() -> None:
25-
"""
26-
Checks first if the expected error will be raised and than
27-
creates a new KrakenFuturesBaseAPI instance that do not raise
28-
the custom Kraken exceptions. This new instance than executes
29-
the same request and the returned response gets evaluated.
30-
"""
31-
with pytest.raises(KrakenRequiredArgumentMissingError):
32-
FuturesClient(
33-
key="fake",
34-
secret="fake",
35-
).request(method="POST", uri="/derivatives/api/v3/sendorder", auth=True)
36-
37-
result: dict = (
38-
FuturesClient(key="fake", secret="fake", use_custom_exceptions=False) # type: ignore[union-attr]
39-
.request(method="POST", uri="/derivatives/api/v3/sendorder", auth=True)
40-
.json()
41-
)
42-
43-
assert result.get("result") == "error"
44-
assert result.get("error") == "requiredArgumentMissing"
25+
class TestFuturesBaseAPI:
26+
"""Test class for Futures Base API functionality."""
4527

28+
def test_KrakenFuturesBaseAPI_without_exception(self) -> None:
29+
"""
30+
Checks first if the expected error will be raised and then
31+
creates a new KrakenFuturesBaseAPI instance that does not raise
32+
the custom Kraken exceptions. This new instance then executes
33+
the same request and the returned response gets evaluated.
34+
"""
35+
with pytest.raises(KrakenRequiredArgumentMissingError):
36+
FuturesClient(
37+
key="fake",
38+
secret="fake",
39+
).request(method="POST", uri="/derivatives/api/v3/sendorder", auth=True)
40+
41+
result: dict = (
42+
FuturesClient(key="fake", secret="fake", use_custom_exceptions=False) # type: ignore[union-attr]
43+
.request(method="POST", uri="/derivatives/api/v3/sendorder", auth=True)
44+
.json()
45+
)
4646

47-
@pytest.mark.futures
48-
@pytest.mark.futures_auth
49-
def test_futures_rest_contextmanager(
50-
futures_market: Market,
51-
futures_auth_funding: Funding,
52-
futures_demo_trade: Trade,
53-
futures_auth_user: User,
54-
) -> None:
55-
"""
56-
Checks if the clients can be used as context manager.
57-
"""
58-
with futures_market as market:
59-
assert isinstance(market.get_tick_types(), list)
47+
assert result.get("result") == "error"
48+
assert result.get("error") == "requiredArgumentMissing"
49+
50+
@pytest.mark.futures_auth
51+
def test_futures_rest_contextmanager(
52+
self,
53+
futures_market: Market,
54+
futures_auth_funding: Funding,
55+
futures_demo_trade: Trade,
56+
futures_auth_user: User,
57+
) -> None:
58+
"""
59+
Checks if the clients can be used as context manager.
60+
"""
61+
with futures_market as market:
62+
assert isinstance(market.get_tick_types(), list)
6063

61-
with futures_auth_funding as funding:
62-
assert is_success(funding.get_historical_funding_rates(symbol="PF_SOLUSD"))
64+
with futures_auth_funding as funding:
65+
assert is_success(funding.get_historical_funding_rates(symbol="PF_SOLUSD"))
6366

64-
with futures_auth_user as user:
65-
assert is_success(user.get_wallets())
67+
with futures_auth_user as user:
68+
assert is_success(user.get_wallets())
6669

67-
with futures_demo_trade as trade:
68-
assert is_success(trade.get_fills())
70+
with futures_demo_trade as trade:
71+
assert is_success(trade.get_fills())
6972

7073

7174
# ==============================================================================
7275
# Futures async client
7376

7477

7578
@pytest.mark.futures
76-
def test_futures_async_rest_contextmanager() -> None:
77-
"""
78-
Checks if the clients can be used as context manager.
79-
"""
80-
81-
async def check() -> None:
82-
async with FuturesAsyncClient() as client:
83-
assert isinstance(
84-
await client.request(
85-
"GET",
86-
"/api/charts/v1/spot/PI_XBTUSD/1h",
87-
auth=False,
88-
post_params={"from": "1668989233", "to": "1668999233"},
89-
),
90-
dict,
91-
)
92-
93-
run(check())
79+
class TestFuturesBaseAPIAsync:
80+
"""Test class for Futures Base API async functionality."""
9481

82+
def test_futures_async_rest_contextmanager(self: Self) -> None:
83+
"""
84+
Checks if the clients can be used as context manager.
85+
"""
9586

96-
@pytest.mark.futures
97-
@pytest.mark.futures_auth
98-
def test_futures_rest_async_client_post(
99-
futures_api_key: str,
100-
futures_secret_key: str,
101-
) -> None:
102-
"""
103-
Check the instantiation as well as a simple request using the async client.
104-
"""
105-
106-
async def check() -> None:
107-
client = FuturesAsyncClient(futures_api_key, futures_secret_key)
108-
try:
109-
assert isinstance(
110-
await client.request(
111-
"POST",
112-
"/derivatives/api/v3/orders/status",
113-
post_params={
114-
"orderIds": [
115-
"bcaaefce-27a3-44b4-b13a-19df21e3f087",
116-
"685d5a1a-23eb-450c-bf17-1e4ab5c6fe8a",
117-
],
118-
},
119-
),
120-
dict,
121-
)
122-
finally:
123-
await client.close()
124-
125-
run(check())
87+
async def check() -> None:
88+
async with FuturesAsyncClient() as client:
89+
assert isinstance(
90+
await client.request(
91+
"GET",
92+
"/api/charts/v1/spot/PI_XBTUSD/1h",
93+
auth=False,
94+
post_params={"from": "1668989233", "to": "1668999233"},
95+
),
96+
dict,
97+
)
98+
99+
run(check())
100+
101+
@pytest.mark.futures_auth
102+
def test_futures_rest_async_client_post(
103+
self: Self,
104+
futures_api_key: str,
105+
futures_secret_key: str,
106+
) -> None:
107+
"""
108+
Check the instantiation as well as a simple request using the async client.
109+
"""
110+
111+
async def check() -> None:
112+
client = FuturesAsyncClient(futures_api_key, futures_secret_key)
113+
try:
114+
assert isinstance(
115+
await client.request(
116+
"POST",
117+
"/derivatives/api/v3/orders/status",
118+
post_params={
119+
"orderIds": [
120+
"bcaaefce-27a3-44b4-b13a-19df21e3f087",
121+
"685d5a1a-23eb-450c-bf17-1e4ab5c6fe8a",
122+
],
123+
},
124+
),
125+
dict,
126+
)
127+
finally:
128+
await client.close()
129+
130+
run(check())
126131

127132

133+
@pytest.mark.futures
134+
@pytest.mark.futures_market
135+
@pytest.mark.futures_market
128136
class TestProxyPyEmbedded(TestCase, IsolatedAsyncioTestCase):
129-
def get_proxy_str(self) -> str:
137+
def get_proxy_str(self: Self) -> str:
130138
return f"http://127.0.0.1:{self.PROXY.flags.port}"
131139

132-
@pytest.mark.futures
133-
@pytest.mark.futures_market
134140
def test_futures_rest_proxies(self) -> None:
135141
"""
136142
Checks if the clients can be used with a proxy.
@@ -147,9 +153,7 @@ def test_futures_rest_proxies(self) -> None:
147153
)
148154

149155
@pytest.mark.asyncio
150-
@pytest.mark.futures
151-
@pytest.mark.futures_market
152-
async def test_futures_rest_proxies_async(self) -> None:
156+
async def test_futures_rest_proxies_async(self: Self) -> None:
153157
"""
154158
Checks if the async clients can be used with a proxy.
155159
"""

0 commit comments

Comments
 (0)