Author

Topic: MtGox python wrapper (Read 3110 times)

hero member
Activity: 566
Merit: 500
Unselfish actions pay back better
July 25, 2011, 02:57:16 PM
#9

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.

Quote

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:

Code:
#!/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,
sr. member
Activity: 387
Merit: 250
July 25, 2011, 02:40:50 PM
#8
i found a test_urllib2.py on my disk is the same on yours or is this only a testversion?

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)

am i too stupid? ;-)
thx 4 your help!
hero member
Activity: 566
Merit: 500
Unselfish actions pay back better
July 25, 2011, 12:26:49 PM
#7

Sry for the noob question: what is urllib, urllib2 and json?

urllib, urllib2 and json are all python modules that should be available in any standard python distro.  If not, you can get them from the Cheese Shop.

Quote

i've no idea, how i can link it with Mtgox and how to get every trade data into phython.

Mt. Gox has a websocket API that gives you near real-time streaming trade data.

Cheers,
sr. member
Activity: 387
Merit: 250
July 25, 2011, 12:11:10 PM
#6
Great!
Sry for the noob question: what is urllib, urllib2 and json?
how can i get and use it?

I know how to make a bot more complex (getting more deciding functions) but i've no idea, how i can link it with Mtgox and how to get every trade data into phython.
who knows it?
hero member
Activity: 566
Merit: 500
Unselfish actions pay back better
May 21, 2011, 09:50:22 AM
#5

I am literally right now working on a sort of extensible and automated MtGox desktop client in Python.

Sounds very interresting.  Please give us a shout when you have something working that you'd like to share.

Cheers,
member
Activity: 87
Merit: 10
May 21, 2011, 09:48:52 AM
#4
Whoa, thanks! I am literally right now working on a sort of extensible and automated MtGox desktop client in Python.
hero member
Activity: 566
Merit: 500
Unselfish actions pay back better
May 21, 2011, 04:11:41 AM
#3
Cool!
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
May 21, 2011, 03:22:09 AM
#2
Thanks, that could certainly be useful.

Would it make sense to include the exchange APIs also in bitcoin-python?
ezl
newbie
Activity: 13
Merit: 0
May 21, 2011, 03:18:44 AM
#1
Wrote this for myself so I could work on some automated trading strategies.  Sharing it in case anyone else in the community is interested:

https://github.com/ezl/mtgox/blob/master/mtgox.py


Jump to: