bitvavo-api-upgraded 1.17.0__py3-none-any.whl → 1.17.2__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,3 +1,8 @@
1
1
  from bitvavo_api_upgraded.bitvavo import Bitvavo
2
+ from bitvavo_api_upgraded.settings import BitvavoApiUpgradedSettings, BitvavoSettings
2
3
 
3
- __all__ = ["Bitvavo"]
4
+ __all__ = [
5
+ "Bitvavo",
6
+ "BitvavoApiUpgradedSettings",
7
+ "BitvavoSettings",
8
+ ]
@@ -5,6 +5,7 @@ import hashlib
5
5
  import hmac
6
6
  import json
7
7
  import time
8
+ from pathlib import Path
8
9
  from threading import Thread
9
10
  from typing import Any, Callable
10
11
 
@@ -14,7 +15,7 @@ from structlog.stdlib import get_logger
14
15
  from websocket import WebSocketApp # missing stubs for WebSocketApp
15
16
 
16
17
  from bitvavo_api_upgraded.helper_funcs import configure_loggers, time_ms, time_to_wait
17
- from bitvavo_api_upgraded.settings import BITVAVO_API_UPGRADED
18
+ from bitvavo_api_upgraded.settings import bitvavo_upgraded_settings
18
19
  from bitvavo_api_upgraded.type_aliases import anydict, errordict, intdict, ms, s_f, strdict, strintdict
19
20
 
20
21
  configure_loggers()
@@ -158,9 +159,6 @@ def callback_example(response: Any) -> None:
158
159
  """
159
160
  if isinstance(response, dict):
160
161
  # instead of printing, you could save the object to a file:
161
- import json
162
- from pathlib import Path
163
-
164
162
  HERE = Path.cwd() # root of your project folder
165
163
  filepath = HERE / "your_output.json"
166
164
  # a = append; figure out yourself to create multiple callback functions, probably one for each type of call that
@@ -332,7 +330,7 @@ class Bitvavo:
332
330
  list[list[str]]
333
331
  ```
334
332
  """
335
- if (self.rateLimitRemaining - rateLimitingWeight) <= BITVAVO_API_UPGRADED.RATE_LIMITING_BUFFER:
333
+ if (self.rateLimitRemaining - rateLimitingWeight) <= bitvavo_upgraded_settings.RATE_LIMITING_BUFFER:
336
334
  self.sleep_until_can_continue()
337
335
  if self.debugging:
338
336
  logger.debug(
@@ -344,7 +342,7 @@ class Bitvavo:
344
342
  },
345
343
  )
346
344
  if self.APIKEY != "":
347
- now = time_ms() + BITVAVO_API_UPGRADED.LAG
345
+ now = time_ms() + bitvavo_upgraded_settings.LAG
348
346
  sig = createSignature(now, "GET", url.replace(self.base, ""), None, self.APISECRET)
349
347
  headers = {
350
348
  "bitvavo-access-key": self.APIKEY,
@@ -391,10 +389,10 @@ class Bitvavo:
391
389
  list[list[str]]
392
390
  ```
393
391
  """
394
- if (self.rateLimitRemaining - rateLimitingWeight) <= BITVAVO_API_UPGRADED.RATE_LIMITING_BUFFER:
392
+ if (self.rateLimitRemaining - rateLimitingWeight) <= bitvavo_upgraded_settings.RATE_LIMITING_BUFFER:
395
393
  self.sleep_until_can_continue()
396
394
  # if this method breaks: add `= {}` after `body: dict`
397
- now = time_ms() + BITVAVO_API_UPGRADED.LAG
395
+ now = time_ms() + bitvavo_upgraded_settings.LAG
398
396
  sig = createSignature(now, method, (endpoint + postfix), body, self.APISECRET)
399
397
  url = self.base + endpoint + postfix
400
398
  headers = {
@@ -591,6 +589,7 @@ class Bitvavo:
591
589
  "nonce": 10378032,
592
590
  "bids": [["1.1908", "600"], ["1.1902", "4091.359809"], ["1.1898", "7563"]],
593
591
  "asks": [["1.1917", "2382.166997"], ["1.1919", "440.7"], ["1.192", "600"]],
592
+ "timestamp": 1700000000000,
594
593
  }
595
594
 
596
595
  # Notice how each bid and ask is also a list
@@ -1832,7 +1831,7 @@ class Bitvavo:
1832
1831
  self.subscriptionBook(market, self.callbacks["subscriptionBookUser"][market])
1833
1832
 
1834
1833
  def on_open(self, ws: Any) -> None: # noqa: ARG002
1835
- now = time_ms() + BITVAVO_API_UPGRADED.LAG
1834
+ now = time_ms() + bitvavo_upgraded_settings.LAG
1836
1835
  self.open = True
1837
1836
  self.reconnectTimer = 0.5
1838
1837
  if self.APIKEY != "":
@@ -1,47 +1,70 @@
1
1
  import logging
2
2
  from pathlib import Path
3
3
 
4
- from decouple import AutoConfig, Choices
4
+ from pydantic import Field, field_validator, model_validator
5
+ from pydantic_settings import BaseSettings, SettingsConfigDict
5
6
 
6
7
  from bitvavo_api_upgraded.type_aliases import ms
7
8
 
8
- # don't use/import python-decouple's `config`` variable, because the search_path isn't set,
9
- # which means applications that use a .env file can't override these variables :(
10
- config = AutoConfig(search_path=Path.cwd())
11
9
 
10
+ class BitvavoApiUpgradedSettings(BaseSettings):
11
+ """
12
+ These settings provide extra functionality. Originally I wanted to combine
13
+ then, but I figured that would be a bad idea.
14
+ """
12
15
 
13
- class _BitvavoApiUpgraded:
14
- # default LOG_LEVEL is WARNING, so users don't get their ass spammed.
15
- LOG_LEVEL: str = config(
16
- "BITVAVO_API_UPGRADED_LOG_LEVEL",
17
- default="INFO",
18
- cast=Choices(list(logging._nameToLevel.keys())), # noqa: SLF001
19
- )
20
- LOG_EXTERNAL_LEVEL: str = config(
21
- "BITVAVO_API_UPGRADED_EXTERNAL_LOG_LEVEL",
22
- default="WARNING",
23
- cast=Choices(list(logging._nameToLevel.keys())), # noqa: SLF001
16
+ LOG_LEVEL: str = Field("INFO")
17
+ LOG_EXTERNAL_LEVEL: str = Field("WARNING")
18
+ LAG: ms = Field(ms(50))
19
+ RATE_LIMITING_BUFFER: int = Field(25)
20
+
21
+ # Configuration for Pydantic Settings
22
+ model_config = SettingsConfigDict(
23
+ env_file=Path.cwd() / ".env",
24
+ env_file_encoding="utf-8",
25
+ env_prefix="BITVAVO_API_UPGRADED_",
26
+ extra="ignore",
24
27
  )
25
- LAG: ms = config("BITVAVO_API_UPGRADED_LAG", default=ms(50), cast=ms)
26
- RATE_LIMITING_BUFFER: int = config("BITVAVO_API_UPGRADED_RATE_LIMITING_BUFFER", default=25, cast=int)
27
28
 
29
+ @classmethod
30
+ @field_validator("LOG_LEVEL", "LOG_EXTERNAL_LEVEL", mode="before")
31
+ def validate_log_level(cls, v: str) -> str:
32
+ if v not in logging._nameToLevel: # noqa: SLF001
33
+ msg = f"Invalid log level: {v}"
34
+ raise ValueError(msg)
35
+ return v
28
36
 
29
- class _Bitvavo:
37
+
38
+ class BitvavoSettings(BaseSettings):
30
39
  """
31
- Changeable variables are handled by the decouple lib, anything else is just static, because they are based on
32
- Bitvavo's documentation and thus should not be able to be set outside of the application.
40
+ These are the base settings from the original library.
33
41
  """
34
42
 
35
- ACCESSWINDOW: int = config("BITVAVO_ACCESSWINDOW", default=10_000, cast=int)
36
- API_RATING_LIMIT_PER_MINUTE: int = 1000
37
- API_RATING_LIMIT_PER_SECOND: float = API_RATING_LIMIT_PER_MINUTE / 60
38
- APIKEY: str = config("BITVAVO_APIKEY", default="BITVAVO_APIKEY is missing")
39
- APISECRET: str = config("BITVAVO_APISECRET", default="BITVAVO_APISECRET is missing")
40
- DEBUGGING: bool = config("BITVAVO_DEBUGGING", default=False, cast=bool)
41
- RESTURL: str = "https://api.bitvavo.com/v2"
42
- WSURL: str = "wss://ws.bitvavo.com/v2/"
43
+ ACCESSWINDOW: int = Field(10_000)
44
+ API_RATING_LIMIT_PER_MINUTE: int = Field(default=1000)
45
+ API_RATING_LIMIT_PER_SECOND: int = Field(default=1000)
46
+ APIKEY: str = Field(default="BITVAVO_APIKEY is missing")
47
+ APISECRET: str = Field(default="BITVAVO_APISECRET is missing")
48
+ DEBUGGING: bool = Field(default=False)
49
+ RESTURL: str = Field(default="https://api.bitvavo.com/v2")
50
+ WSURL: str = Field(default="wss://ws.bitvavo.com/v2/")
51
+
52
+ # Configuration for Pydantic Settings
53
+ model_config = SettingsConfigDict(
54
+ env_file=Path.cwd() / ".env",
55
+ env_file_encoding="utf-8",
56
+ env_prefix="BITVAVO_",
57
+ extra="ignore",
58
+ )
59
+
60
+ @model_validator(mode="after")
61
+ def set_api_rating_limit_per_second(self) -> "BitvavoSettings":
62
+ self.API_RATING_LIMIT_PER_SECOND = self.API_RATING_LIMIT_PER_SECOND // 60
63
+ return self
43
64
 
44
65
 
45
- # Just import these variables to use the settings :)
46
- BITVAVO_API_UPGRADED = _BitvavoApiUpgraded()
47
- BITVAVO = _Bitvavo()
66
+ # Initialize the settings
67
+ bitvavo_upgraded_settings = BitvavoApiUpgradedSettings()
68
+ BITVAVO_API_UPGRADED = bitvavo_upgraded_settings
69
+ bitvavo_settings = BitvavoSettings()
70
+ BITVAVO = bitvavo_settings
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: bitvavo-api-upgraded
3
- Version: 1.17.0
3
+ Version: 1.17.2
4
4
  Summary: A unit-tested fork of the Bitvavo API
5
5
  Project-URL: homepage, https://github.com/Thaumatorium/bitvavo-api-upgraded
6
6
  Project-URL: repository, https://github.com/Thaumatorium/bitvavo-api-upgraded
@@ -9,6 +9,7 @@ Author: Bitvavo BV (original code)
9
9
  Author-email: NostraDavid <55331731+NostraDavid@users.noreply.github.com>
10
10
  Maintainer-email: NostraDavid <55331731+NostraDavid@users.noreply.github.com>
11
11
  License: ISC License
12
+ License-File: LICENSE.txt
12
13
  Classifier: Development Status :: 5 - Production/Stable
13
14
  Classifier: Environment :: Console
14
15
  Classifier: Framework :: Pytest
@@ -27,9 +28,9 @@ Classifier: Programming Language :: Python :: 3.12
27
28
  Classifier: Programming Language :: Python :: 3.13
28
29
  Classifier: Typing :: Typed
29
30
  Requires-Python: >=3.9
30
- Requires-Dist: python-decouple==3.*,>=3.5
31
+ Requires-Dist: pydantic-settings==2.*,>=2.6
31
32
  Requires-Dist: requests==2.*,>=2.26
32
- Requires-Dist: structlog==24.*,>=21.5
33
+ Requires-Dist: structlog==25.*,>=21.5
33
34
  Requires-Dist: websocket-client==1.*,>=1.2
34
35
  Description-Content-Type: text/markdown
35
36
 
@@ -0,0 +1,10 @@
1
+ bitvavo_api_upgraded/__init__.py,sha256=CSK4JninN6nxMUqoT-S_Vl9UJc4NOqwfbbZf-Qnvpo4,222
2
+ bitvavo_api_upgraded/bitvavo.py,sha256=s7l-cAl0FteBrm5iF-gnM_U9_-Yds9lpn5pN6f0oaZU,125981
3
+ bitvavo_api_upgraded/helper_funcs.py,sha256=4oBdQ1xB-C2XkQTmN-refzIzWfO-IUowDSWhOSFdCRU,3212
4
+ bitvavo_api_upgraded/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ bitvavo_api_upgraded/settings.py,sha256=ZH2sR9iUyOC_lSaqmT50wERngUuobvu8d0TLiYN5nTg,2266
6
+ bitvavo_api_upgraded/type_aliases.py,sha256=NAnMSk5n6SaEIvHFeSMKnXOxfOwnbFuEnRKaAXlcmYw,932
7
+ bitvavo_api_upgraded-1.17.2.dist-info/METADATA,sha256=U_5w2WGTB4xykCwIgh3KtcfsVzsYDS3NZWlHwVRz1Tk,11547
8
+ bitvavo_api_upgraded-1.17.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ bitvavo_api_upgraded-1.17.2.dist-info/licenses/LICENSE.txt,sha256=hiFyor_njVlzVblnb-78mzx1Um3CGvuFxEH3YR735rc,744
10
+ bitvavo_api_upgraded-1.17.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.26.3
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,10 +0,0 @@
1
- bitvavo_api_upgraded/__init__.py,sha256=IS9Ci2orRtYKHyFNXq_9qk9bB6zt4KU4tPbQAxkkCUM,72
2
- bitvavo_api_upgraded/bitvavo.py,sha256=-AgVq4hXHEsuQhCLEweyjJ_DhAPwbwtCeCPSNeweisA,125942
3
- bitvavo_api_upgraded/helper_funcs.py,sha256=4oBdQ1xB-C2XkQTmN-refzIzWfO-IUowDSWhOSFdCRU,3212
4
- bitvavo_api_upgraded/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- bitvavo_api_upgraded/settings.py,sha256=MalcO2buJso4NZktDRGGSZ7poF593ceb66zrmX-8dc4,1903
6
- bitvavo_api_upgraded/type_aliases.py,sha256=NAnMSk5n6SaEIvHFeSMKnXOxfOwnbFuEnRKaAXlcmYw,932
7
- bitvavo_api_upgraded-1.17.0.dist-info/METADATA,sha256=Csu9ntgiu7tVaEvKXJmBjrFEMAxlVfHhIHRlvYwflIo,11519
8
- bitvavo_api_upgraded-1.17.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
9
- bitvavo_api_upgraded-1.17.0.dist-info/licenses/LICENSE.txt,sha256=hiFyor_njVlzVblnb-78mzx1Um3CGvuFxEH3YR735rc,744
10
- bitvavo_api_upgraded-1.17.0.dist-info/RECORD,,