"""Official test vector from https://docs.kraken.com/api/docs/guides/spot-rest-auth.""" from ktrade.kraken.rest import OHLC_MAX_ROWS, CallCounter, NonceSource, sign SECRET = "kQH5HW/8p1uGOVjbgWA7FunAmGO8lsSUXNsu3eow76sz84Q18fWxnyRzBHCd3pd5nE9qa99HAZtuZuj6F1huXg==" def test_signature_matches_kraken_test_vector(): data = {"nonce": "1616492376594", "ordertype": "limit", "pair": "XBTUSD", "price": 37500, "type": "buy", "volume": 1.25} assert sign("/0/private/AddOrder", data, SECRET) == "4/dpxb3iT4tp/ZCVEwSnEsLxx0bqyhLpdfOpc6fn7OR8+UClSV5n9E6aSS8MPtnRfp32bAb0nmbRn6H8ndwLUQ==" def test_signature_raw_body_variant(): body = "nonce=1616492376594&ordertype=limit&pair=XBTUSD&price=37500&type=buy&volume=1.25" assert sign("/0/private/AddOrder", body, SECRET, nonce="1616492376594") == "4/dpxb3iT4tp/ZCVEwSnEsLxx0bqyhLpdfOpc6fn7OR8+UClSV5n9E6aSS8MPtnRfp32bAb0nmbRn6H8ndwLUQ==" async def test_nonce_strictly_increasing(): ns = NonceSource() vals = [int(await ns.next()) for _ in range(200)] assert all(b > a for a, b in zip(vals, vals[1:], strict=False)) async def test_call_counter_throttles(): c = CallCounter("starter", safety=0.5) # budget 7.5 points for _ in range(7): await c.acquire(1) assert c.points >= 6.5 assert OHLC_MAX_ROWS == 720