Bitcoin Forum
May 25, 2024, 03:15:49 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MtGox with python  (Read 2424 times)
btcmind (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


View Profile
April 16, 2013, 08:30:08 AM
Last edit: April 16, 2013, 11:55:48 AM by btcmind
 #1

I'm going to a create trading app in python. Might opensource later. I've got connections to all exchanges and will create an abstraction layer, adding some GUI fancies, storage in database, strategy layer etc. Anyone in? Then PM me.

Here is a collection of code bases and snippets.

https://bitbucket.org/nitrous/mtgox-api/overview
http://pastebin.com/aXQfULyq
https://github.com/maxme/bitcoin-arbitrage
https://github.com/viorels/mtgox-trader
https://github.com/prof7bit/goxtool (Websockets and SocketIO)

https://github.com/ezl/mtgox (2years old)
https://github.com/goncalopp/python-mtgox (API v0)
btcmind (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


View Profile
April 16, 2013, 09:12:17 AM
 #2

Working python2.7, API v1

Quote
GOX_secret = '==================================================='
GOX_key = '==============='

from hashlib import sha512
from hmac import HMAC
from base64 import b64decode, b64encode
from urllib import urlencode

from time import time

import requests

url = "https://data.mtgox.com/api/1/generic/info"

class MTGox:
   def __init__(self, key, secret):
      self.key = key
      self.secret = b64decode(secret)
      #self.base = base

   def query(self, path, args={}):
      args['nonce'] = int(time()*100000)
      sign = b64encode(str(HMAC(self.secret, urlencode(args), sha512).digest()))
      print sign

      headers = {
         'User-Agent': 'BitcoinTalk',
         'Rest-Key': self.key,
         'Rest-Sign': sign
      }
      #url = self.base + path
      print url
      r = requests.post(url, data=args, headers=headers)
      print r.text

m = MTGox(GOX_key,GOX_secret)      
m.query("")
btcmind (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


View Profile
April 16, 2013, 09:24:52 AM
 #3

printing the balance

Quote
m = MTGox(GOX_key,GOX_secret)      
r = m.query("")
d = json.loads(r)

btcbalance = float(d['return']['Wallets']['BTC']['Balance']['value'])
usdbalance = float(d['return']['Wallets']['USD']['Balance']['value'])

print 'Balance %6.2f BTC   %6.2f USD'%(btcbalance,usdbalance)
btc_lurker
Member
**
Offline Offline

Activity: 78
Merit: 10



View Profile
April 16, 2013, 04:41:08 PM
 #4

The HTTP API is a lot easier to use, but is there any advantage over the streaming API ? Initially it might be a little harder to create a proper streaming API (there is at least one you listed there, but it doesn't fully use the messages and discard some data that might be relevant; I also have one running here, but it is not public at this point), but to me it looks like to be a much better choice since you will be getting results as soon as they are available, basicly. With the HTTP API you need a pooling loop that might do nothing a lot of times, with the streaming API you have an infinite loop that blocks as long as there is no new information.

Now, are you aware if all the current bitcoin exchanges provide an API ? It would be great to collect data from all the different exchanges.
phorensic
Hero Member
*****
Offline Offline

Activity: 630
Merit: 500



View Profile
April 16, 2013, 06:33:07 PM
 #5

Have you seen this?  https://github.com/ahihi/goxsh
I've been using an older version of it forever.  Decided to use it as my baseline to create a similar app for BTC-E trading.
btcmind (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


View Profile
April 16, 2013, 09:41:55 PM
 #6

Datastorage: good idea. Anyone in, for a team effort collecting data? Somebody even postet market depth (300MB). Haven't checked it. Links welcome, I will have a look at it and write some sanity checks. If somebody tells me how I can store 1-2 GB anonymously.

Goxtools uses websockets and socketIO and is well coded.

btcmind (OP)
Member
**
Offline Offline

Activity: 98
Merit: 10


View Profile
April 18, 2013, 03:43:12 PM
 #7

Anyone who wants to contribute shoot me a PM. This will be private as of now. There is ample opportunity to contribute. I will give intros how to get things running to people who give back.
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!