bitvavo-api-upgraded 2.0.0__py3-none-any.whl → 2.3.0__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.
- bitvavo_api_upgraded/__init__.py +2 -0
- bitvavo_api_upgraded/bitvavo.py +1087 -182
- bitvavo_api_upgraded/dataframe_utils.py +175 -0
- bitvavo_api_upgraded/settings.py +81 -16
- bitvavo_api_upgraded/type_aliases.py +34 -0
- {bitvavo_api_upgraded-2.0.0.dist-info → bitvavo_api_upgraded-2.3.0.dist-info}/METADATA +363 -101
- bitvavo_api_upgraded-2.3.0.dist-info/RECORD +10 -0
- {bitvavo_api_upgraded-2.0.0.dist-info → bitvavo_api_upgraded-2.3.0.dist-info}/WHEEL +1 -1
- bitvavo_api_upgraded-2.0.0.dist-info/RECORD +0 -9
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: bitvavo-api-upgraded
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.3.0
|
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>
|
@@ -8,7 +8,6 @@ License: ISC License
|
|
8
8
|
Classifier: Development Status :: 5 - Production/Stable
|
9
9
|
Classifier: Environment :: Console
|
10
10
|
Classifier: Framework :: Pytest
|
11
|
-
Classifier: Framework :: tox
|
12
11
|
Classifier: Intended Audience :: Developers
|
13
12
|
Classifier: Intended Audience :: Financial and Insurance Industry
|
14
13
|
Classifier: License :: OSI Approved :: ISC License (ISCL)
|
@@ -22,16 +21,40 @@ Classifier: Programming Language :: Python :: 3.12
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.13
|
23
22
|
Classifier: Programming Language :: Python
|
24
23
|
Classifier: Typing :: Typed
|
24
|
+
Requires-Dist: deprecated>=1.2.18
|
25
25
|
Requires-Dist: pydantic-settings==2.*,>=2.6
|
26
26
|
Requires-Dist: requests==2.*,>=2.26
|
27
27
|
Requires-Dist: structlog>=21.5,==25.*
|
28
28
|
Requires-Dist: websocket-client==1.*,>=1.2
|
29
|
+
Requires-Dist: cudf-cu12>=24.0.0 ; extra == 'cudf'
|
30
|
+
Requires-Dist: narwhals>=2.0.0 ; extra == 'cudf'
|
31
|
+
Requires-Dist: narwhals[dask]>=2.0.0 ; extra == 'dask'
|
32
|
+
Requires-Dist: narwhals[duckdb]>=2.0.0 ; extra == 'duckdb'
|
33
|
+
Requires-Dist: narwhals[ibis]>=2.0.0 ; extra == 'ibis'
|
34
|
+
Requires-Dist: narwhals[modin]>=2.0.0 ; extra == 'modin'
|
35
|
+
Requires-Dist: narwhals[pandas]>=2.0.0 ; extra == 'pandas'
|
36
|
+
Requires-Dist: narwhals[polars]>=2.0.0 ; extra == 'polars'
|
37
|
+
Requires-Dist: narwhals[pyarrow]>=2.0.0 ; extra == 'pyarrow'
|
38
|
+
Requires-Dist: narwhals[pyspark]>=2.0.0 ; extra == 'pyspark'
|
39
|
+
Requires-Dist: narwhals[pyspark-connect]>=2.0.0 ; extra == 'pyspark-connect'
|
40
|
+
Requires-Dist: narwhals[sqlframe]>=2.0.0 ; extra == 'sqlframe'
|
29
41
|
Maintainer: NostraDavid
|
30
42
|
Maintainer-email: NostraDavid <55331731+NostraDavid@users.noreply.github.com>
|
31
43
|
Requires-Python: >=3.9
|
32
44
|
Project-URL: changelog, https://github.com/Thaumatorium/bitvavo-api-upgraded/blob/master/CHANGELOG.md
|
33
45
|
Project-URL: homepage, https://github.com/Thaumatorium/bitvavo-api-upgraded
|
34
46
|
Project-URL: repository, https://github.com/Thaumatorium/bitvavo-api-upgraded
|
47
|
+
Provides-Extra: cudf
|
48
|
+
Provides-Extra: dask
|
49
|
+
Provides-Extra: duckdb
|
50
|
+
Provides-Extra: ibis
|
51
|
+
Provides-Extra: modin
|
52
|
+
Provides-Extra: pandas
|
53
|
+
Provides-Extra: polars
|
54
|
+
Provides-Extra: pyarrow
|
55
|
+
Provides-Extra: pyspark
|
56
|
+
Provides-Extra: pyspark-connect
|
57
|
+
Provides-Extra: sqlframe
|
35
58
|
Description-Content-Type: text/markdown
|
36
59
|
|
37
60
|
# Bitvavo API (upgraded)
|
@@ -44,6 +67,46 @@ A **typed, tested, and enhanced** Python wrapper for the Bitvavo cryptocurrency
|
|
44
67
|
pip install bitvavo_api_upgraded
|
45
68
|
```
|
46
69
|
|
70
|
+
### Optional Dataframe Support
|
71
|
+
|
72
|
+
This package supports multiple dataframe libraries via [Narwhals](https://narwhals-dev.github.io/narwhals/), providing a unified interface across:
|
73
|
+
|
74
|
+
- **pandas** - The most popular Python data analysis library
|
75
|
+
- **polars** - Fast, memory-efficient DataFrames in Rust
|
76
|
+
- **cuDF** - GPU-accelerated DataFrames (NVIDIA RAPIDS)
|
77
|
+
- **modin** - Distributed pandas on Ray/Dask
|
78
|
+
- **PyArrow** - In-memory columnar data format
|
79
|
+
- **Dask** - Parallel computing with task scheduling
|
80
|
+
- **DuckDB** - In-process analytical database
|
81
|
+
- **Ibis** - Portable analytics across backends
|
82
|
+
- **PySpark** - Distributed data processing
|
83
|
+
- **PySpark Connect** - Client for remote Spark clusters
|
84
|
+
- **SQLFrame** - SQL-like operations on DataFrames
|
85
|
+
|
86
|
+
Install with your preferred dataframe library:
|
87
|
+
|
88
|
+
```bash
|
89
|
+
# Basic installation (dict output only)
|
90
|
+
pip install bitvavo_api_upgraded
|
91
|
+
|
92
|
+
# With pandas support
|
93
|
+
pip install bitvavo_api_upgraded[pandas]
|
94
|
+
|
95
|
+
# With polars support
|
96
|
+
pip install bitvavo_api_upgraded[polars]
|
97
|
+
|
98
|
+
# With multiple libraries
|
99
|
+
pip install bitvavo_api_upgraded[pandas,polars,pyarrow]
|
100
|
+
|
101
|
+
# With GPU acceleration (cuDF)
|
102
|
+
pip install bitvavo_api_upgraded[cudf]
|
103
|
+
|
104
|
+
# With distributed computing (Dask)
|
105
|
+
pip install bitvavo_api_upgraded[dask]
|
106
|
+
|
107
|
+
# Note: polars-gpu support will be available in a future release
|
108
|
+
```
|
109
|
+
|
47
110
|
Scroll down for detailed usage examples and configuration instructions.
|
48
111
|
|
49
112
|
## What Makes This "Upgraded"?
|
@@ -56,14 +119,19 @@ This wrapper improves upon the official Bitvavo SDK with:
|
|
56
119
|
- 🔄 **Up-to-date API compliance** including MiCA regulatory requirements
|
57
120
|
- 📚 **Enhanced documentation** with examples and clear usage patterns
|
58
121
|
- 🐍 **Modern Python support** (3.9+, dropped EOL versions)
|
122
|
+
- 🔑 **Multi-key & keyless support** for enhanced rate limiting and public access
|
59
123
|
- ⚡ **Better error handling** and rate limiting
|
60
124
|
- 🔧 **Developer-friendly tooling** (ruff, mypy, pre-commit hooks)
|
125
|
+
- 📊 **Unified dataframe support** via Narwhals (pandas, polars, cuDF, modin, PyArrow, Dask, DuckDB, Ibis, PySpark, SQLFrame)
|
61
126
|
|
62
127
|
## Features
|
63
128
|
|
64
129
|
### Full API Coverage
|
65
130
|
|
66
131
|
- ✅ All REST endpoints (public and private)
|
132
|
+
- ✅ **Multiple API key support** with automatic load balancing
|
133
|
+
- ✅ **Keyless access** for public endpoints without authentication
|
134
|
+
- ✅ **Comprehensive dataframe support** via Narwhals (pandas, polars, cuDF, modin, PyArrow, Dask, DuckDB, Ibis, PySpark, and more)
|
67
135
|
- ✅ WebSocket support with reconnection logic
|
68
136
|
- ✅ Rate limiting with automatic throttling
|
69
137
|
- ✅ MiCA compliance reporting endpoints
|
@@ -79,6 +147,7 @@ This wrapper improves upon the official Bitvavo SDK with:
|
|
79
147
|
### Production Ready
|
80
148
|
|
81
149
|
- ✅ Automatic rate limit management
|
150
|
+
- ✅ Multi-key failover support
|
82
151
|
- ✅ Connection retry logic
|
83
152
|
- ✅ Proper error responses
|
84
153
|
- ✅ Memory efficient WebSocket handling
|
@@ -88,8 +157,19 @@ This wrapper improves upon the official Bitvavo SDK with:
|
|
88
157
|
Create a `.env` file in your project root:
|
89
158
|
|
90
159
|
```env
|
160
|
+
# Single API key (traditional)
|
91
161
|
BITVAVO_APIKEY=your-api-key-here
|
92
162
|
BITVAVO_APISECRET=your-api-secret-here
|
163
|
+
|
164
|
+
# Multiple API keys (for rate limiting)
|
165
|
+
# BITVAVO_APIKEYS='[{"key": "key1", "secret": "secret1"}, {"key": "key2", "secret": "secret2"}]'
|
166
|
+
|
167
|
+
# Keyless access (public endpoints only)
|
168
|
+
BITVAVO_PREFER_KEYLESS=true
|
169
|
+
|
170
|
+
# Enhanced settings
|
171
|
+
BITVAVO_API_UPGRADED_DEFAULT_RATE_LIMIT=750
|
172
|
+
BITVAVO_API_UPGRADED_PREFER_KEYLESS=false
|
93
173
|
```
|
94
174
|
|
95
175
|
Then use the settings:
|
@@ -106,6 +186,17 @@ bitvavo = Bitvavo({
|
|
106
186
|
# Option 2: Auto-load from .env
|
107
187
|
settings = BitvavoSettings()
|
108
188
|
bitvavo = Bitvavo(settings.model_dump())
|
189
|
+
|
190
|
+
# Option 3: Multiple API keys
|
191
|
+
bitvavo = Bitvavo({
|
192
|
+
'APIKEYS': [
|
193
|
+
{'key': 'key1', 'secret': 'secret1'},
|
194
|
+
{'key': 'key2', 'secret': 'secret2'}
|
195
|
+
]
|
196
|
+
})
|
197
|
+
|
198
|
+
# Option 4: Keyless (public endpoints only)
|
199
|
+
bitvavo = Bitvavo({'PREFER_KEYLESS': True})
|
109
200
|
```
|
110
201
|
|
111
202
|
## WebSocket Usage
|
@@ -135,6 +226,66 @@ except KeyboardInterrupt:
|
|
135
226
|
ws.closeSocket()
|
136
227
|
```
|
137
228
|
|
229
|
+
## Multi-Key & Keyless Examples
|
230
|
+
|
231
|
+
### Multiple API Keys for Rate Limiting
|
232
|
+
|
233
|
+
```python
|
234
|
+
from bitvavo_api_upgraded import Bitvavo
|
235
|
+
|
236
|
+
# Configure multiple API keys
|
237
|
+
bitvavo = Bitvavo({
|
238
|
+
'APIKEYS': [
|
239
|
+
{'key': 'key1', 'secret': 'secret1'},
|
240
|
+
{'key': 'key2', 'secret': 'secret2'},
|
241
|
+
{'key': 'key3', 'secret': 'secret3'}
|
242
|
+
]
|
243
|
+
})
|
244
|
+
|
245
|
+
# API automatically balances load across keys
|
246
|
+
balance = bitvavo.balance({}) # Uses least-used key
|
247
|
+
orders = bitvavo.getOrders('BTC-EUR', {}) # May use different key
|
248
|
+
trades = bitvavo.getTrades('BTC-EUR', {}) # Automatic failover if rate limit reached
|
249
|
+
```
|
250
|
+
|
251
|
+
### Keyless Access (Public Endpoints)
|
252
|
+
|
253
|
+
```python
|
254
|
+
from bitvavo_api_upgraded import Bitvavo
|
255
|
+
|
256
|
+
# No API keys needed for public data
|
257
|
+
bitvavo = Bitvavo({'PREFER_KEYLESS': True})
|
258
|
+
|
259
|
+
# These work without authentication and don't count against your rate limits
|
260
|
+
markets = bitvavo.markets({})
|
261
|
+
ticker = bitvavo.ticker24h({'market': 'BTC-EUR'})
|
262
|
+
trades = bitvavo.publicTrades('BTC-EUR', {})
|
263
|
+
book = bitvavo.book('BTC-EUR', {})
|
264
|
+
candles = bitvavo.candles('BTC-EUR', '1h', {})
|
265
|
+
|
266
|
+
# Private endpoints will still require authentication
|
267
|
+
# account = bitvavo.account() # This would fail without API keys
|
268
|
+
```
|
269
|
+
|
270
|
+
### Hybrid Configuration
|
271
|
+
|
272
|
+
```python
|
273
|
+
# Combine keyless preference with API keys for optimal performance
|
274
|
+
bitvavo = Bitvavo({
|
275
|
+
'APIKEYS': [
|
276
|
+
{'key': 'key1', 'secret': 'secret1'},
|
277
|
+
{'key': 'key2', 'secret': 'secret2'}
|
278
|
+
],
|
279
|
+
'PREFER_KEYLESS': True # Use keyless for public endpoints, API keys for private
|
280
|
+
})
|
281
|
+
|
282
|
+
# Public calls use keyless (no rate limit impact)
|
283
|
+
markets = bitvavo.markets({})
|
284
|
+
|
285
|
+
# Private calls use API keys with load balancing
|
286
|
+
balance = bitvavo.balance({})
|
287
|
+
```
|
288
|
+
|
138
289
|
## API Examples
|
139
290
|
|
140
291
|
### Public Endpoints (No Authentication)
|
@@ -213,6 +364,74 @@ book_report = bitvavo.reportBook(
|
|
213
364
|
history = bitvavo.accountHistory(options={})
|
214
365
|
```
|
215
366
|
|
367
|
+
### Dataframe Usage
|
368
|
+
|
369
|
+
The library supports multiple dataframe formats for tabular data like market data, asset information, and candlestick data:
|
370
|
+
|
371
|
+
```python
|
372
|
+
from bitvavo_api_upgraded import Bitvavo
|
373
|
+
|
374
|
+
bitvavo = Bitvavo({'APIKEY': 'key', 'APISECRET': 'secret'})
|
375
|
+
|
376
|
+
# Get markets as different dataframe types
|
377
|
+
markets_dict = bitvavo.markets({}, output_format='dict') # Default dict format
|
378
|
+
markets_pandas = bitvavo.markets({}, output_format='pandas') # Pandas DataFrame
|
379
|
+
markets_polars = bitvavo.markets({}, output_format='polars') # Polars DataFrame
|
380
|
+
markets_pyarrow = bitvavo.markets({}, output_format='pyarrow') # PyArrow Table
|
381
|
+
|
382
|
+
# Get assets information as dataframes
|
383
|
+
assets_cudf = bitvavo.assets(
|
384
|
+
{},
|
385
|
+
output_format='cudf' # GPU-accelerated with cuDF
|
386
|
+
)
|
387
|
+
|
388
|
+
# Get candlestick data with distributed processing
|
389
|
+
candles_dask = bitvavo.candles(
|
390
|
+
'BTC-EUR',
|
391
|
+
'1h',
|
392
|
+
{'limit': 100},
|
393
|
+
output_format='dask' # Distributed with Dask
|
394
|
+
)
|
395
|
+
|
396
|
+
# Get public trades with analytical databases
|
397
|
+
trades_duckdb = bitvavo.publicTrades(
|
398
|
+
'BTC-EUR',
|
399
|
+
{'limit': 1000},
|
400
|
+
output_format='duckdb' # DuckDB relation
|
401
|
+
)
|
402
|
+
|
403
|
+
# Account balance with PySpark for big data processing
|
404
|
+
balance_spark = bitvavo.balance(
|
405
|
+
{},
|
406
|
+
output_format='pyspark' # PySpark DataFrame
|
407
|
+
)
|
408
|
+
```
|
409
|
+
|
410
|
+
### Working with Different Libraries
|
411
|
+
|
412
|
+
```python
|
413
|
+
# Pandas example - most common
|
414
|
+
import pandas as pd
|
415
|
+
df = bitvavo.markets({}, output_format='pandas')
|
416
|
+
print(df.describe())
|
417
|
+
df.to_csv('markets.csv')
|
418
|
+
|
419
|
+
# Polars example - faster for large datasets
|
420
|
+
import polars as pl
|
421
|
+
df = bitvavo.candles('BTC-EUR', '1h', {'limit': 1000}, output_format='polars')
|
422
|
+
result = df.filter(pl.col('close') > 50000).select(['timestamp', 'close'])
|
423
|
+
|
424
|
+
# DuckDB example - analytical queries
|
425
|
+
import duckdb
|
426
|
+
rel = bitvavo.publicTrades('BTC-EUR', {'limit': 10000}, output_format='duckdb')
|
427
|
+
high_volume_trades = duckdb.query("SELECT * FROM rel WHERE amount > 1.0")
|
428
|
+
|
429
|
+
# PyArrow example - columnar data
|
430
|
+
import pyarrow as pa
|
431
|
+
table = bitvavo.assets({}, output_format='pyarrow')
|
432
|
+
df = table.to_pandas() # Convert to pandas when needed
|
433
|
+
```
|
434
|
+
|
216
435
|
## Error Handling
|
217
436
|
|
218
437
|
```python
|
@@ -247,11 +466,28 @@ print(f"Remaining API calls: {remaining}")
|
|
247
466
|
if remaining > 10:
|
248
467
|
# Safe to make API calls
|
249
468
|
response = bitvavo.balance({})
|
469
|
+
|
470
|
+
# With multiple API keys, rate limits are distributed
|
471
|
+
bitvavo_multi = Bitvavo({
|
472
|
+
'APIKEYS': [
|
473
|
+
{'key': 'key1', 'secret': 'secret1'},
|
474
|
+
{'key': 'key2', 'secret': 'secret2'}
|
475
|
+
]
|
476
|
+
})
|
477
|
+
|
478
|
+
# Each key gets its own rate limit pool
|
479
|
+
# Automatic failover when one key hits limits
|
480
|
+
for i in range(2000): # Would exceed single key limit
|
481
|
+
markets = bitvavo_multi.markets({}) # Automatically switches keys
|
482
|
+
|
483
|
+
# Keyless calls don't count against authenticated rate limits
|
484
|
+
bitvavo_keyless = Bitvavo({'PREFER_KEYLESS': True})
|
485
|
+
markets = bitvavo_keyless.markets({}) # Uses public rate limit pool
|
250
486
|
```
|
251
487
|
|
252
488
|
## Development & Contributing
|
253
489
|
|
254
|
-
|
490
|
+
````shell
|
255
491
|
echo "install development requirements"
|
256
492
|
uv sync
|
257
493
|
echo "run tox, a program that creates separate environments for different python versions, for testing purposes (among other things)"
|
@@ -283,7 +519,7 @@ uv run mypy src/
|
|
283
519
|
# Linting and formatting
|
284
520
|
uv run ruff check
|
285
521
|
uv run ruff format
|
286
|
-
|
522
|
+
````
|
287
523
|
|
288
524
|
### Project Structure
|
289
525
|
|
@@ -317,6 +553,9 @@ This package includes a `py.typed` file to enable type checking. Reference: [Don
|
|
317
553
|
|
318
554
|
- Import: `from bitvavo_api_upgraded import Bitvavo` (instead of `from python_bitvavo_api.bitvavo import Bitvavo`)
|
319
555
|
- **Breaking Change**: Trading operations require `operatorId` parameter
|
556
|
+
- **New**: Multiple API key support for better rate limiting
|
557
|
+
- **New**: Keyless access for public endpoints
|
558
|
+
- **New**: Comprehensive dataframe support
|
320
559
|
- Enhanced error handling and type safety
|
321
560
|
- Better configuration management with `.env` support
|
322
561
|
|
@@ -325,7 +564,30 @@ This package includes a `py.typed` file to enable type checking. Reference: [Don
|
|
325
564
|
1. Update import statements
|
326
565
|
2. Add `operatorId` to trading method calls
|
327
566
|
3. Optional: Migrate to `.env` configuration
|
328
|
-
4.
|
567
|
+
4. Optional: Configure multiple API keys for better rate limits
|
568
|
+
5. Optional: Enable keyless mode for public endpoint efficiency
|
569
|
+
6. Enjoy improved type hints and error handling!
|
570
|
+
|
571
|
+
### Enhanced Features (Optional)
|
572
|
+
|
573
|
+
```python
|
574
|
+
# Traditional single key (works as before)
|
575
|
+
bitvavo = Bitvavo({'APIKEY': 'key', 'APISECRET': 'secret'})
|
576
|
+
|
577
|
+
# New: Multiple keys for rate limiting
|
578
|
+
bitvavo = Bitvavo({
|
579
|
+
'APIKEYS': [
|
580
|
+
{'key': 'key1', 'secret': 'secret1'},
|
581
|
+
{'key': 'key2', 'secret': 'secret2'}
|
582
|
+
]
|
583
|
+
})
|
584
|
+
|
585
|
+
# New: Keyless for public endpoints
|
586
|
+
bitvavo = Bitvavo({'PREFER_KEYLESS': True})
|
587
|
+
|
588
|
+
# New: Dataframe support
|
589
|
+
markets_df = bitvavo.markets({}, output_format='pandas')
|
590
|
+
```
|
329
591
|
|
330
592
|
---
|
331
593
|
|
@@ -388,105 +650,105 @@ Want to quickly make a trading app? Here you go:
|
|
388
650
|
|
389
651
|
1. **Install Bitvavo SDK for Python**
|
390
652
|
|
391
|
-
|
392
|
-
|
393
|
-
|
653
|
+
In your Python app, add [Bitvavo SDK for
|
654
|
+
Python](https://github.com/bitvavo/python-bitvavo-api) from
|
655
|
+
[pypi.org](https://pypi.org/project/python-bitvavo-api/):
|
394
656
|
|
395
|
-
|
396
|
-
|
397
|
-
|
657
|
+
```shell
|
658
|
+
python -m pip install python_bitvavo_api
|
659
|
+
```
|
398
660
|
|
399
|
-
|
400
|
-
|
661
|
+
If you installed from `test.pypi.com`, update the requests library: `pip
|
662
|
+
install --upgrade requests`.
|
401
663
|
|
402
664
|
1. **Create a simple Bitvavo implementation**
|
403
665
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
666
|
+
Add the following code to a new file in your app:
|
667
|
+
|
668
|
+
```python
|
669
|
+
from python_bitvavo_api.bitvavo import Bitvavo
|
670
|
+
import json
|
671
|
+
import time
|
672
|
+
|
673
|
+
# Use this class to connect to Bitvavo and make your first calls.
|
674
|
+
# Add trading strategies to implement your business logic.
|
675
|
+
class BitvavoImplementation:
|
676
|
+
api_key = "<Replace with your your API key from Bitvavo Dashboard>"
|
677
|
+
api_secret = "<Replace with your API secret from Bitvavo Dashboard>"
|
678
|
+
bitvavo_engine = None
|
679
|
+
bitvavo_socket = None
|
680
|
+
|
681
|
+
# Connect securely to Bitvavo, create the WebSocket and error callbacks.
|
682
|
+
def __init__(self):
|
683
|
+
self.bitvavo_engine = Bitvavo({
|
684
|
+
'APIKEY': self.api_key,
|
685
|
+
'APISECRET': self.api_secret
|
686
|
+
})
|
687
|
+
self.bitvavo_socket = self.bitvavo_engine.newWebsocket()
|
688
|
+
self.bitvavo_socket.setErrorCallback(self.error_callback)
|
689
|
+
|
690
|
+
# Handle errors.
|
691
|
+
def error_callback(self, error):
|
692
|
+
print("Add your error message.")
|
693
|
+
#print("Errors:", json.dumps(error, indent=2))
|
694
|
+
|
695
|
+
# Retrieve the data you need from Bitvavo in order to implement your
|
696
|
+
# trading logic. Use multiple workflows to return data to your
|
697
|
+
# callbacks.
|
698
|
+
def a_trading_strategy(self):
|
699
|
+
self.bitvavo_socket.ticker24h({}, self.a_trading_strategy_callback)
|
700
|
+
|
701
|
+
# In your app you analyse data returned by the trading strategy, then make
|
702
|
+
# calls to Bitvavo to respond to market conditions.
|
703
|
+
def a_trading_strategy_callback(self, response):
|
704
|
+
# Iterate through the markets
|
705
|
+
for market in response:
|
706
|
+
|
707
|
+
match market["market"]:
|
708
|
+
case "ZRX-EUR":
|
709
|
+
print("Eureka, the latest bid for ZRX-EUR is: ", market["bid"] )
|
710
|
+
# Implement calculations for your trading logic.
|
711
|
+
# If they are positive, place an order: For example:
|
712
|
+
# self.bitvavo_socket.placeOrder("ZRX-EUR",
|
713
|
+
# 'buy',
|
714
|
+
# 'limit',
|
715
|
+
# { 'amount': '1', 'price': '00001' },
|
716
|
+
# self.order_placed_callback)
|
717
|
+
case "a different market":
|
718
|
+
print("do something else")
|
719
|
+
case _:
|
720
|
+
print("Not this one: ", market["market"])
|
721
|
+
|
722
|
+
|
723
|
+
|
724
|
+
def order_placed_callback(self, response):
|
725
|
+
# The order return parameters explain the quote and the fees for this trade.
|
726
|
+
print("Order placed:", json.dumps(response, indent=2))
|
727
|
+
# Add your business logic.
|
728
|
+
|
729
|
+
|
730
|
+
# Sockets are fast, but asynchronous. Keep the socket open while you are
|
731
|
+
# trading.
|
732
|
+
def wait_and_close(self):
|
733
|
+
# Bitvavo uses a weight based rate limiting system. Your app is limited to 1000 weight points per IP or
|
734
|
+
# API key per minute. The rate weighting for each endpoint is supplied in Bitvavo API documentation.
|
735
|
+
# This call returns the amount of points left. If you make more requests than permitted by the weight limit,
|
736
|
+
# your IP or API key is banned.
|
737
|
+
limit = self.bitvavo_engine.getRemainingLimit()
|
738
|
+
try:
|
739
|
+
while (limit > 0):
|
740
|
+
time.sleep(0.5)
|
741
|
+
limit = self.bitvavo_engine.getRemainingLimit()
|
742
|
+
except KeyboardInterrupt:
|
743
|
+
self.bitvavo_socket.closeSocket()
|
744
|
+
|
745
|
+
|
746
|
+
# Shall I re-explain main? Naaaaaaaaaa.
|
747
|
+
if __name__ == '__main__':
|
748
|
+
bvavo = BitvavoImplementation()
|
749
|
+
bvavo.a_trading_strategy()
|
750
|
+
bvavo.wait_and_close()
|
751
|
+
```
|
490
752
|
|
491
753
|
1. **Add security information**
|
492
754
|
|
@@ -502,8 +764,8 @@ Want to quickly make a trading app? Here you go:
|
|
502
764
|
|
503
765
|
1. **Run your app**
|
504
766
|
|
505
|
-
|
506
|
-
|
767
|
+
- Command line warriors: `python3 <filename>`.
|
768
|
+
- IDE heroes: press the big green button.
|
507
769
|
|
508
770
|
Your app connects to Bitvavo and returns a list the latest trade price for each
|
509
771
|
market. You use this data to implement your trading logic.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
bitvavo_api_upgraded/__init__.py,sha256=J_HdGBmZOfb1eOydaxsPmXfOIZ58hVa1qAfE6QErUHs,301
|
2
|
+
bitvavo_api_upgraded/bitvavo.py,sha256=0zg4cTU_UAH9d0BcENbvvvK-0T2YurxGIMu-jXlGDSo,178030
|
3
|
+
bitvavo_api_upgraded/dataframe_utils.py,sha256=Jf-2zkYuK5Zs9kiMFJlCmO-OykjZyFIvW2aaMJYPUpo,5792
|
4
|
+
bitvavo_api_upgraded/helper_funcs.py,sha256=4oBdQ1xB-C2XkQTmN-refzIzWfO-IUowDSWhOSFdCRU,3212
|
5
|
+
bitvavo_api_upgraded/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
bitvavo_api_upgraded/settings.py,sha256=br1oqN3K8OoimmKa1JlvzMgpYNHfr2kK2f14tC72dl8,5311
|
7
|
+
bitvavo_api_upgraded/type_aliases.py,sha256=EOd3LhruyM1aZYn4xyKYhdoSql8mZH88acN0qGzMMck,1992
|
8
|
+
bitvavo_api_upgraded-2.3.0.dist-info/WHEEL,sha256=4n27za1eEkOnA7dNjN6C5-O2rUiw6iapszm14Uj-Qmk,79
|
9
|
+
bitvavo_api_upgraded-2.3.0.dist-info/METADATA,sha256=PR1cQJzAFKh8OyXG_5F4IUCDDmNWA7Pb4eBm_XPkE9k,25512
|
10
|
+
bitvavo_api_upgraded-2.3.0.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
bitvavo_api_upgraded/__init__.py,sha256=0922b82678a737a9f1314aa84fe4bf565f5425ce0d3aac1f6db65ff909efa68e,222
|
2
|
-
bitvavo_api_upgraded/bitvavo.py,sha256=e4d986ae3529b082d329f1da51027e7400f7a342faa023e037181dceb439d481,134183
|
3
|
-
bitvavo_api_upgraded/helper_funcs.py,sha256=e2805d435c41f82d979104e637eade7f323359f3be214a300d25a139215d0915,3212
|
4
|
-
bitvavo_api_upgraded/py.typed,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
|
5
|
-
bitvavo_api_upgraded/settings.py,sha256=647dac47d894c8e0bf9526aa993e74c04467814ba86efbbc7744cb8983799d38,2266
|
6
|
-
bitvavo_api_upgraded/type_aliases.py,sha256=3409cc4a4e67e9268422f1c579230a9d73b17cec276c5b849d129a01795c998c,932
|
7
|
-
bitvavo_api_upgraded-2.0.0.dist-info/WHEEL,sha256=2b400f346628f0064eb5bbf656b39df8dfcb092437ab08244409d295749b81a3,78
|
8
|
-
bitvavo_api_upgraded-2.0.0.dist-info/METADATA,sha256=e7e9d2261c0af757cfe323dc911012b2f834a030848684ac6d18585911eb6691,17102
|
9
|
-
bitvavo_api_upgraded-2.0.0.dist-info/RECORD,,
|