Skip to content

Commit dd85f62

Browse files
committed
Update Cryptsy.py
Added new methods cancelMarketOrders and cancelAllOrders.
1 parent 4492fae commit dd85f62

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

Cryptsy.py

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

1212
def api_query(self, method, req={}):
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
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())
3229

3330
def getMarketData(self):
3431
return self.api_query("marketdata")
@@ -171,6 +168,20 @@ def cancelOrder(self, orderid):
171168
return self.api_query('cancelorder', {'orderid': orderid})
172169

173170

171+
# Inputs:
172+
# marketid Market ID for which you would like to cancel all open orders
173+
##
174+
# Outputs:
175+
# return Array for return information on each order cancelled
176+
def cancelMarketOrders(self, marketid):
177+
return self.api_query('cancelmarketorders', {'marketid': marketid})
178+
179+
180+
# Outputs:
181+
# return Array for return information on each order cancelled
182+
def cancelAllOrders(self):
183+
return self.api_query('cancelallorders')
184+
174185
# Inputs:
175186
# ordertype Order type you are calculating for (Buy/Sell)
176187
# quantity Amount of units you are buying/selling

0 commit comments

Comments
 (0)