Bitcoin Forum
May 04, 2024, 02:08:51 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Improved Python code for MTGox API (HTTP auth)  (Read 1734 times)
knite (OP)
Newbie
*
Offline Offline

Activity: 33
Merit: 0


View Profile
March 29, 2012, 01:06:27 AM
 #1

I found this thread to be extremely helpful, so I'm returning the favor by posting an improved and simplified version of the code. Unfortunately, my forum account is limited to the Newbie section. Mods, please move this post to the thread above.
Code:
from hashlib import sha512
from hmac import HMAC
from base64 import b64decode, b64encode
from urllib import urlencode

from time import time

import requests

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

def query(self, path, args={}):
args['nonce'] = int(time()*100000)
headers = {
'User-Agent': 'BitcoinTalk',
'Rest-Key': self.key,
'Rest-Sign': b64encode(str(HMAC(self.secret, urlencode(args), sha512).digest()))
}
r = requests.post(self.base + path, data=args, headers=headers)
print r.text
1714788531
Hero Member
*
Offline Offline

Posts: 1714788531

View Profile Personal Message (Offline)

Ignore
1714788531
Reply with quote  #2

1714788531
Report to moderator
1714788531
Hero Member
*
Offline Offline

Posts: 1714788531

View Profile Personal Message (Offline)

Ignore
1714788531
Reply with quote  #2

1714788531
Report to moderator
1714788531
Hero Member
*
Offline Offline

Posts: 1714788531

View Profile Personal Message (Offline)

Ignore
1714788531
Reply with quote  #2

1714788531
Report to moderator
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
TheStig
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile
March 29, 2012, 01:21:44 AM
 #2

I posted it in that thread for you.

Ente
Legendary
*
Offline Offline

Activity: 2126
Merit: 1001



View Profile
March 29, 2012, 07:46:22 AM
 #3

Thank you, both!

Your code is for using the old http api to do commands?
I ask since now you can use the (more or less) same commands over the streaming api too..

I may find you the thread for this if interested.

Ente
knite (OP)
Newbie
*
Offline Offline

Activity: 33
Merit: 0


View Profile
March 29, 2012, 04:00:21 PM
 #4

Your code is for using the old http api to do commands?
I ask since now you can use the (more or less) same commands over the streaming api too..

Yes, this is for the HTTP API. It's much simpler to implement than the streaming API. It's also good to have a backup, as reports suggest the streaming API is somewhat unstable. I'm rewriting the streaming code from here as well.
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!