python 在独立储备比特币交易所播放限价订单的代码是什么?
What is the python code to play limit orders on independent reserve bitcoin exchange?
在独立储备比特币交易所下限价订单的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)
其实我想通了。需要对参数进行排序..
供他人参考的工作代码:
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)
在独立储备比特币交易所下限价订单的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)
其实我想通了。需要对参数进行排序..
供他人参考的工作代码:
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)