@@ -18,7 +18,7 @@ def errorToConsole(message):
1818
1919def createSignature (timestamp , method , url , body , APISECRET ):
2020 string = str (timestamp ) + method + '/v2' + url
21- if ( len (body .keys ()) != 0 ) :
21+ if body is not None and len (body .keys ()) > 0 :
2222 string += json .dumps (body , separators = (',' ,':' ))
2323 signature = hmac .new (APISECRET .encode ('utf-8' ), string .encode ('utf-8' ), hashlib .sha256 ).hexdigest ()
2424 return signature
@@ -140,6 +140,7 @@ def __init__(self, options = {}):
140140 self .APISECRET = ''
141141 self .rateLimitRemaining = 1000
142142 self .rateLimitReset = 0
143+ self .timeout = None
143144 global debugging
144145 debugging = False
145146 for key in options :
@@ -189,7 +190,7 @@ def publicRequest(self, url):
189190 debugToConsole ("REQUEST: " + url )
190191 if (self .APIKEY != '' ):
191192 now = int (time .time () * 1000 )
192- sig = createSignature (now , 'GET' , url .replace (self .base , '' ), {} , self .APISECRET )
193+ sig = createSignature (now , 'GET' , url .replace (self .base , '' ), None , self .APISECRET )
193194 headers = {
194195 'bitvavo-access-key' : self .APIKEY ,
195196 'bitvavo-access-signature' : sig ,
@@ -205,7 +206,7 @@ def publicRequest(self, url):
205206 self .updateRateLimit (r .headers )
206207 return r .json ()
207208
208- def privateRequest (self , endpoint , postfix , body = {} , method = 'GET' ):
209+ def privateRequest (self , endpoint , postfix , body = None , method = 'GET' ):
209210 now = int (time .time () * 1000 )
210211 sig = createSignature (now , method , (endpoint + postfix ), body , self .APISECRET )
211212 url = self .base + endpoint + postfix
@@ -216,15 +217,8 @@ def privateRequest(self, endpoint, postfix, body = {}, method = 'GET'):
216217 'bitvavo-access-window' : str (self .ACCESSWINDOW ),
217218 }
218219 debugToConsole ("REQUEST: " + url )
219- if (method == 'GET' ):
220- r = requests .get (url , headers = headers , timeout = self .timeout )
221- elif (method == 'DELETE' ):
222- r = requests .delete (url , headers = headers , timeout = self .timeout )
223- elif (method == 'POST' ):
224- r = requests .post (url , headers = headers , json = body , timeout = self .timeout )
225- elif (method == 'PUT' ):
226- r = requests .put (url , headers = headers , json = body , timeout = self .timeout )
227- if ('error' in r .json ()):
220+ r = requests .request (method , url , headers = headers , json = body , timeout = self .timeout )
221+ if 'error' in r .json ():
228222 self .updateRateLimit (r .json ())
229223 else :
230224 self .updateRateLimit (r .headers )
0 commit comments