Skip to content

Commit f36f1f5

Browse files
authored
Update for Python3 & include CC API key option
1 parent c4e6c39 commit f36f1f5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

crypto_compare/apis/helper.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
import urllib2
2+
import urllib.request, urllib.error, urllib.parse
33

44
ALLOWED_KEYS = [
55
'fsym',
@@ -8,16 +8,19 @@
88
'tsyms',
99
'ts',
1010
'e',
11+
'limit',
1112
'markets',
1213
'extraParams',
1314
'sign',
15+
'tots',
16+
'toTs',
1417
'tryConversion',
1518
'calculationType'
1619
]
1720

1821
def _is_params_valid(self, **kwargs):
1922

20-
for key,value in kwargs.items():
23+
for key,value in list(kwargs.items()):
2124
if(value == None or value == ''):
2225
raise ValueError(key+' cannot be empty!')
2326

@@ -28,7 +31,7 @@ def _fetch_data(self, url):
2831

2932
print('Calling URL - ' + url)
3033

31-
json_response = json.load(urllib2.urlopen(url))
34+
json_response = json.load(urllib.request.urlopen(url))
3235

3336
if 'Response' in json_response and json_response["Response"] == 'Error':
3437
raise ValueError("API Error - {} !".format(json_response['Message']))
@@ -43,7 +46,7 @@ def _get_querystring(self, kwargs):
4346

4447
if kwargs is not None:
4548

46-
for key,value in kwargs.items():
49+
for key,value in list(kwargs.items()):
4750

4851
if key == "fsym" or key == "fsyms":
4952
fsym = value
@@ -53,4 +56,4 @@ def _get_querystring(self, kwargs):
5356
if key in ALLOWED_KEYS:
5457
querystring = "{}&{}".format(querystring, "{}={}".format(key, value))
5558

56-
return fsym, tsym, querystring
59+
return fsym, tsym, querystring + '&apikey=' + self.apikey

0 commit comments

Comments
 (0)