Bitcoin Forum
July 02, 2024, 07:59:04 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Mtgox V1 API Newb Question  (Read 368 times)
dkstar (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
May 07, 2013, 02:51:28 PM
 #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("")
dkstar (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
May 09, 2013, 11: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
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!