我是使用API的新手,并已被指派尝试使用Kucoin API组装交易算法。我在尝试列出有效订单时遇到问题。任何帮助表示赞赏
request = Request('https://api.kucoin.com/v1/open/orders-buy')
response_body = urlopen(request).read()
print response_body
控制台正在返回此错误
追踪(最近一次通话): 文件“/ Users / thomas / Documents / Github Repo / algo.py”,第5行,in response_body = urlopen(request).read() 文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第154行,在urlopen中 return opener.open(url,data,timeout) 文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第437行,公开 response = meth(req,response) 在http_response中输入文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第550行 'http',请求,响应,代码,消息,hdrs) 文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第475行,出错 return self._call_chain(* args) 文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第409行,在_call_chain中 result = func(* args) 在http_error_default中输入文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py”,第558行 提出HTTPError(req.get_full_url(),code,msg,hdrs,fp) urllib2.HTTPError:HTTP错误404:
答案 0 :(得分:1)
根据their documentation,它缺少属性。
答案 1 :(得分:0)
这是我在 Python 3 中的工作代码:
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 Orders
method = 'GET'
# endpoint = '/api/v1/orders' #alternative endpoint
endpoint = '/api/v1/orders?status=active'
response = requests.request(method, base_uri+endpoint, headers=get_headers(method,endpoint))
print(response.status_code)
response.json()
输出
200
{'code': '200000', 'data': {'currentPage': 1, 'pageSize': 50, 'totalNum': 0, 'totalPage': 0, 'items': [blah blah blah]}}