Hey guys, I am writing a trading program that I need to connect to MtGox through the API v2. But I keep getting the following error:
URL: https://data.mtgox.com/api/2/BTCUSD/money/bitcoin/address
HTTP Error 403: ForbiddenI have contacted MtGox to make sure my account has the proper API access, and it does. I have created a couple different API keys, so I know I'm using the correct key + secret combination. The nonce is generated from the current time, so I know I have an ever increasing nonce. I'm relatively certain none of these items are an issue.
I got my python script from:
http://pastebin.com/aXQfULyq I modified that code a little bit to fit Python 3.3. However, I had to create 'Rest-Sign' slightly different than in the above code. Here is what I have:
url = self.__url_parts + '2/' + path
api2postdatatohash = (path + chr(0) + post_data).encode('utf-8') #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()).encode('utf-8'))
# Create header for auth-requiring operations
header = {
"User-Agent": 'Arbitrater',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
For comparison, here is what the other guy had:
url = self.__url_parts + '2/' + path
api2postdatatohash = path + chr(0) + post_data #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()))
# Create header for auth-requiring operations
header = {
"User-Agent": 'genBTC-bot',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
Notice how on my code, I had I had to encode my string to utf-8? I'm wondering if that is what is causing me to get that forbidden error. I don't know how the other guy got away without changing to utf-8, because the script won't run if you try to pass a string to b64encode or hmac.
Does anyone see what I am doing wrong? Have any of you guys had the same problem? Any help is appreciated. Here is my full python script if it is helpful:
http://pastebin.com/9fY8Jv15