All
Lọc theo:
Tôi có thể nạp tiền mặt vào tài khoản của mình bằng cách nào?
Tôi cần trợ giúp xác minh tài khoản
Tại sao tôi không thể truy cập vào tài khoản của mình?
Có phí rút tiền điện tử không?
Tôi cần trợ giúp để đăng nhập vào tài khoản của tôi
Xin lưu ý rằng thông tin dưới đây giả định việc triển khai chính xác Thuật toán xác thực của chúng tôi vì nó liên quan đến các lỗi đầu vào và định dạng tiềm ẩn.
Để tìm hiểu thêm về Thuật toán xác thực của chúng tôi, vui lòng nhấp vào ĐÂY
Để thực hiện một cuộc gọi riêng tư thành công, một yêu cầu HTTP POST cần được gửi đến điểm cuối thích hợp.
Yêu cầu này bao gồm Tiêu đề API-Sign (chữ ký) sử dụng Post_data được mã hóa như một phần của thuật toán băm.
Nếu có sự khác biệt giữa Chữ ký được bao gồm trong tiêu đề và dữ liệu POST được bao gồm trong yêu cầu, lỗi Khóa API không hợp lệ sẽ được trả về.
Dưới đây là ví dụ về một cuộc gọi được định dạng chính xác trong đó dữ liệu được sử dụng trong Thuật toán xác thực khớp với dữ liệu trong phần thân của yêu cầu:
Python
#!/usr/bin/env python3
import time
import requests
import urllib.parse
import hashlib
import hmac
import base64
api_key = ''
secret_key = ''
nonce = str(int(1000 * time.time()))
# Define the URI path for the Kraken API request
uri_path = '/0/private/AddOrder'
# API URL
api_url = 'https://api.kraken.com'
# Create a dictionary for the request data
# Note that this is the data that will be used to calculate the Authentication Algorithm (API-Sign).
data = {
'nonce': nonce,
'ordertype': 'limit',
'type': 'buy',
'volume': '1',
'pair': 'btcusd',
'price': '58626.4',
'validate': True
}
# Encode the data for the request
postdata = urllib.parse.urlencode(data)
encoded = (str(data['nonce']) + postdata).encode()
# Create a message to be signed
message = uri_path.encode() + hashlib.sha256(encoded).digest()
# Create the HMAC signature
mac = hmac.new(base64.b64decode(secret_key), message, hashlib.sha512)
sigdigest = base64.b64encode(mac.digest())
# Create headers for the request
headers = {}
headers['API-Key'] = api_key
headers['API-Sign'] = sigdigest.decode()
# Make the POST request
# Note that the data below is what is sent in the HTTP request.
req = requests.post(api_url + uri_path, headers=headers, data={
'nonce': nonce,
'ordertype': 'limit',
'type': 'buy',
'volume': '1',
'pair': 'btcusd',
'price': '58626.4',
'validate': True
})
# Print the result
print(req.json())
# Result:
# {'error': [], 'result': {'descr': {'order': 'buy 1.00000000 XBTUSD @ limit 58626.4'}}}Tuy nhiên, khi loại lệnh (ordertype) và khối lượng (volume) bị hoán đổi, lỗi Khóa không hợp lệ sẽ xảy ra.
Python
#!/usr/bin/env python3
import time
import requests
import urllib.parse
import hashlib
import hmac
import base64
api_key = ''
secret_key = ''
nonce = str(int(1000 * time.time()))
# Define the URI path for the Kraken API request
uri_path = '/0/private/AddOrder'
# API URL
api_url = 'https://api.kraken.com'
# Create a dictionary for the request data
data = {
'nonce': nonce,
'ordertype': 'limit',
'type': 'buy',
'volume': '1',
'pair': 'btcusd',
'price': '58626.4',
'validate': True
}
# Encode the data for the request
postdata = urllib.parse.urlencode(data)
encoded = (str(data['nonce']) + postdata).encode()
# Create a message to be signed
message = uri_path.encode() + hashlib.sha256(encoded).digest()
# Create the HMAC signature
mac = hmac.new(base64.b64decode(secret_key), message, hashlib.sha512)
sigdigest = base64.b64encode(mac.digest())
# Create headers for the request
headers = {}
headers['API-Key'] = api_key
headers['API-Sign'] = sigdigest.decode()
# Make the POST request
req = requests.post(api_url + uri_path, headers=headers, data={
'nonce': nonce,
'volume': '1',
'type': 'buy',
'ordertype': 'limit',
'volume': '1',
'pair': 'btcusd',
'price': '58626.4',
'validate': True
})
# Print the result
print(req.json())
# Result:
# {'error': ['EAPI:Invalid key']}Một dấu hiệu cho thấy đây có thể là nguyên nhân gây ra lỗi Khóa không hợp lệ là nếu các cuộc gọi đến các điểm cuối không yêu cầu nhiều tham số thành công (Số dư, Lệnh mở). Nếu bạn liên tục nhận được phản hồi hợp lệ từ các cuộc gọi này, thì lý thuyết không khớp có vẻ hợp lý hơn.
*Xin lưu ý rằng trong ví dụ trên, Tham số xác thực đã được sử dụng chỉ để xác thực đầu vào mà không gửi lệnh. Tham số này nên được loại bỏ khi giao dịch trực tiếp*
Việc không khớp giữa loại nội dung của phần thân và tiêu đề cũng có thể dẫn đến Khóa API không hợp lệ.
Vui lòng xem bên dưới một kịch bản trong đó cả Tiêu đề và dữ liệu Post đều được mã hóa URL:
Python
api_key = ""
api_secret = base64.b64decode("")
api_domain = "https://api.kraken.com"
api_path = "/0/private/"
api_endpoint = "Balance" # {"error":[]} IS SUCCESS-EMPTY BALANCE
api_parameters = ""
api_nonce = str(int(time.time() * 1000))
api_postdata = api_parameters + "&nonce=" + api_nonce
api_postdata = api_postdata.encode('utf-8')
api_sha256Data = api_nonce.encode('utf-8') + api_postdata
api_sha256 = hashlib.sha256(api_sha256Data).digest()
api_hmacSha512Data = api_path.encode('utf-8') + api_endpoint.encode('utf-8') + api_sha256
api_hmacsha512 = hmac.new(api_secret, api_hmacSha512Data, hashlib.sha512)
api_sig = base64.b64encode(api_hmacsha512.digest())
api_url = api_domain + api_path + api_endpoint
api_request = urllib2.Request(api_url, api_postdata)
api_request.add_header("Content-Type", "application/x-www-form-urlencoded")
api_request.add_header("API-Key", api_key)
api_request.add_header("API-Sign", api_sig)
api_request.add_header("User-Agent", "Kraken REST API")
print("DEBUG DATA : ")
print("api_url : " + api_url)
print("api_endpoint : " + api_endpoint)
print("api_parameters : " + api_parameters)
print("")
api_reply = urllib2.urlopen(api_request).read()
api_reply = api_reply.decode()
print("API JSON DATA:")
print(api_reply)
sys.exit(0)
# Response:
# API JSON DATA:
# {"error":[],"result":{"ADA":"0.00000000","AIR":"0.0000000000","ALGO":"0.00000000","ATOM":"0.00000000",
# "AVAX":"0.0000000000","BONK":"0.24","BSX":"0.00","C98":"0.00000","CVC":"0.0000000000","DOT":"0.0000000058",
# "DYM":"1.001240","ETH2.S":"0.0000000000","FLOW":"0.0000000000","FLR":"0.0000","GRT":"0.0000000000","ICP":"0.00000000",
# "KAVA":"0.00000000","KFEE":"4619.88","KSM":"0.0457969620","KSM.S":"0.0000000000","MATIC":"0.0000000000",
# "MINA":"1.0067624751","MINA.S":"0.0000000000","PARA":"0.000","POLS":"0.00000","SBR":"0.00000000","SCRT":"0.00000000",
# "SCRT21.S":"0.00000000","SDN":"0.0000000000","SEI":"0.0000","SHIB":"0.00000","SOL":"0.0000069748","SOL.S":"0.0000000000",
# "SOL03.S":"0.0201035317","TIA":"0.000000","TRX":"0.00000000","USDC":"0.00000000","USDT":"0.00068726",
# "USDT.B":"3.53191423","WEN":"158958.59","WIF":"0.00000","XBT.M":"0.0001000103","XETH":"0.0000000000",
# "XTZ":"0.00000000","XXBT":"0.0000000000","XXDG":"24.34451185","XXMR":"0.0000000000","ZCAD":"0.0000",
# "ZEUR":"0.2732","ZUSD":"0.6353"}}Tuy nhiên, khi chúng ta thêm Loại nội dung của Tiêu đề dưới dạng JSON, chúng ta nhận được một
Lỗi EAPI: Khóa không hợp lệ.
Python
api_key = ""
api_secret = base64.b64decode("")
api_domain = "https://api.kraken.com"
api_path = "/0/private/"
api_endpoint = "AddOrder" # {"error":[]} IS SUCCESS-EMPTY BALANCE
# api_parameters = "pair=xbtusd&ordertype=market&type=buy&volume=0.0001&validate=True"
api_parameters = ''
api_nonce = str(int(time.time() * 1000))
api_postdata = api_parameters + "&nonce=" + api_nonce
api_postdata = api_postdata.encode('utf-8')
api_sha256Data = api_nonce.encode('utf-8') + api_postdata
api_sha256 = hashlib.sha256(api_sha256Data).digest()
api_hmacSha512Data = api_path.encode('utf-8') + api_endpoint.encode('utf-8') + api_sha256
api_hmacsha512 = hmac.new(api_secret, api_hmacSha512Data, hashlib.sha512)
api_sig = base64.b64encode(api_hmacsha512.digest())
api_url = api_domain + api_path + api_endpoint
api_request = urllib2.Request(api_url, api_postdata)
print("DEBUG DATA : ")
print("api_url : " + api_url)
print("api_endpoint : " + api_endpoint)
print("api_parameters : " + api_parameters)
print("")
headers = {}
headers['API-Key'] = api_key
headers['API-Sign'] = api_sig
headers['Content-Type'] = 'application/json'
headers['Accepts'] = 'application/json'
headers['User-Agent'] = "Kraken REST API"
api_reply = urllib2.urlopen(api_request).read()
api_reply = api_reply.decode()
data = {'nonce': api_nonce}
req = requests.post(api_url, headers=headers, data=data)
print(req.json())
print("API JSON DATA:")
print(api_reply)
sys.exit(0)
# API JSON DATA:
# {"error":["EAPI:Invalid key"]}*Lưu ý rằng có thể sử dụng dữ liệu được mã hóa URL hoặc dữ liệu được mã hóa JSON, nhưng dữ liệu phải khớp chính xác trong cả đầu vào SHA256 và yêu cầu HTTP.*
Lỗi Khóa không hợp lệ cũng có thể do truyền URI điểm cuối không đầy đủ hoặc bị thiếu (ví dụ: "AddOrder" thay vì “/0/private/AddOrder”).
Để Thuật toán xác thực tạo đúng Tiêu đề API-Sign, nó cần sử dụng toàn bộ URI (ví dụ: "/0/private/AddOrder”). Nếu bất kỳ phần nào của URI này bị cắt bớt, nó sẽ dẫn đến giá trị sai cho API-Sign và do đó là lỗi Khóa không hợp lệ.
Dưới đây là ví dụ về việc chỉ “AddOrder” được truyền vào để mã hóa thay vì toàn bộ URI điểm cuối “/0/private/AddOrder”
Python
api_key = ''
secret_key = ''
# Define the URI path for the Kraken API request
uri_path = 'AddOrder'
# API URL
api_url = 'https://api.kraken.com/0/private/'
# Create a dictionary for the request data
data = {
"nonce": str(int(1000 * time.time())),
"ordertype": 'limit',
'type': 'buy',
'volume': '0.07617478622420963',
'pair': 'SOLUSD',
'price': '127.47',
'validate': 'true'
}
# Encode the data for the request
postdata = urllib.parse.urlencode(data)
encoded = (str(data['nonce']) + postdata).encode()
# Create a message to be signed
message = uri_path.encode() + hashlib.sha256(encoded).digest()
# Create the HMAC signature
mac = hmac.new(base64.b64decode(secret_key), message, hashlib.sha512)
sigdigest = base64.b64encode(mac.digest())
# Create headers for the request
headers = {}
headers['API-Key'] = api_key
headers['API-Sign'] = sigdigest.decode()
# Make the POST request
req = requests.post(api_url + uri_path, headers=headers, data=data)
# Print the result
print(req.json())
# Result:
# {'error': ['EAPI:Invalid key']}Một vấn đề phổ biến khác gây ra Lỗi Khóa không hợp lệ là sự không khớp về mã hóa giữa yêu cầu POST và xác thực HTTP.
Trong ví dụ dưới đây, ‘Data’ được truyền đến yêu cầu POST được định dạng URL (với các khoảng trắng được mã hóa là ‘+’) dưới dạng loại nội dung application /x-www-form-urlencoded trong khi ‘data_formatted’ mã hóa các khoảng trắng là ‘%20’.
Mặc dù trong cả hai ví dụ, các khoảng trắng đều được mã hóa, nhưng dữ liệu được truyền đến thuật toán xác thực và yêu cầu POST không hoàn toàn giống nhau. Điều này sẽ dẫn đến lỗi Khóa không hợp lệ.
Python
# Define the URI path for the Kraken API request
uri_path = '/0/private/DepositAddresses'
# API URL
api_url = 'https://api.kraken.com'
# Calculate Nonce for both data variables
nonce = str(int(1000 * time.time()))
# Create a dictionary for the request data
data = {
"nonce": nonce,
"asset": 'BTC',
'method': 'Bitcoin Lightning',
'amount': '0.2',
'new': True
}
postdata_data = urllib.parse.urlencode(data)
# Encode the data for the request manually
data_formatted = f'nonce={nonce}&asset=BTC&method=Bitcoin%20Lightning&amount=0.2&new=True'
postdata = data_formatted
encoded = (nonce + postdata).encode()
# Create a message to be signed
message = uri_path.encode() + hashlib.sha256(encoded).digest()
# Create the HMAC signature
mac = hmac.new(base64.b64decode(secret_key), message, hashlib.sha512)
sigdigest = base64.b64encode(mac.digest())
# Create headers for the request
headers = {}
headers['API-Key'] = api_key
headers['API-Sign'] = sigdigest.decode()
# Make the POST request
req = requests.post(api_url + uri_path, headers=headers, data=data)
# Print the result
print(req.json())
# Result:
# {'error': ['EAPI:Invalid key']}Để minh họa rõ ràng điều này, vui lòng xem bên dưới 2 định dạng khác nhau cho Dữ liệu:
Bash
data = nonce=1719929687102&asset=BTC&method=Bitcoin+Lightning&amount=0.2&new=True
data_formatted = nonce=1719929687102&asset=BTC&method=Bitcoin%20Lightning&amount=0.2&new=True*Có thể sử dụng văn bản thuần túy hoặc mã hóa phần trăm miễn là định dạng giống nhau trong cả dữ liệu Xác thực và yêu cầu.*