# Bitvavo API (upgraded)
## Userguide
`pip install bitvavo_api_upgraded`
Works the same as the official API lib, but I have:
- typing for _all_ functions and classes
- unit tests (I already found three bugs that I fixed, because the original code
wasn't tested, at all)
- a changelog, so you can track of the changes that I make
- compatible with Python 3.7 and newer ([3.6 isn't supported as of
2021-12-23](https://endoflife.date/python))
## Devguide
```shell
echo "install development requirements"
uv sync
echo "run tox, a program that creates separate environments for different python versions, for testing purposes (among other things)"
uv run tox
```
### Semantic Versioning (SemVer)
I'm using semantic versioning, which means that changes mean this:
1. MAJOR version when you make incompatible API changes,
1. MINOR version when you add functionality in a backwards compatible manner,
and
1. PATCH version when you make backwards compatible bug fixes.
### Versioning
Copy the following block to CHANGELOG.md and add all information since last
version bump
```markdown
## $UNRELEASED
### Added
...
### Changed
...
### Removed
...
```
Commit those changes.
After that, run `bump-my-version bump (major|minor|patch)` to automatically
replace `$UNRELEASED` with the new version number, and also automatically tag
and commit (with tag) to release a new version via the Github workflow.
## py.typed
Perhaps a curious file, but it simply exists to let `mypy` know that the code is
typed: [Don't forget `py.typed` for your typed Python package
](https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/)
## Last note
_below this line is the old README.md_
---
# Bitvavo SDK for Python
Crypto starts with Bitvavo. You use Bitvavo SDK for Python to buy, sell, and
store over 200 digital assets on Bitvavo from inside your app.
To trade and execute your advanced trading strategies, Bitvavo SDK for Python is
a wrapper that enables you to easily call every endpoint in [Bitvavo
API](https://docs.bitvavo.com/).
- [Prerequisites](#prerequisites) - what you need to start developing with
Bitvavo SDK for Python
- [Get started](#get-started) - rapidly create an app and start trading with
Bitvavo
- [About the SDK](#about-the-sdk) - general information about Bitvavo SDK for
Python
- [API reference](https://docs.bitvavo.com/) - information on the specifics of
every parameter
This page shows you how to use Bitvavo SDK for Python with WebSockets. For REST,
see the [REST readme](docs/rest.md).
## Prerequisites
To start programming with Bitvavo SDK for Python you need:
- [Python3](https://www.python.org/downloads/) installed on your development
environment
If you are working on macOS, ensure that you have installed SSH certificates:
```terminal
open /Applications/Python\ 3.12/Install\ Certificates.command
open /Applications/Python\ 3.12/Update\ Shell\ Profile.command
```
- A Python app. Use your favorite IDE, or run from the command line
- An [API key and
secret](https://support.bitvavo.com/hc/en-us/articles/4405059841809)
associated with your Bitvavo account
You control the actions your app can do using the rights you assign to the API
key. Possible rights are:
- **View**: retrieve information about your balance, account, deposit and
withdrawals
- **Trade**: place, update, view and cancel orders
- **Withdraw**: withdraw funds
Best practice is to not grant this privilege, withdrawals using the API do
not require 2FA and e-mail confirmation.
## Get started
Want to quickly make a trading app? Here you go:
1. **Install Bitvavo SDK for Python**
In your Python app, add [Bitvavo SDK for
Python](https://github.com/bitvavo/python-bitvavo-api) from
[pypi.org](https://pypi.org/project/python-bitvavo-api/):
```shell
python -m pip install python_bitvavo_api
```
If you installed from `test.pypi.com`, update the requests library: `pip
install --upgrade requests`.
1. **Create a simple Bitvavo implementation**
Add the following code to a new file in your app:
```python
from python_bitvavo_api.bitvavo import Bitvavo
import json
import time
# Use this class to connect to Bitvavo and make your first calls.
# Add trading strategies to implement your business logic.
class BitvavoImplementation:
api_key = "<Replace with your your API key from Bitvavo Dashboard>"
api_secret = "<Replace with your API secret from Bitvavo Dashboard>"
bitvavo_engine = None
bitvavo_socket = None
# Connect securely to Bitvavo, create the WebSocket and error callbacks.
def __init__(self):
self.bitvavo_engine = Bitvavo({
'APIKEY': self.api_key,
'APISECRET': self.api_secret
})
self.bitvavo_socket = self.bitvavo_engine.newWebsocket()
self.bitvavo_socket.setErrorCallback(self.error_callback)
# Handle errors.
def error_callback(self, error):
print("Add your error message.")
#print("Errors:", json.dumps(error, indent=2))
# Retrieve the data you need from Bitvavo in order to implement your
# trading logic. Use multiple workflows to return data to your
# callbacks.
def a_trading_strategy(self):
self.bitvavo_socket.ticker24h({}, self.a_trading_strategy_callback)
# In your app you analyse data returned by the trading strategy, then make
# calls to Bitvavo to respond to market conditions.
def a_trading_strategy_callback(self, response):
# Iterate through the markets
for market in response:
match market["market"]:
case "ZRX-EUR":
print("Eureka, the latest bid for ZRX-EUR is: ", market["bid"] )
# Implement calculations for your trading logic.
# If they are positive, place an order: For example:
# self.bitvavo_socket.placeOrder("ZRX-EUR",
# 'buy',
# 'limit',
# { 'amount': '1', 'price': '00001' },
# self.order_placed_callback)
case "a different market":
print("do something else")
case _:
print("Not this one: ", market["market"])
def order_placed_callback(self, response):
# The order return parameters explain the quote and the fees for this trade.
print("Order placed:", json.dumps(response, indent=2))
# Add your business logic.
# Sockets are fast, but asynchronous. Keep the socket open while you are
# trading.
def wait_and_close(self):
# Bitvavo uses a weight based rate limiting system. Your app is limited to 1000 weight points per IP or
# API key per minute. The rate weighting for each endpoint is supplied in Bitvavo API documentation.
# This call returns the amount of points left. If you make more requests than permitted by the weight limit,
# your IP or API key is banned.
limit = self.bitvavo_engine.getRemainingLimit()
try:
while (limit > 0):
time.sleep(0.5)
limit = self.bitvavo_engine.getRemainingLimit()
except KeyboardInterrupt:
self.bitvavo_socket.closeSocket()
# Shall I re-explain main? Naaaaaaaaaa.
if __name__ == '__main__':
bvavo = BitvavoImplementation()
bvavo.a_trading_strategy()
bvavo.wait_and_close()
```
1. **Add security information**
You must supply your security information to trade on Bitvavo and see your
account information using the authenticate methods. Replace the values of
`api_key` and `api_secret` with your credentials from [Bitvavo
Dashboard](https://account.bitvavo.com/user/api).
You can retrieve public information such as available markets, assets and
current market without supplying your key and secret. However,
unauthenticated calls have lower rate limits based on your IP address, and
your account is blocked for longer if you exceed your limit.
1. **Run your app**
- Command line warriors: `python3 <filename>`.
- IDE heroes: press the big green button.
Your app connects to Bitvavo and returns a list the latest trade price for each
market. You use this data to implement your trading logic.
## About the SDK
This section explains global concepts about Bitvavo SDK for Python.
### Rate limit
Bitvavo uses a weight based rate limiting system. Your app is limited to 1000
weight points per IP or API key per minute. When you make a call to Bitvavo API,
your remaining weight points are returned in the header of each REST request.
Websocket methods do not return your returning weight points, you track your
remaining weight points with a call to:
```python
limit = bitvavo.getRemainingLimit()
```
If you make more requests than permitted by the weight limit, your IP or API key
is banned.
The rate weighting for each endpoint is supplied in the [Bitvavo API
documentation](https://docs.bitvavo.com/).
### Requests
For all methods, required parameters are passed as separate values, optional
parameters are passed as a dictionary. Return parameters are in dictionary
format: `response['<key>'] = '<value>'`. However, as a limit order requires more
information than a market order, some optional parameters are required when you
place an order.
### Security
You must set your API key and secret for authenticated endpoints, public
endpoints do not require authentication.
Raw data
{
"_id": null,
"home_page": null,
"name": "bitvavo-api-upgraded",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "NostraDavid <55331731+NostraDavid@users.noreply.github.com>",
"keywords": null,
"author": "Bitvavo BV (original code)",
"author_email": "NostraDavid <55331731+NostraDavid@users.noreply.github.com>",
"download_url": "https://files.pythonhosted.org/packages/6b/78/7847f0e551ac1274652bcc9ebeab56d1ae1adf1bd61d6b70043cf9d3f9ac/bitvavo_api_upgraded-1.17.1.tar.gz",
"platform": null,
"description": "# Bitvavo API (upgraded)\n\n## Userguide\n\n`pip install bitvavo_api_upgraded`\n\nWorks the same as the official API lib, but I have:\n\n- typing for _all_ functions and classes\n- unit tests (I already found three bugs that I fixed, because the original code\n wasn't tested, at all)\n- a changelog, so you can track of the changes that I make\n- compatible with Python 3.7 and newer ([3.6 isn't supported as of\n 2021-12-23](https://endoflife.date/python))\n\n## Devguide\n\n```shell\necho \"install development requirements\"\nuv sync\necho \"run tox, a program that creates separate environments for different python versions, for testing purposes (among other things)\"\nuv run tox\n```\n\n### Semantic Versioning (SemVer)\n\nI'm using semantic versioning, which means that changes mean this:\n\n1. MAJOR version when you make incompatible API changes,\n1. MINOR version when you add functionality in a backwards compatible manner,\n and\n1. PATCH version when you make backwards compatible bug fixes.\n\n### Versioning\n\nCopy the following block to CHANGELOG.md and add all information since last\nversion bump\n\n```markdown\n## $UNRELEASED\n\n### Added\n\n...\n\n### Changed\n\n...\n\n### Removed\n\n...\n```\n\nCommit those changes.\n\nAfter that, run `bump-my-version bump (major|minor|patch)` to automatically\nreplace `$UNRELEASED` with the new version number, and also automatically tag\nand commit (with tag) to release a new version via the Github workflow.\n\n## py.typed\n\nPerhaps a curious file, but it simply exists to let `mypy` know that the code is\ntyped: [Don't forget `py.typed` for your typed Python package\n](https://blog.whtsky.me/tech/2021/dont-forget-py.typed-for-your-typed-python-package/)\n\n## Last note\n\n_below this line is the old README.md_\n\n---\n\n# Bitvavo SDK for Python\n\nCrypto starts with Bitvavo. You use Bitvavo SDK for Python to buy, sell, and\nstore over 200 digital assets on Bitvavo from inside your app.\n\nTo trade and execute your advanced trading strategies, Bitvavo SDK for Python is\na wrapper that enables you to easily call every endpoint in [Bitvavo\nAPI](https://docs.bitvavo.com/).\n\n- [Prerequisites](#prerequisites) - what you need to start developing with\n Bitvavo SDK for Python\n- [Get started](#get-started) - rapidly create an app and start trading with\n Bitvavo\n- [About the SDK](#about-the-sdk) - general information about Bitvavo SDK for\n Python\n- [API reference](https://docs.bitvavo.com/) - information on the specifics of\n every parameter\n\nThis page shows you how to use Bitvavo SDK for Python with WebSockets. For REST,\nsee the [REST readme](docs/rest.md).\n\n## Prerequisites\n\nTo start programming with Bitvavo SDK for Python you need:\n\n- [Python3](https://www.python.org/downloads/) installed on your development\n environment\n\n If you are working on macOS, ensure that you have installed SSH certificates:\n\n ```terminal\n open /Applications/Python\\ 3.12/Install\\ Certificates.command\n open /Applications/Python\\ 3.12/Update\\ Shell\\ Profile.command\n ```\n\n- A Python app. Use your favorite IDE, or run from the command line\n- An [API key and\n secret](https://support.bitvavo.com/hc/en-us/articles/4405059841809)\n associated with your Bitvavo account\n\n You control the actions your app can do using the rights you assign to the API\n key. Possible rights are:\n\n - **View**: retrieve information about your balance, account, deposit and\n withdrawals\n - **Trade**: place, update, view and cancel orders\n - **Withdraw**: withdraw funds\n\n Best practice is to not grant this privilege, withdrawals using the API do\n not require 2FA and e-mail confirmation.\n\n## Get started\n\nWant to quickly make a trading app? Here you go:\n\n1. **Install Bitvavo SDK for Python**\n\n In your Python app, add [Bitvavo SDK for\n Python](https://github.com/bitvavo/python-bitvavo-api) from\n [pypi.org](https://pypi.org/project/python-bitvavo-api/):\n\n ```shell\n python -m pip install python_bitvavo_api\n ```\n\n If you installed from `test.pypi.com`, update the requests library: `pip\n install --upgrade requests`.\n\n1. **Create a simple Bitvavo implementation**\n\n Add the following code to a new file in your app:\n\n ```python\n from python_bitvavo_api.bitvavo import Bitvavo\n import json\n import time\n\n # Use this class to connect to Bitvavo and make your first calls.\n # Add trading strategies to implement your business logic.\n class BitvavoImplementation:\n api_key = \"<Replace with your your API key from Bitvavo Dashboard>\"\n api_secret = \"<Replace with your API secret from Bitvavo Dashboard>\"\n bitvavo_engine = None\n bitvavo_socket = None\n\n # Connect securely to Bitvavo, create the WebSocket and error callbacks.\n def __init__(self):\n self.bitvavo_engine = Bitvavo({\n 'APIKEY': self.api_key,\n 'APISECRET': self.api_secret\n })\n self.bitvavo_socket = self.bitvavo_engine.newWebsocket()\n self.bitvavo_socket.setErrorCallback(self.error_callback)\n\n # Handle errors.\n def error_callback(self, error):\n print(\"Add your error message.\")\n #print(\"Errors:\", json.dumps(error, indent=2))\n\n # Retrieve the data you need from Bitvavo in order to implement your\n # trading logic. Use multiple workflows to return data to your\n # callbacks.\n def a_trading_strategy(self):\n self.bitvavo_socket.ticker24h({}, self.a_trading_strategy_callback)\n\n # In your app you analyse data returned by the trading strategy, then make\n # calls to Bitvavo to respond to market conditions.\n def a_trading_strategy_callback(self, response):\n # Iterate through the markets\n for market in response:\n\n match market[\"market\"]:\n case \"ZRX-EUR\":\n print(\"Eureka, the latest bid for ZRX-EUR is: \", market[\"bid\"] )\n # Implement calculations for your trading logic.\n # If they are positive, place an order: For example:\n # self.bitvavo_socket.placeOrder(\"ZRX-EUR\",\n # 'buy',\n # 'limit',\n # { 'amount': '1', 'price': '00001' },\n # self.order_placed_callback)\n case \"a different market\":\n print(\"do something else\")\n case _:\n print(\"Not this one: \", market[\"market\"])\n\n\n\n def order_placed_callback(self, response):\n # The order return parameters explain the quote and the fees for this trade.\n print(\"Order placed:\", json.dumps(response, indent=2))\n # Add your business logic.\n\n\n # Sockets are fast, but asynchronous. Keep the socket open while you are\n # trading.\n def wait_and_close(self):\n # Bitvavo uses a weight based rate limiting system. Your app is limited to 1000 weight points per IP or\n # API key per minute. The rate weighting for each endpoint is supplied in Bitvavo API documentation.\n # This call returns the amount of points left. If you make more requests than permitted by the weight limit,\n # your IP or API key is banned.\n limit = self.bitvavo_engine.getRemainingLimit()\n try:\n while (limit > 0):\n time.sleep(0.5)\n limit = self.bitvavo_engine.getRemainingLimit()\n except KeyboardInterrupt:\n self.bitvavo_socket.closeSocket()\n\n\n # Shall I re-explain main? Naaaaaaaaaa.\n if __name__ == '__main__':\n bvavo = BitvavoImplementation()\n bvavo.a_trading_strategy()\n bvavo.wait_and_close()\n ```\n\n1. **Add security information**\n\n You must supply your security information to trade on Bitvavo and see your\n account information using the authenticate methods. Replace the values of\n `api_key` and `api_secret` with your credentials from [Bitvavo\n Dashboard](https://account.bitvavo.com/user/api).\n\n You can retrieve public information such as available markets, assets and\n current market without supplying your key and secret. However,\n unauthenticated calls have lower rate limits based on your IP address, and\n your account is blocked for longer if you exceed your limit.\n\n1. **Run your app**\n\n - Command line warriors: `python3 <filename>`.\n - IDE heroes: press the big green button.\n\nYour app connects to Bitvavo and returns a list the latest trade price for each\nmarket. You use this data to implement your trading logic.\n\n## About the SDK\n\nThis section explains global concepts about Bitvavo SDK for Python.\n\n### Rate limit\n\nBitvavo uses a weight based rate limiting system. Your app is limited to 1000\nweight points per IP or API key per minute. When you make a call to Bitvavo API,\nyour remaining weight points are returned in the header of each REST request.\n\nWebsocket methods do not return your returning weight points, you track your\nremaining weight points with a call to:\n\n```python\nlimit = bitvavo.getRemainingLimit()\n```\n\nIf you make more requests than permitted by the weight limit, your IP or API key\nis banned.\n\nThe rate weighting for each endpoint is supplied in the [Bitvavo API\ndocumentation](https://docs.bitvavo.com/).\n\n### Requests\n\nFor all methods, required parameters are passed as separate values, optional\nparameters are passed as a dictionary. Return parameters are in dictionary\nformat: `response['<key>'] = '<value>'`. However, as a limit order requires more\ninformation than a market order, some optional parameters are required when you\nplace an order.\n\n### Security\n\nYou must set your API key and secret for authenticated endpoints, public\nendpoints do not require authentication.\n",
"bugtrack_url": null,
"license": "ISC License",
"summary": "A unit-tested fork of the Bitvavo API",
"version": "1.17.1",
"project_urls": {
"changelog": "https://github.com/Thaumatorium/bitvavo-api-upgraded/blob/master/CHANGELOG.md",
"homepage": "https://github.com/Thaumatorium/bitvavo-api-upgraded",
"repository": "https://github.com/Thaumatorium/bitvavo-api-upgraded"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "1ce4d0f2bb9832c1189740d00ee375afd3d91f5a9db4e358df12c5f98098a077",
"md5": "447c66591f9f10a9e5a4f473d59ba354",
"sha256": "ea0ea645d5f5daec3820edacf87885196f185d6a83c3f10c55273a659d7dab0c"
},
"downloads": -1,
"filename": "bitvavo_api_upgraded-1.17.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "447c66591f9f10a9e5a4f473d59ba354",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 30419,
"upload_time": "2024-12-24T18:33:06",
"upload_time_iso_8601": "2024-12-24T18:33:06.958840Z",
"url": "https://files.pythonhosted.org/packages/1c/e4/d0f2bb9832c1189740d00ee375afd3d91f5a9db4e358df12c5f98098a077/bitvavo_api_upgraded-1.17.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "6b787847f0e551ac1274652bcc9ebeab56d1ae1adf1bd61d6b70043cf9d3f9ac",
"md5": "cdc1ed3f5c48fc7dc3944d3fc1279fa8",
"sha256": "3ef31e6530604e10af5c32352fc974d236f3e0e9eb074e1ce37f17df497c8465"
},
"downloads": -1,
"filename": "bitvavo_api_upgraded-1.17.1.tar.gz",
"has_sig": false,
"md5_digest": "cdc1ed3f5c48fc7dc3944d3fc1279fa8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 112085,
"upload_time": "2024-12-24T18:33:10",
"upload_time_iso_8601": "2024-12-24T18:33:10.086084Z",
"url": "https://files.pythonhosted.org/packages/6b/78/7847f0e551ac1274652bcc9ebeab56d1ae1adf1bd61d6b70043cf9d3f9ac/bitvavo_api_upgraded-1.17.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-24 18:33:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Thaumatorium",
"github_project": "bitvavo-api-upgraded",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "bitvavo-api-upgraded"
}