2017-07-11 8 views
-3

独立リザーブビットコイン交換で制限オーダーを配置するPythonコードは何ですか?独立リザーブビットコイン交換で制限注文を再生するPythonコードは何ですか?

ここに私自身の書面によるコードがあります。{'Message': 'Invalid credentials'}エラーが発生します。誰でも助けることができますか?

公式リファレンスガイドはここにある:https://www.independentreserve.com/API#PlaceLimitOrder

import time,hmac,hashlib,requests,json 

key = 'test123' 
secret = 'test321' 

primaryCurrencyCode="Xbt" 
secondaryCurrencyCode="Aud" 
orderType="LimitBid" 
volume=0.88 
price=100 

url = 'https://api.independentreserve.com/Private/PlaceLimitOrder' 
nonce=int(time.time()) 
parameters = [url,'apiKey='+key,'nonce='+str(nonce),"primaryCurrencyCode="+primaryCurrencyCode,"secondaryCurrencyCode="+secondaryCurrencyCode,"orderType="+orderType,"price="+str(price),"volume="+str(volume)] 
message = ','.join(parameters) 
signature=hmac.new(secret.encode('utf-8'),msg=message.encode('utf-8'),digestmod=hashlib.sha256).hexdigest().upper() 
data = {"apiKey":key,"nonce": str(nonce),"signature": str(signature),"primaryCurrencyCode":primaryCurrencyCode, 
     "secondaryCurrencyCode":secondaryCurrencyCode,"orderType":orderType,"price":price,"volume":volume} 
headers={'Content-Type':'application/json'} 
r = requests.post(url, data=json.dumps(data,sort_keys=True), headers=headers).content 
response_body = json.loads(r.decode()) 
print(response_body) 
+0

はおそらく、あなたの資格情報が無効ですか?あなたはjson.loads(r.content.decode ...)をスキップし、単にr.json()を呼び出すことができます。 – jlaur

+0

このヒントありがとう – llwj

答えて

0

実は、私はこの問題を考え出しました。パラメータをソートする必要がある。..他の人のためのコードの作業

は参照:レスポンスが言うよう

import time,hmac,hashlib,requests,json 

key = 'test123' 
secret = 'test321' 

primaryCurrencyCode="Xbt" 
secondaryCurrencyCode="Aud" 
orderType="LimitBid" 
volume=0.88 
price=100 

url = 'https://api.independentreserve.com/Private/PlaceLimitOrder' 
nonce=int(time.time()) 
parameters = [url] + sorted(['apiKey='+key,'nonce='+str(nonce),"primaryCurrencyCode="+primaryCurrencyCode,"secondaryCurrencyCode="+secondaryCurrencyCode,"orderType="+orderType,"price="+str(price),"volume="+str(volume)]) 
message = ','.join(parameters) 
signature=hmac.new(secret.encode('utf-8'),msg=message.encode('utf-8'),digestmod=hashlib.sha256).hexdigest().upper() 
data = {"apiKey":key,"nonce": str(nonce),"signature": str(signature),"primaryCurrencyCode":primaryCurrencyCode, 
     "secondaryCurrencyCode":secondaryCurrencyCode,"orderType":orderType,"price":price,"volume":volume} 
headers={'Content-Type':'application/json'} 
r = requests.post(url, data=json.dumps(data,sort_keys=True), headers=headers).content 
response_body = json.loads(r.decode()) 
print(response_body) 
関連する問題