spb/crypto-trade-bot
Public
Python 54.7%
TypeScript 42.5%
SQL 1.9%
1"""Official test vector from https://docs.kraken.com/api/docs/guides/spot-rest-auth."""23from ktrade.kraken.rest import OHLC_MAX_ROWS, CallCounter, NonceSource, sign45SECRET = "kQH5HW/8p1uGOVjbgWA7FunAmGO8lsSUXNsu3eow76sz84Q18fWxnyRzBHCd3pd5nE9qa99HAZtuZuj6F1huXg=="678def test_signature_matches_kraken_test_vector():9 data = {"nonce": "1616492376594", "ordertype": "limit", "pair": "XBTUSD", "price": 37500, "type": "buy", "volume": 1.25}10 assert sign("/0/private/AddOrder", data, SECRET) == "4/dpxb3iT4tp/ZCVEwSnEsLxx0bqyhLpdfOpc6fn7OR8+UClSV5n9E6aSS8MPtnRfp32bAb0nmbRn6H8ndwLUQ=="111213def test_signature_raw_body_variant():14 body = "nonce=1616492376594&ordertype=limit&pair=XBTUSD&price=37500&type=buy&volume=1.25"15 assert sign("/0/private/AddOrder", body, SECRET, nonce="1616492376594") == "4/dpxb3iT4tp/ZCVEwSnEsLxx0bqyhLpdfOpc6fn7OR8+UClSV5n9E6aSS8MPtnRfp32bAb0nmbRn6H8ndwLUQ=="161718async def test_nonce_strictly_increasing():19 ns = NonceSource()20 vals = [int(await ns.next()) for _ in range(200)]21 assert all(b > a for a, b in zip(vals, vals[1:], strict=False))222324async def test_call_counter_throttles():25 c = CallCounter("starter", safety=0.5) # budget 7.5 points26 for _ in range(7):27 await c.acquire(1)28 assert c.points >= 6.529 assert OHLC_MAX_ROWS == 72030