Advertisement
joric

mtgox all time high script

May 15th, 2012
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import json
  2. import time
  3. import datetime
  4. import urllib2
  5.  
  6. def fetch():
  7.  
  8.     start_tid = 130500
  9.     stop_tid = -1
  10.  
  11.     start_date = '2009-01-01'
  12.     stop_date = '2011-06-09'
  13.  
  14.     start_ts = int(time.mktime(time.strptime(start_date, '%Y-%m-%d')))
  15.     stop_ts = int(time.mktime(time.strptime(stop_date, '%Y-%m-%d')))
  16.  
  17.     r = { 'tid':start_tid, 'date':0 }
  18.  
  19.     arr = []
  20.  
  21.     while r['date'] < stop_ts:
  22.         url = 'https://mtgox.com/code/data/getTrades.php?since=' + str(r['tid'])
  23.         socket = urllib2.urlopen(url)
  24.         js = json.load(socket)
  25.         socket.close()
  26.         for r in js:
  27.             arr.append(r)
  28.  
  29.         arr.sort(key=lambda x:-float(x['price']))
  30.  
  31.         r = js[-1]
  32.  
  33.     for r in arr[0:100]:
  34.         print r['tid'], datetime.datetime.fromtimestamp(r['date']), r['amount'], r['item'], '@', r['price'], r['price_currency']
  35.  
  36. def main():
  37.     fetch()
  38.  
  39. if __name__ == '__main__':
  40.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement