Bitcoin Forum
May 10, 2024, 05:15:51 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MtGox python wrapper  (Read 3087 times)
ezl (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 0


View Profile
May 21, 2011, 08: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


"With e-currency based on cryptographic proof, without the need to trust a third party middleman, money can be secure and transactions effortless." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715361351
Hero Member
*
Offline Offline

Posts: 1715361351

View Profile Personal Message (Offline)

Ignore
1715361351
Reply with quote  #2

1715361351
Report to moderator
1715361351
Hero Member
*
Offline Offline

Posts: 1715361351

View Profile Personal Message (Offline)

Ignore
1715361351
Reply with quote  #2

1715361351
Report to moderator
1715361351
Hero Member
*
Offline Offline

Posts: 1715361351

View Profile Personal Message (Offline)

Ignore
1715361351
Reply with quote  #2

1715361351
Report to moderator
wumpus
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
May 21, 2011, 08:22:09 AM
 #2

Thanks, that could certainly be useful.

Would it make sense to include the exchange APIs also in bitcoin-python?

Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
May 21, 2011, 09:11:41 AM
 #3

Cool!

Klaus Alexander Seistrup
theboos
Member
**
Offline Offline

Activity: 87
Merit: 10


View Profile
May 21, 2011, 02:48:52 PM
 #4

Whoa, thanks! I am literally right now working on a sort of extensible and automated MtGox desktop client in Python.
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
May 21, 2011, 02:50:22 PM
 #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,

Klaus Alexander Seistrup
cloon
Sr. Member
****
Offline Offline

Activity: 387
Merit: 250


View Profile
July 25, 2011, 05: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?

donations to 13zWUMSHA7AzGjqWmJNhJLYZxHmjNPKduY
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
July 25, 2011, 05: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,

Klaus Alexander Seistrup
cloon
Sr. Member
****
Offline Offline

Activity: 387
Merit: 250


View Profile
July 25, 2011, 07: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!

donations to 13zWUMSHA7AzGjqWmJNhJLYZxHmjNPKduY
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
July 25, 2011, 07: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,

Klaus Alexander Seistrup
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!