Kraken api - get token with python
Kraken api - get token with python
```python
import time
import base64
import hashlib
import hmac
import urllib.request
import json
# Replace with your Kraken API public and private keys
api_key = 'YOUR_API_PUBLIC_KEY'
api_secret = 'YOUR_API_PRIVATE_KEY'
# API endpoint and parameters
api_path = '/0/private/GetWebSocketsToken'
api_nonce = str(int(time.time() * 1000))
api_post = 'nonce=' + api_nonce
# Create the SHA256 hash
api_sha256 = hashlib.sha256(api_nonce.encode('utf-8') + api_post.encode('utf-8')).digest()
# Create the HMAC signature
api_hmac = hmac.new(base64.b64decode(api_secret), api_path.encode('utf-8') + api_sha256, hashlib.sha512)
api_signature = base64.b64encode(api_hmac.digest())
# Create the request
api_request = urllib.request.Request('https://api.kraken.com' + api_path, api_post.encode('utf-8'))
api_request.add_header('API-Key', api_key)
api_request.add_header('API-Sign', api_signature)
# Send the request and get the response
api_response = urllib.request.urlopen(api_request).read().decode()
token = json.loads(api_response)['result']['token']
print('WebSocket Token:', token)
```
Make sure to replace `'YOUR_API_PUBLIC_KEY'` and `'YOUR_API_PRIVATE_KEY'` with your actual Kraken API keys. This script will generate a WebSocket authentication token that you can use for private feeds¹.
If you need more examples or have any specific requirements, feel free to ask!
원본: Copilot과의 대화, 2024. 11. 2.
(1) How to retrieve a WebSocket authentication token - Example code in Python 3 | Kraken. https://support.kraken.com/hc/articles/360034437672-How-to-retrieve-a-WebSocket-authentication-token-Example-code-in-Python-3.
(2) veox/python3-krakenex: REST Exchange API for Kraken.com, Python 3 - GitHub. https://github.com/veox/python3-krakenex.
(3) REST API command line client (Python) - Kraken. https://support.kraken.com/hc/en-us/articles/360025180232-REST-API-command-line-client-Python-.
(4) Spot REST Authentication | Kraken API Center. https://docs.kraken.com/api/docs/guides/spot-rest-auth/.
(5) undefined. https://api.kraken.com/0/private/GetWebSocketsToken.
댓글
댓글 쓰기