Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/kraken_ruby_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,15 @@ def parse_response(http)
# current Unix Time.
#
def generate_nonce
(Time.now.to_f * 1_000_000).to_i
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this error; how to reproduce?

According to the Kraken API docs at

"Nonce must be an always increasing, unsigned 64-bit integer, for each request that is made with a particular API key. While a simple counter would provide a valid nonce, a more usual method of generating a valid nonce is to use e.g. a UNIX timestamp in milliseconds."

The code examples in the second link are similar to the current code, as is the nonce code in my other Kraken client in Common Lisp: https://github.com/jonatack/cl-kraken/blob/master/src/time.lisp. So the current code seems correct?

((high_bits | low_bits).to_s)
end

def low_bits
@low_bits ||= (SecureRandom.random_number(2 ** 16) & 0xffff)
end

def high_bits
@high_bits ||= ((Time.now.to_f * 10000).to_i << 16)
end

def auth_url(method, nonce, params)
Expand Down
15 changes: 8 additions & 7 deletions test/public_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ def test_get_server_time

def test_get_assets
assets = %w(
1INCH AAVE ADA ADA.S ALGO ALGO.S ANKR ANT ATOM ATOM.S AVAX AXS BADGER BAL
BAND BAT BCH BNC BNT CHF CHZ COMP CQT CRV CTSI DAI DASH DOT DOT.P DOT.S
DYDX ENJ EOS ETH2 ETH2.S EUR.HOLD EUR.M EWT FIL FLOW FLOW.S FLOWH FLOWH.S
GHST GLMR GNO GRT ICX INJ KAR KAVA KAVA.S KEEP KFEE KILT KINT KNC KSM
KSM.P KSM.S LINK LPT LRC LSK LUNA MANA MATIC MINA MIR MKR MOVR NANO OCEAN
OGN OMG OXT OXY PAXG PERP PHA QTUM RARI RAY REN REPV2 SAND SC SDN SHIB SNX
SOL SOL.S SRM STORJ SUSHI TBTC TRX UNI USD.HOLD USD.M USDC USDT WAVES WBTC
1INCH AAVE ACA ADA ADA.S AKT ALGO ALGO.S ANKR ANT ASTR ATLAS ATOM ATOM.S
AVAX AXS BADGER BAL BAND BAT BCH BNC BNT CHF CHZ COMP CQT CRV CTSI DAI
DASH DOT DOT.P DOT.S DYDX ENJ EOS ETH2 ETH2.S EUR.HOLD EUR.M EWT FIDA FIL
FLOW FLOW.S FLOWH FLOWH.S GHST GLMR GNO GRT ICX INJ KAR KAVA KAVA.S KEEP
KFEE KILT KIN KINT KNC KSM KSM.P KSM.S LINK LPT LRC LSK LUNA MANA MATIC
MINA MINA.S MIR MKR MNGO MOVR NANO OCEAN OGN OMG ORCA OXT OXY PAXG PERP
PHA POLIS QTUM RARI RAY REN REPV2 SAND SBR SC SDN SHIB SNX SOL SOL.S SRM
STEP STORJ SUSHI TBTC TRX TRX.S UNI USD.HOLD USD.M USDC USDT WAVES WBTC
XBT.M XETC XETH XLTC XMLN XREP XTZ XTZ.S XXBT XXDG XXLM XXMR XXRP XZEC YFI
ZAUD ZCAD ZEUR ZGBP ZJPY ZRX ZUSD
)
Expand Down