Skip to content

Commit eca07b3

Browse files
Lead in sentence.
1 parent 2ceaf4a commit eca07b3

File tree

1 file changed

+76
-52
lines changed

1 file changed

+76
-52
lines changed

README.md

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<td>
55
<table cellspacing="3" border="0">
66
<tr>
7-
<td><a href="https://bitvavo.com"><img src="https://bitvavo.com/press/blue/bitvavo-mark-square/bitvavo-mark-square-blue.png" width="100" title="Bitvavo Logo"></td>
7+
<td><a href="https://bitvavo.com"><img src="./assets/bitvavo-mark-square-blue.svg" width="100" title="Bitvavo Logo"></td>
88
<td><h1>Bitvavo SDK for Python</h1></td>
99
</tr>
1010
</table>
@@ -57,67 +57,91 @@ Want to quickly make a first app? Here we go:
5757
import json
5858
import time
5959
60-
# Use this class to connect to Bitvavo and make your first calls.
61-
# Add workflows to implement your business logic.
62-
class bitvavo_implementation:
63-
api_key = "<Replace with your your API key from Bitvavo Dashboard>"
64-
api_secret = "<Replace with your API secrete from Bitvavo Dashboard>"
65-
bitvavo_engine = None
66-
bitvavo_socket = None
67-
68-
# Connect securely to Bitvavo, create the websocket and error callbacks
69-
def __init__(self):
70-
self.bitvavo_engine = Bitvavo({
71-
'APIKEY': self.api_key,
72-
'APISECRET': self.api_secret
73-
})
74-
self.bitvavo_socket = self.bitvavo_engine.newWebsocket()
75-
self.bitvavo_socket.setErrorCallback(self.error_callback)
76-
77-
# Handle errors
78-
def error_callback(self, error):
79-
print("Errors:", json.dumps(error, indent=2))
80-
81-
# Retrieve the data you need from Bitvavo in order to implement your
82-
# trading logic. Use multiple workflows to return data to your
83-
# callbacks
84-
def a_workflow(self):
85-
self.bitvavo_socket.time(self.a_workflow_callback)
86-
self.bitvavo_socket.markets({}, self.a_workflow_callback)
87-
88-
# In your app you analyse data returned by the workflow, then make
89-
# calls to Bitvavo to respond to market conditions
90-
def a_workflow_callback(self, response):
91-
print("workflow:", json.dumps(response, indent=2))
92-
93-
# Sockets are fast, but asynchronous. Keep the socket open while you are
94-
# trading.
95-
def wait_and_close(self):
96-
limit = self.bitvavo_engine.getRemainingLimit()
97-
try:
98-
while (limit > 0):
99-
time.sleep(0.5)
100-
limit = self.bitvavo_engine.getRemainingLimit()
101-
except KeyboardInterrupt:
102-
self.bitvavo_socket.closeSocket()
103-
104-
# Shall I re-explain main? Naaaaaaaaaa.
105-
if __name__ == '__main__':
106-
bvavo = bitvavo_implementation()
107-
bvavo.a_workflow()
108-
bvavo.wait_and_close()
109-
60+
61+
# Use this class to connect to Bitvavo and make your first calls
62+
# Add trading strategies to implement your business logic.
63+
class bitvavo_implementation:
64+
api_key = "<Replace with your your API key from Bitvavo Dashboard>"
65+
api_secret = "<Replace with your API secrete from Bitvavo Dashboard>"
66+
bitvavo_engine = None
67+
bitvavo_socket = None
68+
69+
# Connect securely to Bitvavo, create the websocket and error callbacks
70+
def __init__(self):
71+
self.bitvavo_engine = Bitvavo({
72+
'APIKEY': self.api_key,
73+
'APISECRET': self.api_secret
74+
})
75+
self.bitvavo_socket = self.bitvavo_engine.newWebsocket()
76+
self.bitvavo_socket.setErrorCallback(self.error_callback)
77+
78+
# Handle errors
79+
def error_callback(self, error):
80+
print("Errors:", json.dumps(error, indent=2))
81+
82+
# Retrieve the data you need from Bitvavo in order to implement your
83+
# Trading logic. Use multiple workflows to return data to your
84+
# Callbacks
85+
def a_trading_strategy(self):
86+
self.bitvavo_socket.ticker24h({}, self.a_trading_strategy_callback)
87+
# You can also filter the ticker to retrieve specific markets only.
88+
89+
# In your app you analyse data returned by the workflow, then make
90+
# calls to Bitvavo to respond to market conditions
91+
def a_trading_strategy_callback(self, response):
92+
# Iterate through the
93+
for market in response:
94+
match market["market"]:
95+
case "A market":
96+
print("Check data against your trading strategy. For example, the bid is: ", market["bid"] )
97+
# Implement calculations for your trading logic
98+
# If they are positive, place an order: For example:
99+
# self.bitvavo_socket.placeOrder("A market",
100+
# 'buy',
101+
# 'limit',
102+
# { 'amount': '1', 'price': '00001' },
103+
# self.order_placed_callback)
104+
case "a different market":
105+
print("Implement a different strategy for this market")
106+
107+
108+
def order_placed_callback(self, response):
109+
print("Order placed:", json.dumps(response, indent=2))
110+
# Add your business logic to handle orders
111+
112+
113+
# Sockets are fast, but asynchronous. Keep the socket open while you are
114+
# trading.
115+
def wait_and_close(self):
116+
limit = self.bitvavo_engine.getRemainingLimit()
117+
try:
118+
while (limit > 0):
119+
time.sleep(0.5)
120+
limit = self.bitvavo_engine.getRemainingLimit()
121+
except KeyboardInterrupt:
122+
self.bitvavo_socket.closeSocket()
123+
124+
125+
# Shall I re-explain main? Naaaaaaaaaa.
126+
if __name__ == '__main__':
127+
bvavo = bitvavo_implementation()
128+
bvavo.a_trading_strategy()
129+
bvavo.wait_and_close()
110130
```
111131
1. **Add security information**
112132
113133
Replace the values of `api_key` and `api_secret` with your credentials from [Bitvavo Dashboard](https://account.bitvavo.com/user/api).
134+
135+
You must supply your security information to trade on Bitvavo and see your account details. You can retrieve public information such as available markets, assets and current market without
136+
supplying your key and secret. However, Bitvavo returns an error.
114137
115138
1. **Run your app**
116139
117140
- Command line warriors: `python3 <filename>`.
118141
- IDE heroes: press the big green button.
119142
120-
Your app connects to Bitvavo and returns a list of the current market prices.
143+
Your app connects to Bitvavo and returns a list the latest trade price for each market. The callback cycles through the
144+
market data so you can implement your trading logic.
121145
122146
# Python Bitvavo Api
123147
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)