bitvavo-api-upgraded 4.2.0__py3-none-any.whl → 4.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bitvavo-api-upgraded
3
- Version: 4.2.0
3
+ Version: 4.2.1
4
4
  Summary: A unit-tested fork of the Bitvavo API
5
5
  Author: Bitvavo BV (original code), NostraDavid
6
6
  Author-email: NostraDavid <55331731+NostraDavid@users.noreply.github.com>
@@ -9,7 +9,7 @@ bitvavo_client/__init__.py,sha256=YXTBdP6fBREV34VeTqS_gkjfzIoHv5uSYhbqSUEeAVU,20
9
9
  bitvavo_client/adapters/__init__.py,sha256=9YVjMhNiAN6K1x7N0UvAXMQwuhOFy4W6Edrba1hW8KI,64
10
10
  bitvavo_client/adapters/returns_adapter.py,sha256=3HSAPw6HB9GCS8AbKmeidURpZXnvMZqkvalOu6JhBv0,14195
11
11
  bitvavo_client/auth/__init__.py,sha256=bjWu5WCKNNnNoLcVU290tKBml9M5afmcxaU_KrkisSQ,39
12
- bitvavo_client/auth/rate_limit.py,sha256=NzWpWCc263diuJ3hVPH-fpJjKXy8a1WvdxHqOgvpplQ,4088
12
+ bitvavo_client/auth/rate_limit.py,sha256=EfZtt4nxzu8D3Ea2ElYadrAvEYEt_Wlm60P8u-zVMvs,4391
13
13
  bitvavo_client/auth/signing.py,sha256=DJrI1R1SLKjl276opj9hN4RrKIgsMhxsSEDA8b7T04I,1037
14
14
  bitvavo_client/core/__init__.py,sha256=WqjaU9Ut5JdZwn4tsR1vDdrSfMjEJred3im6fvWpalc,39
15
15
  bitvavo_client/core/errors.py,sha256=jWHHQKqkkhpHS9TeKlccl7wuyuRrq0H_PGZ0bl6sbW4,460
@@ -26,7 +26,7 @@ bitvavo_client/endpoints/base.py,sha256=EyhxXJ2YVuXJeaIwgvF7VAzY-qVZ9maA282Xj0lS
26
26
  bitvavo_client/endpoints/common.py,sha256=fc4gNNZ2zGMJJwkbHexNz6qMDLjl6dalQFGDXWmBo2E,2413
27
27
  bitvavo_client/endpoints/private.py,sha256=yChMe-HL2wFm6GBYoghURjdLzSxCPTYlEIOjysCrn3E,34589
28
28
  bitvavo_client/endpoints/public.py,sha256=EY7y3vuuo3li1BiPCM2KfSNnoa91X426DPtp8BvHiS8,21944
29
- bitvavo_client/facade.py,sha256=uEfjZu5Ag2KcSVVgv_KTt7lYkRl0_TzNYXTK5SCA3e8,3583
29
+ bitvavo_client/facade.py,sha256=y08585HMAhYGRI51dUbBezsTFOoZFKgpMZ4GA39r1ew,4368
30
30
  bitvavo_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
31
  bitvavo_client/schemas/__init__.py,sha256=udqMyAFElrcBbNJIhoarQuTI-CF425JvPFqgLVjILU8,1126
32
32
  bitvavo_client/schemas/private_schemas.py,sha256=cG-cV5HKO8ZvWp3hjUPBFMT6Th0UBumMViI8gAZTyik,6143
@@ -34,6 +34,6 @@ bitvavo_client/schemas/public_schemas.py,sha256=zfV6C_PQvNLLYEWS72ZD77Nm3XtRrEgh
34
34
  bitvavo_client/transport/__init__.py,sha256=H7txnyuz6v84_GzdBiqpsehVQitEymgUTA5AJPeUEvg,44
35
35
  bitvavo_client/transport/http.py,sha256=H5N-ZQbKwtKsGNadi6YB1gTCViZSns2TMLCGY0LiKgQ,6144
36
36
  bitvavo_client/ws/__init__.py,sha256=Q4SVEq3EihXLVUKpguMdxrhfNAoU8cncpMFbU6kIX_0,44
37
- bitvavo_api_upgraded-4.2.0.dist-info/WHEEL,sha256=Jb20R3Ili4n9P1fcwuLup21eQ5r9WXhs4_qy7VTrgPI,79
38
- bitvavo_api_upgraded-4.2.0.dist-info/METADATA,sha256=l5ySQtIhs57E-OwDwce5hzd4i_JBkZQ-givaObkcfkE,35937
39
- bitvavo_api_upgraded-4.2.0.dist-info/RECORD,,
37
+ bitvavo_api_upgraded-4.2.1.dist-info/WHEEL,sha256=Jb20R3Ili4n9P1fcwuLup21eQ5r9WXhs4_qy7VTrgPI,79
38
+ bitvavo_api_upgraded-4.2.1.dist-info/METADATA,sha256=qil3_u24JDZf1uKRE22_kX87viD56lXcSZw4R6o8EdU,35937
39
+ bitvavo_api_upgraded-4.2.1.dist-info/RECORD,,
@@ -34,6 +34,7 @@ class RateLimitManager:
34
34
  buffer: Buffer to keep before hitting limit
35
35
  strategy: Optional strategy callback when rate limit exceeded
36
36
  """
37
+ self.default_remaining: int = default_remaining
37
38
  self.state: dict[int, dict[str, int]] = {-1: {"remaining": default_remaining, "resetAt": 0}}
38
39
  self.buffer: int = buffer
39
40
 
@@ -100,6 +101,12 @@ class RateLimitManager:
100
101
  """Invoke the configured strategy when rate limit is exceeded."""
101
102
  self._strategy(self, idx, weight)
102
103
 
104
+ def reset_key(self, idx: int) -> None:
105
+ """Reset the remaining budget and reset time for a key index."""
106
+ self.ensure_key(idx)
107
+ self.state[idx]["remaining"] = self.default_remaining
108
+ self.state[idx]["resetAt"] = 0
109
+
103
110
  def get_remaining(self, idx: int) -> int:
104
111
  """Get remaining rate limit for key index.
105
112
 
bitvavo_client/facade.py CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import time
5
6
  from typing import TYPE_CHECKING, TypeVar
6
7
 
7
8
  from bitvavo_client.auth.rate_limit import RateLimitManager
@@ -51,7 +52,7 @@ class BitvavoClient:
51
52
 
52
53
  # Configure API keys if available
53
54
  self._api_keys: list[tuple[str, str]] = []
54
- self._current_key: int = 0
55
+ self._current_key: int = -1
55
56
  self._configure_api_keys()
56
57
 
57
58
  def _configure_api_keys(self) -> None:
@@ -68,18 +69,42 @@ class BitvavoClient:
68
69
  for idx, (_key, _secret) in enumerate(self._api_keys):
69
70
  self.rate_limiter.ensure_key(idx)
70
71
 
71
- first_key = self._api_keys[0]
72
- self.http.configure_key(first_key[0], first_key[1], 0)
73
- if len(self._api_keys) > 1:
72
+ if self._api_keys:
74
73
  self.http.set_key_rotation_callback(self.rotate_key)
75
74
 
76
75
  def rotate_key(self) -> bool:
77
76
  """Rotate to the next configured API key if available."""
78
- if len(self._api_keys) <= 1:
77
+ if not self._api_keys:
79
78
  return False
80
- self._current_key = (self._current_key + 1) % len(self._api_keys)
81
- key, secret = self._api_keys[self._current_key]
82
- self.http.configure_key(key, secret, self._current_key)
79
+
80
+ now = int(time.time() * 1000)
81
+
82
+ if self._current_key == -1:
83
+ idx = 0
84
+ if now < self.rate_limiter.get_reset_at(idx):
85
+ self.rate_limiter.sleep_until_reset(idx)
86
+ self.rate_limiter.reset_key(idx)
87
+ self._current_key = idx
88
+ key, secret = self._api_keys[idx]
89
+ self.http.configure_key(key, secret, idx)
90
+ return True
91
+
92
+ if self._current_key < len(self._api_keys) - 1:
93
+ idx = self._current_key + 1
94
+ if now < self.rate_limiter.get_reset_at(idx):
95
+ self.rate_limiter.sleep_until_reset(idx)
96
+ self.rate_limiter.reset_key(idx)
97
+ self._current_key = idx
98
+ key, secret = self._api_keys[idx]
99
+ self.http.configure_key(key, secret, idx)
100
+ return True
101
+
102
+ reset_at = self.rate_limiter.get_reset_at(-1)
103
+ if now < reset_at:
104
+ self.rate_limiter.sleep_until_reset(-1)
105
+ self.rate_limiter.reset_key(-1)
106
+ self._current_key = -1
107
+ self.http.configure_key("", "", -1)
83
108
  return True
84
109
 
85
110
  def select_key(self, index: int) -> None: