在尝试对OKEx API进行身份验证时,我一直收到一个无效的符号错误,但是我无法理解为什么我的签名没有通过。再看一只眼睛会有帮助吗?
以下是OKEx API文档中的一些上下文:
*-签名
创建一个时间戳+方法+ sign=CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(timestamp + 'GET' + '/users/self/verify', SecretKey)) + body (其中+表示字符串连接)的捕获字符串,准备秘密签名,并使用格式的SHA256对Base64格式的签名进行编码:
/orders?before=2&limit=30{"product_id":"BTC-USD-0309","order_id":"377454671037440"}22582BD0CFF14C41EDBF1AB98506286D*import hmac
import base64
import requests
import json
from Secrets import okex_key
from Secrets import okex_secret
from Secrets import okex_pass
#get time
def get_time():
urltime= 'https://www.okex.com/api/general/v3/time'
response=requests.get(urltime)
time=response.json()
time=time['iso']
return time
# signature
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)
# set request header
def get_header():
body= {}
request= 'GET'
endpoint= '/api/spot/v3/accounts'
header = dict()
header['CONTENT-TYPE'] = 'application/json'
header['OK-ACCESS-KEY'] = okex_key
header['OK-ACCESS-SIGN'] = signature(get_time(), request, endpoint , body, okex_secret)
header['OK-ACCESS-TIMESTAMP'] = str(get_time())
header['OK-ACCESS-PASSPHRASE'] = okex_pass
return header
url = 'http://www.okex.com/api/spot/v3/accounts'
header = get_header()
response= requests.get(url, headers=header)
response.json()发布于 2021-12-10 06:01:56
我正在邮递员中执行REST,它对我很好。下面是步骤。(您需要使用来自okex time api的时间戳)
GET:https://www.okex.com/api/v5/account/balance
标题:
OK-ACCESS-KEY:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (API_KEY)
OK-ACCESS-SIGN:{{sign}}
OK-ACCESS-TIMESTAMP:{{timestamp}}
OK-ACCESS-PASSPHRASE:YOUR_PASSPHRASE
Content-Type:application/json预请求脚本
pm.sendRequest('https://www.okex.com/api/general/v3/time', function (err, res) {
console.log('Response_ISO: '+res.json().iso);
pm.expect(err).to.not.be.ok;
var timestamp = res.json().iso;
var sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(timestamp + 'GET' + '/api/v5/account/balance', 'YOUR_SECRET_KEY'));
console.log(sign);
postman.setEnvironmentVariable('timestamp',timestamp)
postman.setGlobalVariable('timestamp',timestamp)
postman.setEnvironmentVariable('sign',sign)
postman.setGlobalVariable('sign',sign)
}); https://stackoverflow.com/questions/66486374
复制相似问题