bitvavo-api-upgraded 1.16.0__tar.gz → 1.17.0__tar.gz

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.
Files changed (29) hide show
  1. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/.gitignore +6 -5
  2. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/CHANGELOG.md +46 -2
  3. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/LICENSE.txt +2 -2
  4. bitvavo_api_upgraded-1.17.0/PKG-INFO +319 -0
  5. bitvavo_api_upgraded-1.17.0/README.md +284 -0
  6. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/README.pypi.md +5 -3
  7. bitvavo_api_upgraded-1.17.0/docs/assets/bitvavo-mark-square-blue.svg +5 -0
  8. bitvavo_api_upgraded-1.17.0/docs/rest.md +72 -0
  9. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/pyproject.toml +19 -8
  10. bitvavo_api_upgraded-1.17.0/src/bitvavo_api_upgraded/__init__.py +3 -0
  11. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/src/bitvavo_api_upgraded/bitvavo.py +80 -34
  12. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/src/bitvavo_api_upgraded/helper_funcs.py +1 -1
  13. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/src/bitvavo_api_upgraded/type_aliases.py +3 -1
  14. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/tests/conftest.py +11 -1
  15. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/tests/test_bitvavo.py +65 -5
  16. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/tox.ini +1 -1
  17. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/uv.lock +1 -1
  18. bitvavo_api_upgraded-1.16.0/PKG-INFO +0 -2429
  19. bitvavo_api_upgraded-1.16.0/README.md +0 -2394
  20. bitvavo_api_upgraded-1.16.0/tests/__init__.py +0 -0
  21. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/.github/README.md +0 -0
  22. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/.github/workflows/release.yml +0 -0
  23. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/.pre-commit-config.yaml +0 -0
  24. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/.python-version +0 -0
  25. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/scripts/bootstrap.sh +0 -0
  26. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/src/bitvavo_api_upgraded/py.typed +0 -0
  27. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/src/bitvavo_api_upgraded/settings.py +0 -0
  28. {bitvavo_api_upgraded-1.16.0/src/bitvavo_api_upgraded → bitvavo_api_upgraded-1.17.0/tests}/__init__.py +0 -0
  29. {bitvavo_api_upgraded-1.16.0 → bitvavo_api_upgraded-1.17.0}/tests/test_helper_funcs.py +0 -0
@@ -1,11 +1,12 @@
1
1
  /*
2
2
 
3
3
  # dirs
4
- !.github
5
- !requirements
6
- !scripts
7
- !src
8
- !tests
4
+ !.github/
5
+ !requirements/
6
+ !scripts/
7
+ !src/
8
+ !tests/
9
+ !docs/
9
10
 
10
11
  # files
11
12
  !.bumpversion.cfg
@@ -1,9 +1,53 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.17.0 - 2024-11-24
4
+
5
+ Integrate all changes from Bitvavo's `v1.1.1` to `v1.4.2` lib versions,
6
+ basically catching up their changes with our code. The reason for choosing
7
+ `v1.1.1` as starting point, is because I'm not sure if I missed anything,
8
+ because if I follow the timeline on PyPI is that I should pick `v1.2.2`, but if
9
+ I look at my commit history, I should choose an older point. Oh well, it's only
10
+ a little bit more work.
11
+
12
+ I used [this Github
13
+ link](https://github.com/bitvavo/python-bitvavo-api/compare/v1.1.1...v1.4.2) to
14
+ compare their versions.
15
+
16
+ ### Added
17
+
18
+ - `fees()` call. This was added to the Python SDK in early 2024.
19
+ - `_default(value, fallback)` function, which ensures a `fallback` is returned,
20
+ if `value` is `None`. This ensures sane values will always be available.
21
+ - `strintdict` type, as I had a bunch of `dict` types copied.
22
+
23
+ ### Changed
24
+
25
+ - you can now do `from bitvavo_api_upgraded import Bitvavo`, instead of `from
26
+ bitvavo_api_upgraded.bitvavo import Bitvavo`, which always felt annoying. You
27
+ can still use the old way; no worries.
28
+ - lowercased the http headers like `Bitvavo-Ratelimit-Remaining`, because
29
+ Bitvavo updated the API, which broke this code. This should probably fix the
30
+ issues of older versions of this lib going over the rate limit. 😅
31
+ - `LICENSE.txt`'s year got updated
32
+ - in `README.md`, below my text, I've replaced their old README with their
33
+ current one.
34
+ - fixed coverage report; I switched to `pytest-cov`, from `coverage.py`
35
+ eventhough `pytest-cov` still uses `coverage.py`, but the output was messed up
36
+ (it also covered `tests/`, wich was unintentional)
37
+
38
+ ### Unchanged
39
+
40
+ Normally I don't add this chapter, but I'm moving changes from Bitvavo's repo to
41
+ here, so it's good I'll track this stuff for later.
42
+
43
+ - I did NOT add the `name` var to `__init__.py`, because I'm pretty sure they
44
+ added it for their build process, but since I'm using `uv` I don't need that.
45
+ - Did not add `self.timeout`, as I use `self.ACCESSWINDOW / 1000` instead.
46
+
3
47
  ## v1.16.0 - 2024-11-18
4
48
 
5
- Quite a few changes, most aimed at the maintenance of this project, but all changes are superficial - the functional
6
- code has not changed.
49
+ Quite a few changes, most aimed at the maintenance of this project, but all
50
+ changes are superficial - the functional code has not changed.
7
51
 
8
52
  ### Added
9
53
 
@@ -1,6 +1,6 @@
1
1
  ISC License
2
2
 
3
- Copyright (c) 2018, Bitvavo
3
+ Copyright (c) 2024, Bitvavo B.V.
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
@@ -12,4 +12,4 @@ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
12
  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
13
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
14
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,319 @@
1
+ Metadata-Version: 2.3
2
+ Name: bitvavo-api-upgraded
3
+ Version: 1.17.0
4
+ Summary: A unit-tested fork of the Bitvavo API
5
+ Project-URL: homepage, https://github.com/Thaumatorium/bitvavo-api-upgraded
6
+ Project-URL: repository, https://github.com/Thaumatorium/bitvavo-api-upgraded
7
+ Project-URL: changelog, https://github.com/Thaumatorium/bitvavo-api-upgraded/blob/master/CHANGELOG.md
8
+ Author: Bitvavo BV (original code)
9
+ Author-email: NostraDavid <55331731+NostraDavid@users.noreply.github.com>
10
+ Maintainer-email: NostraDavid <55331731+NostraDavid@users.noreply.github.com>
11
+ License: ISC License
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Environment :: Console
14
+ Classifier: Framework :: Pytest
15
+ Classifier: Framework :: tox
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Financial and Insurance Industry
18
+ Classifier: License :: OSI Approved :: ISC License (ISCL)
19
+ Classifier: Operating System :: MacOS :: MacOS X
20
+ Classifier: Operating System :: Microsoft :: Windows
21
+ Classifier: Operating System :: POSIX
22
+ Classifier: Programming Language :: Python
23
+ Classifier: Programming Language :: Python :: 3.9
24
+ Classifier: Programming Language :: Python :: 3.10
25
+ Classifier: Programming Language :: Python :: 3.11
26
+ Classifier: Programming Language :: Python :: 3.12
27
+ Classifier: Programming Language :: Python :: 3.13
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.9
30
+ Requires-Dist: python-decouple==3.*,>=3.5
31
+ Requires-Dist: requests==2.*,>=2.26
32
+ Requires-Dist: structlog==24.*,>=21.5
33
+ Requires-Dist: websocket-client==1.*,>=1.2
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Bitvavo API (upgraded)
37
+
38
+ ## Userguide
39
+
40
+ `pip install bitvavo_api_upgraded`
41
+
42
+ Works the same as the official API lib, but I have:
43
+
44
+ - typing for _all_ functions and classes
45
+ - unit tests (I already found three bugs that I fixed, because the original code
46
+ wasn't tested, at all)
47
+ - a changelog, so you can track of the changes that I make
48
+ - compatible with Python 3.7 and newer ([3.6 isn't supported as of
49
+ 2021-12-23](https://endoflife.date/python))
50
+
51
+ ## Devguide
52
+
53
+ ```shell
54
+ echo "install development requirements"
55
+ uv sync
56
+ echo "run tox, a program that creates separate environments for different python versions, for testing purposes (among other things)"
57
+ uv run tox
58
+ ```
59
+
60
+ ### Semantic Versioning (SemVer)
61
+
62
+ I'm using semantic versioning, which means that changes mean this:
63
+
64
+ 1. MAJOR version when you make incompatible API changes,
65
+ 1. MINOR version when you add functionality in a backwards compatible manner,
66
+ and
67
+ 1. PATCH version when you make backwards compatible bug fixes.
68
+
69
+ ### Versioning
70
+
71
+ Copy the following block to CHANGELOG.md and add all information since last
72
+ version bump
73
+
74
+ ```markdown
75
+ ## $UNRELEASED
76
+
77
+ ### Added
78
+
79
+ ...
80
+
81
+ ### Changed
82
+
83
+ ...
84
+
85
+ ### Removed
86
+
87
+ ...
88
+ ```
89
+
90
+ Commit those changes.
91
+
92
+ After that, run `bump-my-version bump (major|minor|patch)` to automatically
93
+ replace `$UNRELEASED` with the new version number, and also automatically tag
94
+ and commit (with tag) to release a new version via the Github workflow.
95
+
96
+ ## py.typed
97
+
98
+ Perhaps a curious file, but it simply exists to let `mypy` know that the code is
99
+ typed: [Don't forget `py.typed` for your typed Python package
100
+ ](https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/)
101
+
102
+ ## Last note
103
+
104
+ _below this line is the old README.md_
105
+
106
+ ---
107
+
108
+ # Bitvavo SDK for Python
109
+
110
+ Crypto starts with Bitvavo. You use Bitvavo SDK for Python to buy, sell, and
111
+ store over 200 digital assets on Bitvavo from inside your app.
112
+
113
+ To trade and execute your advanced trading strategies, Bitvavo SDK for Python is
114
+ a wrapper that enables you to easily call every endpoint in [Bitvavo
115
+ API](https://docs.bitvavo.com/).
116
+
117
+ - [Prerequisites](#prerequisites) - what you need to start developing with
118
+ Bitvavo SDK for Python
119
+ - [Get started](#get-started) - rapidly create an app and start trading with
120
+ Bitvavo
121
+ - [About the SDK](#about-the-sdk) - general information about Bitvavo SDK for
122
+ Python
123
+ - [API reference](https://docs.bitvavo.com/) - information on the specifics of
124
+ every parameter
125
+
126
+ This page shows you how to use Bitvavo SDK for Python with WebSockets. For REST,
127
+ see the [REST readme](docs/rest.md).
128
+
129
+ ## Prerequisites
130
+
131
+ To start programming with Bitvavo SDK for Python you need:
132
+
133
+ - [Python3](https://www.python.org/downloads/) installed on your development
134
+ environment
135
+
136
+ If you are working on macOS, ensure that you have installed SSH certificates:
137
+
138
+ ```terminal
139
+ open /Applications/Python\ 3.12/Install\ Certificates.command
140
+ open /Applications/Python\ 3.12/Update\ Shell\ Profile.command
141
+ ```
142
+
143
+ - A Python app. Use your favorite IDE, or run from the command line
144
+ - An [API key and
145
+ secret](https://support.bitvavo.com/hc/en-us/articles/4405059841809)
146
+ associated with your Bitvavo account
147
+
148
+ You control the actions your app can do using the rights you assign to the API
149
+ key. Possible rights are:
150
+
151
+ - **View**: retrieve information about your balance, account, deposit and
152
+ withdrawals
153
+ - **Trade**: place, update, view and cancel orders
154
+ - **Withdraw**: withdraw funds
155
+
156
+ Best practice is to not grant this privilege, withdrawals using the API do
157
+ not require 2FA and e-mail confirmation.
158
+
159
+ ## Get started
160
+
161
+ Want to quickly make a trading app? Here you go:
162
+
163
+ 1. **Install Bitvavo SDK for Python**
164
+
165
+ In your Python app, add [Bitvavo SDK for
166
+ Python](https://github.com/bitvavo/python-bitvavo-api) from
167
+ [pypi.org](https://pypi.org/project/python-bitvavo-api/):
168
+
169
+ ```shell
170
+ python -m pip install python_bitvavo_api
171
+ ```
172
+
173
+ If you installed from `test.pypi.com`, update the requests library: `pip
174
+ install --upgrade requests`.
175
+
176
+ 1. **Create a simple Bitvavo implementation**
177
+
178
+ Add the following code to a new file in your app:
179
+
180
+ ```python
181
+ from python_bitvavo_api.bitvavo import Bitvavo
182
+ import json
183
+ import time
184
+
185
+ # Use this class to connect to Bitvavo and make your first calls.
186
+ # Add trading strategies to implement your business logic.
187
+ class BitvavoImplementation:
188
+ api_key = "<Replace with your your API key from Bitvavo Dashboard>"
189
+ api_secret = "<Replace with your API secret from Bitvavo Dashboard>"
190
+ bitvavo_engine = None
191
+ bitvavo_socket = None
192
+
193
+ # Connect securely to Bitvavo, create the WebSocket and error callbacks.
194
+ def __init__(self):
195
+ self.bitvavo_engine = Bitvavo({
196
+ 'APIKEY': self.api_key,
197
+ 'APISECRET': self.api_secret
198
+ })
199
+ self.bitvavo_socket = self.bitvavo_engine.newWebsocket()
200
+ self.bitvavo_socket.setErrorCallback(self.error_callback)
201
+
202
+ # Handle errors.
203
+ def error_callback(self, error):
204
+ print("Add your error message.")
205
+ #print("Errors:", json.dumps(error, indent=2))
206
+
207
+ # Retrieve the data you need from Bitvavo in order to implement your
208
+ # trading logic. Use multiple workflows to return data to your
209
+ # callbacks.
210
+ def a_trading_strategy(self):
211
+ self.bitvavo_socket.ticker24h({}, self.a_trading_strategy_callback)
212
+
213
+ # In your app you analyse data returned by the trading strategy, then make
214
+ # calls to Bitvavo to respond to market conditions.
215
+ def a_trading_strategy_callback(self, response):
216
+ # Iterate through the markets
217
+ for market in response:
218
+
219
+ match market["market"]:
220
+ case "ZRX-EUR":
221
+ print("Eureka, the latest bid for ZRX-EUR is: ", market["bid"] )
222
+ # Implement calculations for your trading logic.
223
+ # If they are positive, place an order: For example:
224
+ # self.bitvavo_socket.placeOrder("ZRX-EUR",
225
+ # 'buy',
226
+ # 'limit',
227
+ # { 'amount': '1', 'price': '00001' },
228
+ # self.order_placed_callback)
229
+ case "a different market":
230
+ print("do something else")
231
+ case _:
232
+ print("Not this one: ", market["market"])
233
+
234
+
235
+
236
+ def order_placed_callback(self, response):
237
+ # The order return parameters explain the quote and the fees for this trade.
238
+ print("Order placed:", json.dumps(response, indent=2))
239
+ # Add your business logic.
240
+
241
+
242
+ # Sockets are fast, but asynchronous. Keep the socket open while you are
243
+ # trading.
244
+ def wait_and_close(self):
245
+ # Bitvavo uses a weight based rate limiting system. Your app is limited to 1000 weight points per IP or
246
+ # API key per minute. The rate weighting for each endpoint is supplied in Bitvavo API documentation.
247
+ # This call returns the amount of points left. If you make more requests than permitted by the weight limit,
248
+ # your IP or API key is banned.
249
+ limit = self.bitvavo_engine.getRemainingLimit()
250
+ try:
251
+ while (limit > 0):
252
+ time.sleep(0.5)
253
+ limit = self.bitvavo_engine.getRemainingLimit()
254
+ except KeyboardInterrupt:
255
+ self.bitvavo_socket.closeSocket()
256
+
257
+
258
+ # Shall I re-explain main? Naaaaaaaaaa.
259
+ if __name__ == '__main__':
260
+ bvavo = BitvavoImplementation()
261
+ bvavo.a_trading_strategy()
262
+ bvavo.wait_and_close()
263
+ ```
264
+
265
+ 1. **Add security information**
266
+
267
+ You must supply your security information to trade on Bitvavo and see your
268
+ account information using the authenticate methods. Replace the values of
269
+ `api_key` and `api_secret` with your credentials from [Bitvavo
270
+ Dashboard](https://account.bitvavo.com/user/api).
271
+
272
+ You can retrieve public information such as available markets, assets and
273
+ current market without supplying your key and secret. However,
274
+ unauthenticated calls have lower rate limits based on your IP address, and
275
+ your account is blocked for longer if you exceed your limit.
276
+
277
+ 1. **Run your app**
278
+
279
+ - Command line warriors: `python3 <filename>`.
280
+ - IDE heroes: press the big green button.
281
+
282
+ Your app connects to Bitvavo and returns a list the latest trade price for each
283
+ market. You use this data to implement your trading logic.
284
+
285
+ ## About the SDK
286
+
287
+ This section explains global concepts about Bitvavo SDK for Python.
288
+
289
+ ### Rate limit
290
+
291
+ Bitvavo uses a weight based rate limiting system. Your app is limited to 1000
292
+ weight points per IP or API key per minute. When you make a call to Bitvavo API,
293
+ your remaining weight points are returned in the header of each REST request.
294
+
295
+ Websocket methods do not return your returning weight points, you track your
296
+ remaining weight points with a call to:
297
+
298
+ ```python
299
+ limit = bitvavo.getRemainingLimit()
300
+ ```
301
+
302
+ If you make more requests than permitted by the weight limit, your IP or API key
303
+ is banned.
304
+
305
+ The rate weighting for each endpoint is supplied in the [Bitvavo API
306
+ documentation](https://docs.bitvavo.com/).
307
+
308
+ ### Requests
309
+
310
+ For all methods, required parameters are passed as separate values, optional
311
+ parameters are passed as a dictionary. Return parameters are in dictionary
312
+ format: `response['<key>'] = '<value>'`. However, as a limit order requires more
313
+ information than a market order, some optional parameters are required when you
314
+ place an order.
315
+
316
+ ### Security
317
+
318
+ You must set your API key and secret for authenticated endpoints, public
319
+ endpoints do not require authentication.
@@ -0,0 +1,284 @@
1
+ # Bitvavo API (upgraded)
2
+
3
+ ## Userguide
4
+
5
+ `pip install bitvavo_api_upgraded`
6
+
7
+ Works the same as the official API lib, but I have:
8
+
9
+ - typing for _all_ functions and classes
10
+ - unit tests (I already found three bugs that I fixed, because the original code
11
+ wasn't tested, at all)
12
+ - a changelog, so you can track of the changes that I make
13
+ - compatible with Python 3.7 and newer ([3.6 isn't supported as of
14
+ 2021-12-23](https://endoflife.date/python))
15
+
16
+ ## Devguide
17
+
18
+ ```shell
19
+ echo "install development requirements"
20
+ uv sync
21
+ echo "run tox, a program that creates separate environments for different python versions, for testing purposes (among other things)"
22
+ uv run tox
23
+ ```
24
+
25
+ ### Semantic Versioning (SemVer)
26
+
27
+ I'm using semantic versioning, which means that changes mean this:
28
+
29
+ 1. MAJOR version when you make incompatible API changes,
30
+ 1. MINOR version when you add functionality in a backwards compatible manner,
31
+ and
32
+ 1. PATCH version when you make backwards compatible bug fixes.
33
+
34
+ ### Versioning
35
+
36
+ Copy the following block to CHANGELOG.md and add all information since last
37
+ version bump
38
+
39
+ ```markdown
40
+ ## $UNRELEASED
41
+
42
+ ### Added
43
+
44
+ ...
45
+
46
+ ### Changed
47
+
48
+ ...
49
+
50
+ ### Removed
51
+
52
+ ...
53
+ ```
54
+
55
+ Commit those changes.
56
+
57
+ After that, run `bump-my-version bump (major|minor|patch)` to automatically
58
+ replace `$UNRELEASED` with the new version number, and also automatically tag
59
+ and commit (with tag) to release a new version via the Github workflow.
60
+
61
+ ## py.typed
62
+
63
+ Perhaps a curious file, but it simply exists to let `mypy` know that the code is
64
+ typed: [Don't forget `py.typed` for your typed Python package
65
+ ](https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/)
66
+
67
+ ## Last note
68
+
69
+ _below this line is the old README.md_
70
+
71
+ ---
72
+
73
+ # Bitvavo SDK for Python
74
+
75
+ Crypto starts with Bitvavo. You use Bitvavo SDK for Python to buy, sell, and
76
+ store over 200 digital assets on Bitvavo from inside your app.
77
+
78
+ To trade and execute your advanced trading strategies, Bitvavo SDK for Python is
79
+ a wrapper that enables you to easily call every endpoint in [Bitvavo
80
+ API](https://docs.bitvavo.com/).
81
+
82
+ - [Prerequisites](#prerequisites) - what you need to start developing with
83
+ Bitvavo SDK for Python
84
+ - [Get started](#get-started) - rapidly create an app and start trading with
85
+ Bitvavo
86
+ - [About the SDK](#about-the-sdk) - general information about Bitvavo SDK for
87
+ Python
88
+ - [API reference](https://docs.bitvavo.com/) - information on the specifics of
89
+ every parameter
90
+
91
+ This page shows you how to use Bitvavo SDK for Python with WebSockets. For REST,
92
+ see the [REST readme](docs/rest.md).
93
+
94
+ ## Prerequisites
95
+
96
+ To start programming with Bitvavo SDK for Python you need:
97
+
98
+ - [Python3](https://www.python.org/downloads/) installed on your development
99
+ environment
100
+
101
+ If you are working on macOS, ensure that you have installed SSH certificates:
102
+
103
+ ```terminal
104
+ open /Applications/Python\ 3.12/Install\ Certificates.command
105
+ open /Applications/Python\ 3.12/Update\ Shell\ Profile.command
106
+ ```
107
+
108
+ - A Python app. Use your favorite IDE, or run from the command line
109
+ - An [API key and
110
+ secret](https://support.bitvavo.com/hc/en-us/articles/4405059841809)
111
+ associated with your Bitvavo account
112
+
113
+ You control the actions your app can do using the rights you assign to the API
114
+ key. Possible rights are:
115
+
116
+ - **View**: retrieve information about your balance, account, deposit and
117
+ withdrawals
118
+ - **Trade**: place, update, view and cancel orders
119
+ - **Withdraw**: withdraw funds
120
+
121
+ Best practice is to not grant this privilege, withdrawals using the API do
122
+ not require 2FA and e-mail confirmation.
123
+
124
+ ## Get started
125
+
126
+ Want to quickly make a trading app? Here you go:
127
+
128
+ 1. **Install Bitvavo SDK for Python**
129
+
130
+ In your Python app, add [Bitvavo SDK for
131
+ Python](https://github.com/bitvavo/python-bitvavo-api) from
132
+ [pypi.org](https://pypi.org/project/python-bitvavo-api/):
133
+
134
+ ```shell
135
+ python -m pip install python_bitvavo_api
136
+ ```
137
+
138
+ If you installed from `test.pypi.com`, update the requests library: `pip
139
+ install --upgrade requests`.
140
+
141
+ 1. **Create a simple Bitvavo implementation**
142
+
143
+ Add the following code to a new file in your app:
144
+
145
+ ```python
146
+ from python_bitvavo_api.bitvavo import Bitvavo
147
+ import json
148
+ import time
149
+
150
+ # Use this class to connect to Bitvavo and make your first calls.
151
+ # Add trading strategies to implement your business logic.
152
+ class BitvavoImplementation:
153
+ api_key = "<Replace with your your API key from Bitvavo Dashboard>"
154
+ api_secret = "<Replace with your API secret from Bitvavo Dashboard>"
155
+ bitvavo_engine = None
156
+ bitvavo_socket = None
157
+
158
+ # Connect securely to Bitvavo, create the WebSocket and error callbacks.
159
+ def __init__(self):
160
+ self.bitvavo_engine = Bitvavo({
161
+ 'APIKEY': self.api_key,
162
+ 'APISECRET': self.api_secret
163
+ })
164
+ self.bitvavo_socket = self.bitvavo_engine.newWebsocket()
165
+ self.bitvavo_socket.setErrorCallback(self.error_callback)
166
+
167
+ # Handle errors.
168
+ def error_callback(self, error):
169
+ print("Add your error message.")
170
+ #print("Errors:", json.dumps(error, indent=2))
171
+
172
+ # Retrieve the data you need from Bitvavo in order to implement your
173
+ # trading logic. Use multiple workflows to return data to your
174
+ # callbacks.
175
+ def a_trading_strategy(self):
176
+ self.bitvavo_socket.ticker24h({}, self.a_trading_strategy_callback)
177
+
178
+ # In your app you analyse data returned by the trading strategy, then make
179
+ # calls to Bitvavo to respond to market conditions.
180
+ def a_trading_strategy_callback(self, response):
181
+ # Iterate through the markets
182
+ for market in response:
183
+
184
+ match market["market"]:
185
+ case "ZRX-EUR":
186
+ print("Eureka, the latest bid for ZRX-EUR is: ", market["bid"] )
187
+ # Implement calculations for your trading logic.
188
+ # If they are positive, place an order: For example:
189
+ # self.bitvavo_socket.placeOrder("ZRX-EUR",
190
+ # 'buy',
191
+ # 'limit',
192
+ # { 'amount': '1', 'price': '00001' },
193
+ # self.order_placed_callback)
194
+ case "a different market":
195
+ print("do something else")
196
+ case _:
197
+ print("Not this one: ", market["market"])
198
+
199
+
200
+
201
+ def order_placed_callback(self, response):
202
+ # The order return parameters explain the quote and the fees for this trade.
203
+ print("Order placed:", json.dumps(response, indent=2))
204
+ # Add your business logic.
205
+
206
+
207
+ # Sockets are fast, but asynchronous. Keep the socket open while you are
208
+ # trading.
209
+ def wait_and_close(self):
210
+ # Bitvavo uses a weight based rate limiting system. Your app is limited to 1000 weight points per IP or
211
+ # API key per minute. The rate weighting for each endpoint is supplied in Bitvavo API documentation.
212
+ # This call returns the amount of points left. If you make more requests than permitted by the weight limit,
213
+ # your IP or API key is banned.
214
+ limit = self.bitvavo_engine.getRemainingLimit()
215
+ try:
216
+ while (limit > 0):
217
+ time.sleep(0.5)
218
+ limit = self.bitvavo_engine.getRemainingLimit()
219
+ except KeyboardInterrupt:
220
+ self.bitvavo_socket.closeSocket()
221
+
222
+
223
+ # Shall I re-explain main? Naaaaaaaaaa.
224
+ if __name__ == '__main__':
225
+ bvavo = BitvavoImplementation()
226
+ bvavo.a_trading_strategy()
227
+ bvavo.wait_and_close()
228
+ ```
229
+
230
+ 1. **Add security information**
231
+
232
+ You must supply your security information to trade on Bitvavo and see your
233
+ account information using the authenticate methods. Replace the values of
234
+ `api_key` and `api_secret` with your credentials from [Bitvavo
235
+ Dashboard](https://account.bitvavo.com/user/api).
236
+
237
+ You can retrieve public information such as available markets, assets and
238
+ current market without supplying your key and secret. However,
239
+ unauthenticated calls have lower rate limits based on your IP address, and
240
+ your account is blocked for longer if you exceed your limit.
241
+
242
+ 1. **Run your app**
243
+
244
+ - Command line warriors: `python3 <filename>`.
245
+ - IDE heroes: press the big green button.
246
+
247
+ Your app connects to Bitvavo and returns a list the latest trade price for each
248
+ market. You use this data to implement your trading logic.
249
+
250
+ ## About the SDK
251
+
252
+ This section explains global concepts about Bitvavo SDK for Python.
253
+
254
+ ### Rate limit
255
+
256
+ Bitvavo uses a weight based rate limiting system. Your app is limited to 1000
257
+ weight points per IP or API key per minute. When you make a call to Bitvavo API,
258
+ your remaining weight points are returned in the header of each REST request.
259
+
260
+ Websocket methods do not return your returning weight points, you track your
261
+ remaining weight points with a call to:
262
+
263
+ ```python
264
+ limit = bitvavo.getRemainingLimit()
265
+ ```
266
+
267
+ If you make more requests than permitted by the weight limit, your IP or API key
268
+ is banned.
269
+
270
+ The rate weighting for each endpoint is supplied in the [Bitvavo API
271
+ documentation](https://docs.bitvavo.com/).
272
+
273
+ ### Requests
274
+
275
+ For all methods, required parameters are passed as separate values, optional
276
+ parameters are passed as a dictionary. Return parameters are in dictionary
277
+ format: `response['<key>'] = '<value>'`. However, as a limit order requires more
278
+ information than a market order, some optional parameters are required when you
279
+ place an order.
280
+
281
+ ### Security
282
+
283
+ You must set your API key and secret for authenticated endpoints, public
284
+ endpoints do not require authentication.