Skip to content

Commit bf1af9a

Browse files
Include timeout option for connection to API
1 parent f488776 commit bf1af9a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ bitvavo = Bitvavo({
7272
'RESTURL': 'https://api.bitvavo.com/v2',
7373
'WSURL': 'wss://ws.bitvavo.com/v2/',
7474
'ACCESSWINDOW': 10000,
75-
'DEBUGGING': False
75+
'DEBUGGING': False,
76+
'TIMEOUT': (15, 30), # 15 seconds for connection, 30 seconds for response
7677
})
7778
```
7879

python_bitvavo_api/bitvavo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def __init__(self, options = {}):
152152
self.base = options[key]
153153
elif key.lower() == "wsurl":
154154
self.wsUrl = options[key]
155+
elif key.lower() == "timeout":
156+
self.timeout = options[key]
155157
if(self.ACCESSWINDOW == None):
156158
self.ACCESSWINDOW = 10000
157159

@@ -191,9 +193,9 @@ def publicRequest(self, url):
191193
'bitvavo-access-timestamp': str(now),
192194
'bitvavo-access-window': str(self.ACCESSWINDOW)
193195
}
194-
r = requests.get(url, headers = headers)
196+
r = requests.get(url, headers = headers, timeout = self.timeout)
195197
else:
196-
r = requests.get(url)
198+
r = requests.get(url, timeout = self.timeout)
197199
if('error' in r.json()):
198200
self.updateRateLimit(r.json())
199201
else:
@@ -212,13 +214,13 @@ def privateRequest(self, endpoint, postfix, body = {}, method = 'GET'):
212214
}
213215
debugToConsole("REQUEST: " + url)
214216
if(method == 'GET'):
215-
r = requests.get(url, headers = headers)
217+
r = requests.get(url, headers = headers, timeout = self.timeout)
216218
elif(method == 'DELETE'):
217-
r = requests.delete(url, headers = headers)
219+
r = requests.delete(url, headers = headers, timeout = self.timeout)
218220
elif(method == 'POST'):
219-
r = requests.post(url, headers = headers, json = body)
221+
r = requests.post(url, headers = headers, json = body, timeout = self.timeout)
220222
elif(method == 'PUT'):
221-
r = requests.put(url, headers = headers, json = body)
223+
r = requests.put(url, headers = headers, json = body, timeout = self.timeout)
222224
if('error' in r.json()):
223225
self.updateRateLimit(r.json())
224226
else:

0 commit comments

Comments
 (0)