Skip to content

Commit f788acc

Browse files
authored
Merge pull request #37 from michaelvanvliet/master
Include timeout option for connection to API
2 parents 05b123d + e36934f commit f788acc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Websocket methods do not return your returning weight points, you track your rem
172172
limit = bitvavo.getRemainingLimit()
173173
```
174174
175+
175176
If you make more requests than permitted by the weight limit, your IP or API key is banned.
176177
177178
The rate weighting for each endpoint is supplied in the [Bitvavo API documentation](https://docs.bitvavo.com/).

python_bitvavo_api/bitvavo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def __init__(self, options = {}):
155155
self.base = options[key]
156156
elif key.lower() == "wsurl":
157157
self.wsUrl = options[key]
158+
elif key.lower() == "timeout":
159+
self.timeout = options[key]
158160
if(self.ACCESSWINDOW == None):
159161
self.ACCESSWINDOW = 10000
160162

@@ -194,9 +196,9 @@ def publicRequest(self, url):
194196
'bitvavo-access-timestamp': str(now),
195197
'bitvavo-access-window': str(self.ACCESSWINDOW)
196198
}
197-
r = requests.get(url, headers = headers)
199+
r = requests.get(url, headers = headers, timeout = self.timeout)
198200
else:
199-
r = requests.get(url)
201+
r = requests.get(url, timeout = self.timeout)
200202
if('error' in r.json()):
201203
self.updateRateLimit(r.json())
202204
else:
@@ -215,13 +217,13 @@ def privateRequest(self, endpoint, postfix, body = {}, method = 'GET'):
215217
}
216218
debugToConsole("REQUEST: " + url)
217219
if(method == 'GET'):
218-
r = requests.get(url, headers = headers)
220+
r = requests.get(url, headers = headers, timeout = self.timeout)
219221
elif(method == 'DELETE'):
220-
r = requests.delete(url, headers = headers)
222+
r = requests.delete(url, headers = headers, timeout = self.timeout)
221223
elif(method == 'POST'):
222-
r = requests.post(url, headers = headers, json = body)
224+
r = requests.post(url, headers = headers, json = body, timeout = self.timeout)
223225
elif(method == 'PUT'):
224-
r = requests.put(url, headers = headers, json = body)
226+
r = requests.put(url, headers = headers, json = body, timeout = self.timeout)
225227
if('error' in r.json()):
226228
self.updateRateLimit(r.json())
227229
else:

0 commit comments

Comments
 (0)