OKEX v5接口鉴权认证
pass_phrase = '***' # 申请
api_key = "***" # 申请
secret_key = "***" # 申请
timestamp = requests.get('https://www.okex.com/api/general/v3/time').json()['iso'] # 根据需要选择对应的时间格式
def signature(timestamp, method, request_path, body, secret_key):
"""
签名
"""
if str(body) == '{}' or str(body) == 'None':
body = ''
message = str(timestamp) + str.upper(method) + request_path + str(body)
mac = hmac.new(bytes(secret_key, encoding='utf8'), bytes(message, encoding='utf-8'), digestmod='sha256')
d = mac.digest()
return base64.b64encode(d)
def get_header(api_key, current_time, pass_phrase, secret_key):
"""
拼接请求头
"""
return {
'OK-ACCESS-KEY': api_key,
'OK-ACCESS-SIGN': signature(current_time, 'GET', '/api/v5/asset/currencies', 'None', secret_key),
'OK-ACCESS-TIMESTAMP': current_time,
'OK-ACCESS-PASSPHRASE': pass_phrase,
}
url = 'https://www.okex.com/api/v5/asset/currencies'
headers=get_header(api_key, timestamp, pass_phrase, secret_key)
response = requests.get(url=url, headers=headers).json()