首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不确定如何验证我的api密钥Kucoin

不确定如何验证我的api密钥Kucoin
EN

Stack Overflow用户
提问于 2017-12-13 12:58:00
回答 2查看 1.6K关注 0票数 3

我正在学习如何使用Kucoin,并且在向API服务器进行身份验证时遇到了问题。

我正在尝试加载所有活动的订单,但仍然得到一个401错误。

Kucoin API文档指出,我需要添加以下内容:

代码语言:javascript
复制
{
    "KC-API-KEY": "59c5ecfe18497f5394ded813",  
    "KC-API-NONCE" : 1506219855000   //Client timestamp (exact to 
milliseconds), before using the calibration time, the server does not 
accept calls with a time difference of more than 3 seconds
    "KC-API-SIGNATURE" : 
"fd83147802c361575bbe72fef32ba90dcb364d388d05cb909c1a6e832f6ca3ac"   
//signature after client encryption
}

作为请求标头的参数。我不确定这是什么意思。任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

发布于 2018-01-12 06:56:24

创建头文件可能有点棘手。

对于nonce值或任何毫秒时间戳值,我发现生成该值的最佳方法如下

代码语言:javascript
复制
import time
int(time.time() * 1000)

签名要求您按查询字符串格式的字母顺序对参数进行排序,将其与路径和随机数组合在一起,然后使用sha256和密钥对字符串进行散列。

如果你想自己实现它,请随意复制这里的代码,它被分成了几个函数,应该是非常可读的https://github.com/sammchardy/python-kucoin/blob/0ece729c406056a428a57853345c9931d449be02/kucoin/client.py#L117

或者,你最好直接使用这个库。(注:我是python-kucoin的作者和维护者)

票数 1
EN

Stack Overflow用户

发布于 2021-05-17 00:18:06

以下是我在Python 3中的工作代码:

代码语言:javascript
复制
import requests
import json
import hmac
import hashlib
import base64
from urllib.parse import urlencode
import time

api_key = 'xxxxx'
api_secret = 'xx-xxx-xx'
api_passphrase = 'xxx'   #this is NOT trading password
base_uri = 'https://api.kucoin.com'

def get_headers(method, endpoint):
    now = int(time.time() * 1000)
    str_to_sign = str(now) + method + endpoint
    signature = base64.b64encode(hmac.new(api_secret.encode(), str_to_sign.encode(), hashlib.sha256).digest()).decode()
    passphrase = base64.b64encode(hmac.new(api_secret.encode(), api_passphrase.encode(), hashlib.sha256).digest()).decode()
    return {'KC-API-KEY': api_key,
            'KC-API-KEY-VERSION': '2',
            'KC-API-PASSPHRASE': passphrase,
            'KC-API-SIGN': signature,
            'KC-API-TIMESTAMP': str(now)
    }

#List Accounts
method = 'GET'
endpoint = '/api/v1/accounts'
response = requests.request(method, base_uri+endpoint, headers=get_headers(method,endpoint))
print(response.status_code)
print(response.json())

输出

代码语言:javascript
复制
200
{'code': '200000', 'data': [{'available': blah, blah blah  }]}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47785751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档