| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 38d63fe commit a74cdde
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,11 +4,26 @@ | |||
| 4 | 4 | import time | |
| 5 | 5 | import hmac,hashlib | |
| 6 | 6 | ||
| 7 | + def createTimeStamp(datestr, format="%Y-%m-%d %H:%M:%S"): | ||
| 8 | + return time.mktime(time.strptime(datestr, format)) | ||
| 9 | + | ||
| 7 | 10 | class Cryptsy: | |
| 8 | 11 | def __init__(self, APIKey, Secret): | |
| 9 | 12 | self.APIKey = APIKey | |
| 10 | 13 | self.Secret = Secret | |
| 11 | 14 | ||
| 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 | + | ||
| 12 | 27 | def api_query(self, method, req={}): | |
| 13 | 28 | if(method=="marketdata" or method=="orderdata"): | |
| 14 | 29 | ret = urllib2.urlopen(urllib2.Request('https://www.cryptsy.com/api.php?method=' + method)) | |
@@ -25,7 +40,8 @@ def api_query(self, method, req={}): | |||
| 25 | 40 | } | |
| 26 | 41 | ||
| 27 | 42 | 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) | ||
| 29 | 45 | ||
| 30 | 46 | def getMarketData(self): | |
| 31 | 47 | return self.api_query("marketdata") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments