osmosis (OP)
|
|
October 25, 2011, 06:37:56 AM |
|
The wiki has a mtgox authentication example in PHP. Anyone out there have an example they can provide for python? I have been trying to get goxsh.py to work with no luck. https://en.bitcoin.it/wiki/MtGox/API
|
|
|
|
kokjo
Legendary
Offline
Activity: 1050
Merit: 1000
You are WRONG!
|
|
October 25, 2011, 06:52:50 AM |
|
from urllib import urlencode import urllib2 import time from hashlib import sha512 from hmac import HMAC import base64 import json def get_nonce(): return int(time.time()*100000)
def sign_data(secret, data): return base64.b64encode(str(HMAC(secret, data, sha512).digest())) class requester: def __init__(self, auth_key, auth_secret): self.auth_key = auth_key self.auth_secret = base64.b64decode(auth_secret) def build_query(self, req={}): req["nonce"] = get_nonce() post_data = urlencode(req) headers = {} headers["User-Agent"] = "GoxApi" headers["Rest-Key"] = self.auth_key headers["Rest-Sign"] = sign_data(self.auth_secret, post_data) return (post_data, headers) def perform(self, path, args): data, headers = self.build_query(args) req = urllib2.Request("https://mtgox.com/api/0/"+path, data, headers) res = urllib2.urlopen(req, data) return json.load(res)
|
"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
|
|
|
osmosis (OP)
|
|
October 26, 2011, 05:36:27 AM |
|
THANKS!
|
|
|
|
kokjo
Legendary
Offline
Activity: 1050
Merit: 1000
You are WRONG!
|
|
October 26, 2011, 07:42:56 AM |
|
THANKS!
please consider to donate, so i am motivated to helping more people.
|
"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
|
|
|
molecular
Donator
Legendary
Offline
Activity: 2772
Merit: 1019
|
|
January 10, 2012, 07:01:17 PM |
|
from urllib import urlencode import urllib2 import time from hashlib import sha512 from hmac import HMAC import base64 import json def get_nonce(): return int(time.time()*100000)
def sign_data(secret, data): return base64.b64encode(str(HMAC(secret, data, sha512).digest())) class requester: def __init__(self, auth_key, auth_secret): self.auth_key = auth_key self.auth_secret = base64.b64decode(auth_secret) def build_query(self, req={}): req["nonce"] = get_nonce() post_data = urlencode(req) headers = {} headers["User-Agent"] = "GoxApi" headers["Rest-Key"] = self.auth_key headers["Rest-Sign"] = sign_data(self.auth_secret, post_data) return (post_data, headers) def perform(self, path, args): data, headers = self.build_query(args) req = urllib2.Request("https://mtgox.com/api/0/"+path, data, headers) res = urllib2.urlopen(req, data) return json.load(res) cool, this helped speed things up, thanks. Donation address?
|
PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0 3F39 FC49 2362 F9B7 0769
|
|
|
kokjo
Legendary
Offline
Activity: 1050
Merit: 1000
You are WRONG!
|
|
January 10, 2012, 07:22:37 PM |
|
cool, this helped speed things up, thanks.
Donation address?
1JpsKmkim7REYq2EWE5aEXG8YN4zJTTX16 thanks
|
"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
|
|
|
osmosis (OP)
|
|
January 10, 2012, 07:27:13 PM |
|
THANKS!
please consider to donate, so i am motivated to helping more people. thx kokjo
|
|
|
|
kokjo
Legendary
Offline
Activity: 1050
Merit: 1000
You are WRONG!
|
|
January 10, 2012, 07:34:28 PM |
|
im amazed it actually works. it was something i wrote up, in like 10 min.
|
"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
|
|
|
molecular
Donator
Legendary
Offline
Activity: 2772
Merit: 1019
|
|
January 11, 2012, 02:51:52 AM |
|
I'm also amazed.
looked at goxsh python impl a while back and I couldn't even figure out wtf was going on...
your solution: drop 2 functions into my sources, change 2-3 lines => switched from user/pass to api key auth.
thanks kokjo, sent a nickle
|
PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0 3F39 FC49 2362 F9B7 0769
|
|
|
finway
|
|
January 11, 2012, 05:58:22 AM |
|
mark.
|
|
|
|
Ente
Legendary
Offline
Activity: 2126
Merit: 1001
|
|
January 28, 2012, 12:20:40 PM |
|
from urllib import urlencode import urllib2 import time from hashlib import sha512 from hmac import HMAC import base64 import json def get_nonce(): return int(time.time()*100000)
def sign_data(secret, data): return base64.b64encode(str(HMAC(secret, data, sha512).digest())) class requester: def __init__(self, auth_key, auth_secret): self.auth_key = auth_key self.auth_secret = base64.b64decode(auth_secret) def build_query(self, req={}): req["nonce"] = get_nonce() post_data = urlencode(req) headers = {} headers["User-Agent"] = "GoxApi" headers["Rest-Key"] = self.auth_key headers["Rest-Sign"] = sign_data(self.auth_secret, post_data) return (post_data, headers) def perform(self, path, args): data, headers = self.build_query(args) req = urllib2.Request("https://mtgox.com/api/0/"+path, data, headers) res = urllib2.urlopen(req, data) return json.load(res) Thank you a lot for posting this! Uh, python newbie question: How to use that class? I tried: key = "12345" secret = "1234567890" path = "info.php" args = "123"
tuer = requester(key,secret) tuer.perform(path,args) (key and secret replaced) Dropped error: Traceback (most recent call last): File "./auth.py", line 48, in <module> tuer.perform(path,args) File "./auth.py", line 33, in perform data, headers = self.build_query(args) File "./auth.py", line 24, in build_query req["nonce"] = get_nonce() TypeError: 'str' object does not support item assignment
By the way, what goes in the "args" when none are needed, like when fetching "info"? Ah, success comes in tiny, bloody steps.. Ente
|
|
|
|
kokjo
Legendary
Offline
Activity: 1050
Merit: 1000
You are WRONG!
|
|
January 28, 2012, 12:44:58 PM |
|
from urllib import urlencode import urllib2 import time from hashlib import sha512 from hmac import HMAC import base64 import json def get_nonce(): return int(time.time()*100000)
def sign_data(secret, data): return base64.b64encode(str(HMAC(secret, data, sha512).digest())) class requester: def __init__(self, auth_key, auth_secret): self.auth_key = auth_key self.auth_secret = base64.b64decode(auth_secret) def build_query(self, req={}): req["nonce"] = get_nonce() post_data = urlencode(req) headers = {} headers["User-Agent"] = "GoxApi" headers["Rest-Key"] = self.auth_key headers["Rest-Sign"] = sign_data(self.auth_secret, post_data) return (post_data, headers) def perform(self, path, args): data, headers = self.build_query(args) req = urllib2.Request("https://mtgox.com/api/0/"+path, data, headers) res = urllib2.urlopen(req, data) return json.load(res) Thank you a lot for posting this! Uh, python newbie question: How to use that class? I tried: key = "12345" secret = "1234567890" path = "info.php" args = "123"
tuer = requester(key,secret) tuer.perform(path,args) (key and secret replaced) Dropped error: Traceback (most recent call last): File "./auth.py", line 48, in <module> tuer.perform(path,args) File "./auth.py", line 33, in perform data, headers = self.build_query(args) File "./auth.py", line 24, in build_query req["nonce"] = get_nonce() TypeError: 'str' object does not support item assignment
By the way, what goes in the "args" when none are needed, like when fetching "info"? Ah, success comes in tiny, bloody steps.. Ente args is a dict. args = {"someparameter": "value of the parameter"}, thats why it does not work.
|
"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
|
|
|
Ente
Legendary
Offline
Activity: 2126
Merit: 1001
|
|
January 28, 2012, 01:31:37 PM |
|
args is a dict. args = {"someparameter": "value of the parameter"}, thats why it does not work.
Haha I really an a noob! :-) Thank you, kokjo! *flips a coin in your direction* Ente
|
|
|
|
kokjo
Legendary
Offline
Activity: 1050
Merit: 1000
You are WRONG!
|
|
January 28, 2012, 01:33:03 PM |
|
args is a dict. args = {"someparameter": "value of the parameter"}, thats why it does not work.
Haha I really an a noob! :-) Thank you, kokjo! *flips a coin in your direction* Ente thank you.
|
"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
|
|
|
molecular
Donator
Legendary
Offline
Activity: 2772
Merit: 1019
|
|
January 28, 2012, 09:01:14 PM |
|
args is a dict. args = {"someparameter": "value of the parameter"}, thats why it does not work.
As much as I like python, but one has to admit that languages that use static typing do have certain advantages.
|
PGP key molecular F9B70769 fingerprint 9CDD C0D3 20F8 279F 6BE0 3F39 FC49 2362 F9B7 0769
|
|
|
Ente
Legendary
Offline
Activity: 2126
Merit: 1001
|
|
January 31, 2012, 01:46:42 PM |
|
ah, here comes my next stumbling block: (still Python, still with the code kokjo was so nice to post) How do I cancel an order? I only found old-api-examples (the apt where you POST your credentials directly). Is it even possible with the newer api? It expects: #POST data: oid=#&type=# #oid: Order ID #type: 1 for sell order or 2 for buy order For example: OID=123asd-123-etz-1542-12947 Type=1 123asd-123-etz-1542-12947=1 How do I pass this string into the "args" variable? Stupid.. everything else (get info, get orders, buy, sell) works as simple as passing the arguments as a JSON to the .php. Do I have to rewrite it all just for this single "cancel" order? Or is it only possible with the old API altogether, which will be deactivated in some weeks? ..being noobish again: Ente edit: I would expect something as easy as this to work: path_cancel = "0/cancelOrder.php" oid = "123-124-124-124" typ = "1" args_cancel = {oid: typ}
|
|
|
|
kokjo
Legendary
Offline
Activity: 1050
Merit: 1000
You are WRONG!
|
|
January 31, 2012, 02:03:03 PM |
|
args = {"oid": "123-456-bla-bla", "type":"1"} notice the "" around the 1, AFAIK does urlencode not take numbers, only strings.
|
"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
|
|
|
Ente
Legendary
Offline
Activity: 2126
Merit: 1001
|
|
January 31, 2012, 02:12:38 PM |
|
Yea, works, great! :-) Actually I had the "1" in "", my mistake was even more silly. I did: expected is: {"oid": "123-456-bla-bla", "type":"1"} Thanks mate, again! Ente edit: wiki says . I just read that wrong. This is the moment where I really sense the value in programming languages. What the speaker says is what the listener will understand. Without two "but I meant.." in between!
|
|
|
|
DBordello
|
|
February 10, 2012, 01:25:19 AM |
|
I am having difficulty getting this to work. Here is the code I am using. Any thoughts? I am getting not logged in errors. def test(): key = 'x' secret = 'x' path = "info.php" args = {}
tuer = requester(key,secret) r = tuer.perform(path,args) print r #### MT Gox Code #### from urllib import urlencode import urllib2 import time from hashlib import sha512 from hmac import HMAC import base64 import json def get_nonce(): return int(time.time()*100000)
def sign_data(secret, data): return base64.b64encode(str(HMAC(secret, data, sha512).digest())) class requester: def __init__(self, auth_key, auth_secret): self.auth_key = auth_key self.auth_secret = base64.b64decode(auth_secret) def build_query(self, req={}): req["nonce"] = get_nonce() post_data = urlencode(req) headers = {} headers["User-Agent"] = "GoxApi" headers["Rest-Key"] = self.auth_key headers["Rest-Sign"] = sign_data(self.auth_secret, post_data) return (post_data, headers) def perform(self, path, args): data, headers = self.build_query(args) req = urllib2.Request("https://mtgox.com/api/0/"+path, data, headers) res = urllib2.urlopen(req, data) return json.load(res)
|
www.BTCPak.com - Exchange your bitcoins for MP: Secure, Anonymous and Easy!
|
|
|
Waam
Newbie
Offline
Activity: 21
Merit: 0
|
|
February 19, 2012, 05:17:06 AM |
|
I am having difficulty getting this to work. Here is the code I am using. Any thoughts? I am getting not logged in errors. def test(): key = 'x' secret = 'x' path = "info.php" args = {}
tuer = requester(key,secret) r = tuer.perform(path,args) print r #### MT Gox Code #### from urllib import urlencode import urllib2 import time from hashlib import sha512 from hmac import HMAC import base64 import json def get_nonce(): return int(time.time()*100000)
def sign_data(secret, data): return base64.b64encode(str(HMAC(secret, data, sha512).digest())) class requester: def __init__(self, auth_key, auth_secret): self.auth_key = auth_key self.auth_secret = base64.b64decode(auth_secret) def build_query(self, req={}): req["nonce"] = get_nonce() post_data = urlencode(req) headers = {} headers["User-Agent"] = "GoxApi" headers["Rest-Key"] = self.auth_key headers["Rest-Sign"] = sign_data(self.auth_secret, post_data) return (post_data, headers) def perform(self, path, args): data, headers = self.build_query(args) req = urllib2.Request("https://mtgox.com/api/0/"+path, data, headers) res = urllib2.urlopen(req, data) return json.load(res) key =, etc are variables -- They need to be declared outside of a function. imports/froms should be before any other syntax. Let me know if you need any more help and I can post my working script (up to Authentication, I wouldn't want to do the work for ya.)
|
|
|
|
|