44import time
55import hmac ,hashlib
66
7+ def createTimeStamp (datestr , format = "%Y-%m-%d %H:%M:%S" ):
8+ return time .mktime (time .strptime (datestr , format ))
9+
710class 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