@@ -18,9 +18,8 @@ def __init__(self, key: str='', secret: str='', url: str='', futures: bool=False
1818 self ._api_v = ''
1919 if url : self .url = url
2020 elif futures :
21- if sandbox : self .url = 'https://demo-futures.kraken.com/derivatives'
22- else : self .url = 'https://futures.kraken.com/derivatives'
23- self ._api_v = '/api/v3'
21+ if sandbox : self .url = 'https://demo-futures.kraken.com'
22+ else : self .url = 'https://futures.kraken.com'
2423 raise ValueError ('Futures endpoints and clients not implemented yet.' )
2524 else :
2625 self .url = 'https://api.kraken.com'
@@ -32,7 +31,6 @@ def __init__(self, key: str='', secret: str='', url: str='', futures: bool=False
3231 def _request (self , method : str , uri : str , timeout : int = 10 , auth : bool = True , params : dict = {}, do_json : bool = False , return_raw : bool = False ):
3332 uri_path = uri
3433 data_json = ''
35- params ['nonce' ] = str (int (time .time ()* 1000 )) # generate nonce
3634
3735 if method .upper () in ['GET' , 'DELETE' ]:
3836 if params :
@@ -46,6 +44,7 @@ def _request(self, method: str, uri: str, timeout: int=10, auth: bool=True, para
4644 headers = {}
4745 if auth :
4846 if not self .key or self .key == '' or not self .secret or self .secret == '' : raise ValueError ('Missing credentials' )
47+ params ['nonce' ] = str (int (time .time ()* 1000 )) # generate nonce
4948 headers = {
5049 'Content-Type' : 'application/x-www-form-urlencoded; charset=utf-8' ,
5150 'API-Key' : self .key ,
@@ -55,10 +54,10 @@ def _request(self, method: str, uri: str, timeout: int=10, auth: bool=True, para
5554 headers ['User-Agent' ] = 'Kraken-Python-SDK'
5655 url = f'{ self .url } { self ._api_v } { uri } '
5756
58- #logging.info(f'Request: {url}')
57+ # logging.info(f'Request: {url}')
5958
6059 if method in ['GET' , 'DELETE' ]:
61- response_data = requests .request (method , url , headers = headers , timeout = timeout )
60+ return self . check_response_data ( requests .request (method , url , headers = headers , timeout = timeout ), return_raw )
6261 else :
6362 if do_json :
6463 return self .check_response_data (requests .request (method , url , headers = headers , json = params , timeout = timeout ), return_raw )
@@ -83,10 +82,10 @@ def check_response_data(response_data, return_raw: bool=False):
8382 except ValueError :
8483 raise Exception (response_data .content )
8584 else :
86- if len ( data . get ( 'error' )) == 0 :
87- if data .get ('result' ): return data ['result' ]
88- else : return data
89- else : raise Exception ( f' { response_data . status_code } - { response_data . text } ' )
85+ if 'error' in data :
86+ if len ( data . get ( 'error' )) == 0 and data .get ('result' ): return data ['result' ]
87+ else : raise Exception ( f' { response_data . status_code } - { response_data . text } ' )
88+ else : return data
9089 else : raise Exception (f'{ response_data .status_code } -{ response_data .text } ' )
9190
9291 @property
0 commit comments