Skip to content

Commit 4492fae

Browse files
committed
Update Cryptsy.py
1 parent 94da6d8 commit 4492fae

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

Cryptsy.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ def __init__(self, APIKey, Secret):
1010
self.Secret = Secret
1111

1212
def api_query(self, method, req={}):
13-
if(method=="marketdata" or method=="orderdata"):
14-
ret = urllib2.urlopen(urllib2.Request('https://www.cryptsy.com/api.php?method=' + method))
15-
return json.loads(ret.read())
16-
else:
17-
req['method'] = method
18-
req['nonce'] = int(time.time())
19-
post_data = urllib.urlencode(req)
20-
21-
sign = hmac.new(self.Secret, post_data, hashlib.sha512).hexdigest()
22-
headers = {
23-
'Sign': sign,
24-
'Key': self.APIKey
25-
}
26-
27-
ret = urllib2.urlopen(urllib2.Request('https://www.cryptsy.com/api', post_data, headers))
28-
return json.loads(ret.read())
13+
try:
14+
if(method=="marketdata" or method=="orderdata"):
15+
ret = urllib2.urlopen(urllib2.Request('https://www.cryptsy.com/api.php?method=' + method))
16+
return json.loads(ret.read())
17+
else:
18+
req['method'] = method
19+
req['nonce'] = int(time.time())
20+
post_data = urllib.urlencode(req)
21+
22+
sign = hmac.new(self.Secret, post_data, hashlib.sha512).hexdigest()
23+
headers = {
24+
'Sign': sign,
25+
'Key': self.APIKey
26+
}
27+
28+
ret = urllib2.urlopen(urllib2.Request('https://www.cryptsy.com/api', post_data, headers))
29+
return json.loads(ret.read())
30+
except:
31+
return None
2932

3033
def getMarketData(self):
3134
return self.api_query("marketdata")

0 commit comments

Comments
 (0)