Author

Topic: Mtgox V1 API Newb Question (Read 390 times)

newbie
Activity: 4
Merit: 0
May 09, 2013, 06:38:04 AM
#2
Problem solved, this can get axed.  For others with the same issue...

here is some good background on the request module and has a specific section on passing parameter in a url with a keyword argument.  You then need to urlencode your parameters.
 
http://docs.python-requests.org/en/latest/index.html
newbie
Activity: 4
Merit: 0
May 07, 2013, 09:51:28 AM
#1
I have been trying to figure out how to pass my parameters for the bid ask url to the MTGox V1 API with no luck.  Here is the code I am using. I have also tried to define the parameters within the class query function with no success as of yet.  Any help would be appreciated.

GOX_secret = removed
GOX_key = removed
 
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/BTCUSD/private/order/add?type=bid&amount_int=010000000&price_int=1099489" #this does not work

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


   def query(self, path, args={}, param={}):
      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
      }
    

      print url
      r = requests.post(url,data=args, headers=headers)
      print r.text

m = MTGox(GOX_key,GOX_secret)     
m.query("")
Jump to: