python脚本正在运行,现在不是。
public_client = bitstamp.client.Public()
data=backTestBitCoin.getHistoricalPrices();
trading_client = bitstamp.client.Trading(username='AAA', key='BBB', secret='CCC')
tick=trading_client.ticker();
lastBid = float(tick['bid']);
lastAsk = float(tick['ask']);
balances = trading_client.account_balance(); #error thrown from this line
我收到以下错误:
return self._post("balance/", return_json=True)
File "/Library/Python/2.7/site-packages/bitstamp/client.py", line 47, in _post
return self._request(requests.post, *args, **kwargs)
File "/Library/Python/2.7/site-packages/bitstamp/client.py", line 80, in _request
raise BitstampError(error)
bitstamp.client.BitstampError: Invalid nonce
有没有人经历过这个?不熟悉图书馆,因此不确定是什么导致它。
答案 0 :(得分:1)
生成新的api密钥/密钥修复了这个问题。我相信它是由使用php api和python api或iphone Bitstamp应用程序混合引起的。我将证实这种怀疑,但总体解决方案是拔掉它并将其重新插入。
缩写解决方案:我的问题来自使用以下php和python库,
两者都是A +很棒且易于使用。
错误的产生是因为他们创建nonce的方法存在以下差异(在我看来,两者都不是更多"右边"只是不同)。
<强> PHP 强>:
// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1] . substr($mt[0], 2, 6);
$req['key'] = $key;
$req['signature'] = $this->get_signature($req['nonce']);
<强>蟒强>:
self._nonce = max(int(time.time()), nonce)
time.time()
给你的地方:1403366728.072785
并microtime()
给你:1403366859731819。
我实施的解决方案是将python代码更改为:
self._nonce = max(int(time.time()*1000000), nonce)
并且错误已解决。