0
我想使用Bitstamp API,并且能够成功调用任何只需要密钥,签名和随机数参数的任何事物。但是,当我尝试转移或订购时,需要额外的参数(如地址,价格和金额),我的请求似乎变得混乱。我对编程,API和请求很陌生。如何在使用python请求模块的bitstamp API中发送参数
def sell(self, product):
nonce = self.get_nonce() #an integer time.time()*10000
btc = self.get_btc_bal() #float
price = self.get_btcusd_bid() #float
amount = float(str(btc)[:5])
message = str(nonce) + self.customer_id + self.api_key
signature = hmac.new(self.api_secret, msg=message, digestmod=hashlib.sha256).hexdigest().upper()
r = requests.post(self.url + 'sell/btcusd/', params={'key':self.api_key, 'signature':signature, 'nonce': nonce, 'amount': amount, 'price':price})
r = r.json()
print(r)
print('open sell order in Bitstamp for %s BTC at %s USD'%(amount,price))
我确切的问题是如何正确地格式化/组织/编码参数。当我像这样把它,它返回
{"status": "error", "reason": "Missing key, signature and nonce parameters.", "code": "API0000"}
如果我不使用params=
返回
{"status": "error", "reason": "Invalid nonce", "code": "API0004"}
我不相信,因为我用的是完全一样的get_nonce的现时原因()方法为我所有的要求。我希望有人能看到我错了,请和谢谢
感谢您的帮助,我不知道。我试着用data =替换params =,它仍然返回相同的错误。我也尝试了一些作为参数和其他数据。我开始认为这是一个API特定的字典键,它的价值包含了我的额外参数,如价格,金额或地址。 –