Hello,
i'm trying to use the Kraken WEB API via a simple Python Script for placing Orders or getting the actual User Balance without !!! using any Kraken spec. Library.
Unfortunately i have no Chance to have success with this.
I'm using this method for the Bitstamp API without any Problems...
def BuyMarket(curr,amount):
client_id = xxx
api_key = xxx
api_secret = xxx
amount = round(amount, 8)
timestamp = str(int(round(time.time() * 1000)))
nonce = str(uuid.uuid4())
content_type = 'application/x-www-form-urlencoded'
payload = {'amount': amount}
if sys.version_info.major >= 3:
from urllib.parse import urlencode
else:
from urllib import urlencode
payload_string = urlencode(payload)
message = 'BITSTAMP ' + api_key + \
'POST' + \
'www.bitstamp.net' + \
'/api/v2/buy/market/' + curr +'/' + \
'' + \
content_type + \
nonce + \
timestamp + \
'v2' + \
payload_string
message = message.encode('utf-8')
signature = hmac.new(API_SECRET, msg=message, digestmod=hashlib.sha256).hexdigest()
headers = {
'X-Auth': 'BITSTAMP ' + api_key,
'X-Auth-Signature': signature,
'X-Auth-Nonce': nonce,
'X-Auth-Timestamp': timestamp,
'X-Auth-Version': 'v2',
'Content-Type': content_type
}
r = requests.post(
'https://www.bitstamp.net/api/v2/buy/market/' + curr +'/',
headers=headers,
data=payload_string
)
if not r.status_code == 200:
# raise Exception('Status code not 200')
raise Exception(r.status_code)
string_to_sign = (nonce + timestamp + r.headers.get('Content-Type')).encode('utf-8') + r.content
signature_check = hmac.new(API_SECRET, msg=string_to_sign, digestmod=hashlib.sha256).hexdigest()
if not r.headers.get('X-Server-Auth-Signature') == signature_check:
raise Exception('Signatures do not match')
log ("Place Market Buy Order - amount:" + str(amount) + " currencypair:"+curr+ " " + str(r.content) )
try:
OrderID=json.loads(r.text)["id"]
except:
OrderID="error"
return(OrderID)
Does anyone have an example Python Code who show's me how this would work for KRAKEN (Place Orders or get Balance...)
Thank a lot
Neuri