I have serious problem with changing PHP sample code to equivalent in python. Here is an example PHP code:
function bitmarket_api($method, $params = array())
{
$key = "klucz_jawny";
$secret = "klucz_tajny";
$params["method"] = $method;
$params["tonce"] = time();
$post = http_build_query($params, "", "&");
$sign = hash_hmac("sha512", $post, $secret);
$headers = array(
"API-Key: " . $key,
"API-Hash: " . $sign,
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, "https://www.bitmarket.pl/api2/");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$ret = curl_exec($curl);
return json_decode($ret);
}
Thank you in advance for any help.
UPDATE:
My code is:
apiurl = "https://www.bitmarket.pl/api2/"
key = "mypubkey"
secret = "myceretkey"
apicommand = "info"
tonce = time.time()
params = str(apicommand) + " " + str(tonce)
postdata = (params + " " + "&")
signdata = hmac.new(postdata, secret, hashlib.sha512).hexdigest()
headerapi = { "API-Key: ": key,
"API-Hash: " : signdata}
getapi = requests.post(apiurl, data=headerapi ,params=postdata)
print getapi.text
Result: {"error":501,"errorMsg":"Invalid API key","time":1486049060}