Skip to content

Commit e0b7f4c

Browse files
Add a code example
1 parent 8ba3e83 commit e0b7f4c

File tree

1 file changed

+81
-9
lines changed

1 file changed

+81
-9
lines changed

README.md

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<table cellspacing="3" border="0">
66
<tr>
77
<td><a href="https://bitvavo.com"><img src="https://bitvavo.com/press/blue/bitvavo-mark-square/bitvavo-mark-square-blue.svg" width="100" title="Bitvavo Logo"></td>
8-
<td><h1>Bitvavo API for Python</h1></td>
8+
<td><h1>Bitvavo SDK for Python</h1></td>
99
</tr>
1010
</table>
1111
</td>
@@ -16,13 +16,13 @@
1616
</tr>
1717
</table>
1818

19-
Crypto starts with Bitvavo. You use Bitvavo API for Python to buy, sell and store over 200 digital assets on Bitvavo from inside your own app.
19+
Crypto starts with Bitvavo. You use Bitvavo SDK for Python to buy, sell, and store over 200 digital assets on Bitvavo from inside your own app.
2020

21-
To trade and execute your advanced trading strategies, Bitvavo API for Python is a wrapper that enables you to easily call every endpoint in [Bitvavo API](https://docs.bitvavo.com/)
21+
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/)
2222

2323
## Prerequisites
2424

25-
To start programming with Bitvavo API for Python you need:
25+
To start programming with Bitvavo SDK for Python you need:
2626

2727
- [Python3](https://www.python.org/downloads/) installed on your development environment
2828

@@ -31,6 +31,7 @@ To start programming with Bitvavo API for Python you need:
3131
open /Applications/Python\ 3.12/Install\ Certificates.command
3232
open /Applications/Python\ 3.12/Update\ Shell\ Profile.command
3333
```
34+
- A Python app. Use your favorite IDE, or run from the command line.
3435
- An [API key and secret](https://support.bitvavo.com/hc/en-us/articles/4405059841809) associated with your Bitvavo account
3536
3637
You control the actions your app can do using the rights you assign to the API key. Possible rights are:
@@ -42,12 +43,83 @@ To start programming with Bitvavo API for Python you need:
4243
4344
## Get started
4445
45-
1. Download this python repository
46+
1. **Install Bitvavo SDK for Python**
47+
48+
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/):
49+
```terminal
50+
python -m pip install python_bitvavo_api
51+
```
52+
1. **Create a simple Bitvavo implementation**
53+
54+
Add the following code in a new file in your app:
55+
56+
```python
57+
# Import Bitvavo SDK for Python
58+
from python_bitvavo_api.bitvavo import Bitvavo
59+
import json
60+
import time
61+
62+
# Use this class to connect to Bitvavo and make your first calls
63+
# Add workflows to implement your business logic.
64+
class bitvavo_implementation:
65+
api_key = "<Replace with your your API key from Bitvavo Dashboard>"
66+
api_secret = "<Replace with your API secrete from Bitvavo Dashboard>"
67+
bitvavo_engine = None
68+
bitvavo_socket = None
69+
70+
# Connect securely to Bitvavo, create the websocket and error callbacks
71+
def __init__(self):
72+
self.bitvavo_engine = Bitvavo({
73+
'APIKEY': self.api_key,
74+
'APISECRET': self.api_secret
75+
})
76+
self.bitvavo_socket = self.bitvavo_engine.newWebsocket()
77+
self.bitvavo_socket.setErrorCallback(self.error_callback)
78+
79+
# Handle errors
80+
def error_callback(self, error):
81+
print("Errors:", json.dumps(error, indent=2))
82+
83+
# Retrieve the data you need from Bitvavo in order to implement your
84+
# Trading logic. Use multiple workflows to return data to your
85+
# Callbacks
86+
def a_workflow(self):
87+
self.bitvavo_socket.time(self.a_workflow_callback)
88+
self.bitvavo_socket.markets({}, self.a_workflow_callback)
89+
90+
# In your app you analyse data returned by the workflow, then make
91+
# calls to Bitvavo to respond to market conditions
92+
def a_workflow_callback(self, response):
93+
print("workflow:", json.dumps(response, indent=2))
94+
95+
# Sockets are fast, but asynchronous. Keep the socket open while you are
96+
# trading.
97+
def wait_and_close(self):
98+
limit = self.bitvavo_engine.getRemainingLimit()
99+
try:
100+
while (limit > 0):
101+
time.sleep(0.5)
102+
limit = self.bitvavo_engine.getRemainingLimit()
103+
except KeyboardInterrupt:
104+
self.bitvavo_socket.closeSocket()
105+
106+
# Shall I re-explain main? Naaaaaaaaaa.
107+
if __name__ == '__main__':
108+
bvavo = bitvavo_implementation()
109+
bvavo.a_workflow()
110+
bvavo.wait_and_close()
46111
47-
1. In your development environment, install the Bitvavo API for Python package from pip:
48-
```terminal
49-
python -m pip install python_bitvavo_api
50-
```
112+
```
113+
1. **Add security information**
114+
115+
Replace the values of `api_key` and `api_secret` with your credentials from [Bitvavo Dashboard](https://account.bitvavo.com/user/api).
116+
117+
1. **Run your app**
118+
119+
- Command line warriors: `python3 <filename>`.
120+
- IDE heroes: press the big green button.
121+
122+
Your app connects to Bitvavo and returns a list of the current market prices.
51123
52124
# Python Bitvavo Api
53125
This is the python wrapper for the Bitvavo API. This project can be used to build your own projects which interact with the Bitvavo platform. Every function available on the API can be called through a REST request or over websockets. For info on the specifics of every parameter consult the [Bitvavo API documentation](https://docs.bitvavo.com/)

0 commit comments

Comments
 (0)