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特定的字典鍵,它的價值包含了我的額外參數,如價格,金額或地址。 –