Skip to content

Commit a74cdde

Browse files
committed
Update Cryptsy.py
Implemented post processing of returns. If a datetime exists but not a timestamp then one will be generated based on the datetime.
1 parent 38d63fe commit a74cdde

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Cryptsy.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
import time
55
import hmac,hashlib
66

7+
def createTimeStamp(datestr, format="%Y-%m-%d %H:%M:%S"):
8+
return time.mktime(time.strptime(datestr, format))
9+
710
class Cryptsy:
811
def __init__(self, APIKey, Secret):
912
self.APIKey = APIKey
1013
self.Secret = Secret
1114

15+
def post_process(self, before):
16+
after = before
17+
18+
# Add timestamps if there isnt one but is a datetime
19+
if(isinstance(after['return'], list)):
20+
for x in xrange(0, len(after['return'])):
21+
if(isinstance(after['return'][x], dict)):
22+
if('datetime' in after['return'][x] and 'timestamp' not in after['return'][x]):
23+
after['return'][x]['timestamp'] = float(createTimeStamp(after['return'][x]['datetime']))
24+
25+
return after
26+
1227
def api_query(self, method, req={}):
1328
if(method=="marketdata" or method=="orderdata"):
1429
ret = urllib2.urlopen(urllib2.Request('https://www.cryptsy.com/api.php?method=' + method))
@@ -25,7 +40,8 @@ def api_query(self, method, req={}):
2540
}
2641

2742
ret = urllib2.urlopen(urllib2.Request('https://www.cryptsy.com/api', post_data, headers))
28-
return json.loads(ret.read())
43+
jsonRet = json.loads(ret.read())
44+
return self.post_process(jsonRet)
2945

3046
def getMarketData(self):
3147
return self.api_query("marketdata")

0 commit comments

Comments
 (0)