Tôi đang học Python và như một bài tập tôi đã cố gắng thực hiện một chương trình để thực hiện giao dịch trên thị trường bitcoin: https://bitcurex.com. Dưới đây là tham chiếu API: https://bitcurex.com/reading-room/API. Có một ví dụ PHP khách hàng, vì vậy tôi cố gắng dịch nó để Python, vì vậy tôi đã có:Dịch PHP sang Python (Kết nối Rest-API)
import math
import time
import simplejson
import urllib
import urllib2
import hmac,hashlib
def microtime():
return '%f %d' % math.modf(time.time())
def query(path, key, secret, data={}):
mt = microtime().split()
nonce = mt[1] + mt[0][2:]
data['nonce'] = nonce
post_data = urllib.urlencode(data)
sign = hmac.new(secret.decode('base64'), post_data, hashlib.sha512).digest()
headers = {'Rest-Key' : key,
'Rest-Sign': sign.encode('base64').strip(),
'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
'Content-type': 'application/x-www-form-urlencoded'}
print headers
url = 'https://bitcurex.com/api/0/' + path
req = urllib2.Request(url, post_data, headers)
response = urllib2.urlopen(req)
return simplejson.loads(response.read())
print query('getFunds', '29a28e8fe234537056a8b256c0df50413f50da9c49ca61991ea8b8f108a88e09', 'y2NDxKGa/xvhtXrDP+3oscbBUFSac9+T8jzu2nRmt0vBdHbbl8NRqdmxKFr2IwwY5LAskTQZGyy2XONaNN6Jrg==')
Các phím API đang làm việc - bạn chỉ có thể làm cho getFunds truy vấn với họ.
Nó liên tục trả về lỗi "Tôi phải đăng nhập". Tôi cố gắng để tìm kiếm theo yêu cầu rằng thông qua Fiddler Proxy Debugger, và ở đây bạn có tiêu đề của nỗ lực đó:
POST /api/0/getFunds HTTP/1.1
Accept-Encoding: identity
Rest-Sign: Dd1WBn2T5SYTbqMMohOxr46IaLDrkelgH7AgkrrB0mT0PxKfv15vSJ3b6xNdc5PO2Yz9cDpu0u/H
WIc7bH56sQ==:
Content-Length: 22
Rest-Key: 29a28e8fe234537056a8b256c0df50413f50da9c49ca61991ea8b8f108a88e09
Connection: close
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)
Host: bitcurex.com
Content-Type: application/x-www-form-urlencoded
Fiddler được hiển thị cho tôi một lỗi:
Incorrectly formed request headers.
Missing colon in header #3, WIc7bH56sQ==
Bất kỳ ý tưởng? Có vẻ như Rest-Sign của tôi quá dài hoặc một cái gì đó như thế. Tôi nghĩ rằng mã của tôi nên làm chính xác giống như ví dụ PHP. Tôi đang làm gì sai?
CNTT Đã hoạt động! Cảm ơn! – mpestkow
Làm việc cho tôi cũng vậy, nhưng mỗi khi tôi nhận được 403 phản hồi. Tôi đã sử dụng khóa/giá trị bí mật của riêng mình nhưng vẫn không thể đăng nhập –