i found a test_urllib2.py on my disk is the same on yours or is this only a testversion?
I guess test_urllib2.py is a python script to test the urllib2 module, the real urllib2 is called urllib2.py. On a standard Linux distro you can most likely find it at /usr/lib/python2.[567]/urllib2.py (for python2.5 through 2.7). I have no clue about Windows or Mac.
i only want a history of the trades who gets automatically updated, where i could point my functions on...
and the possibility to trade
(and the whole thing in python)
The websocket API is the way to go. Install python-websocket from the Cheese Shop, then look at the documentation at the previous link I gave you.
The following is an extremely simple websocket client:
#!/usr/bin/env python
# -*- mode: python; coding: utf-8 -*-
import sys
import websocket
from sys import stdout, stderr
from datetime import datetime
MTGOX_WEBSOCKET_URI = 'ws://websocket.mtgox.com/mtgox'
GIMME_DEBUG = ('true', 't', 'yes', 'y', 'ja', 'j', 'on', '1')
def cb(ws, msg=None, fp=stdout):
if msg is not None:
log = '\t'.join([datetime.now().strftime('%F %T'), msg])
fp.write(log)
fp.write('\n')
fp.flush()
# end if
# end def cb
if os.environ.get('DEBUG', 'no').lower() in GIMME_DEBUG:
websocket.enableTrace(True)
else:
websocket.enableTrace(False)
# end if
if len(sys.argv) == 2:
wsuri = sys.argv[1]
else:
wsuri = MTGOX_WEBSOCKET_URI
# end if
ws = websocket.WebSocketApp(
wsuri,
on_open=lambda ws: cb(ws, 'opening %s' % wsuri, stderr),
on_close=lambda ws: cb(ws, 'closing %s' % wsuri, stderr),
on_message=cb,
on_error=lambda ws, msg=None: cb(ws, msg, stderr)
)
rc = 0
try:
ws.run_forever()
except (KeyboardInterrupt, SystemExit):
rc = 0
except Exception:
rc = 1
finally:
try:
ws.close()
except:
pass
# end if
# end if
sys.exit(rc)
# eof
Cheers,