Skip to main content

Kraky

Python client for Kraken API REST and Kraken Websockets API using httpx and websockets. Supports both sync and async for API REST.

Disclaimer

This software is for educational purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.

Always start by running a trading bot in Dry-run and do not engage money before you understand how it works and what profit/loss you should expect.

We strongly recommend you to have coding and Python knowledge. Do not hesitate to read the source code and understand the mechanism of this library.

Installation

pip install kraky

Docs

https://kraky.readthedocs.io/en/latest/

Usage

CLI

Kraky provides a CLI that matches the API function names and args.

You can use it like the following:

kraky get_ohlc_data pair=XBTUSD interval=240

You can replace get_ohlc_data by any kraky API function and pair=XBTUSD or interval=240 by any function argument. Please respect the format key=value.

It also supports .env files so you can also create a .env file with your api_key and secret and kraky will pick them up.

Example:

KRAKEN_API_KEY=""
KRAKEN_SECRET=""

Sync REST API

from kraky import KrakyApiClient


def get_web_sockets_token():
    kraken_api_key = ""
    kraken_secret = ""
    kraky_api_client = KrakyApiClient(
        api_key=kraken_api_key, secret=kraken_secret
    )

    ws_token = kraky_api_client.get_web_sockets_token()
    return ws_token

get_web_sockets_token()

Async REST API

from kraky import KrakyApiAsyncClient


async def get_web_sockets_token():
    kraken_api_key = ""
    kraken_secret = ""
    kraky_api_client = KrakyApiAsyncClient(
        api_key=kraken_api_key, secret=kraken_secret
    )

    ws_token = await kraky_api_client.get_web_sockets_token()
    return ws_token

asyncio.run(get_web_sockets_token)

Websocket

import asyncio
from kraky import KrakyApiAsyncClient, KrakyWsClient


async def get_web_sockets_token():
    kraken_api_key = ""
    kraken_secret = ""
    kraky_api_client = KrakyApiAsyncClient(
        api_key=kraken_api_key, secret=kraken_secret
    )

    ws_token = await kraky_api_client.get_web_sockets_token()
    return ws_token


async def public_handler(response):
    print(response)


async def private_handler(response):
    print(response)


async def main():

    interval = 30

    ws_pairs = ["XBT/USD", "ETH/USD"]

    ws_token = await get_web_sockets_token()

    kraky_public_ws_client = KrakyWsClient("production")
    kraky_private_ws_client = KrakyWsClient("production-auth")

    asyncio.create_task(
        kraky_public_ws_client.connect(public_handler, connection_name="public")
    )

    asyncio.create_task(
        kraky_private_ws_client.connect(private_handler, connection_name="private")
    )

    await kraky_public_ws_client.subscribe(
        {"name": "ohlc", "interval": interval},
        ws_pairs,
        connection_name="public",
    )

    await kraky_private_ws_client.subscribe(
        {
            "interval": interval,
            "token": ws_token,
            "name": "openOrders",
        },
        connection_name="private",
    )


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.create_task(main())
    loop.run_forever()

Compatibility

  • Python 3.8 and above

Licence

MIT License

Release files for kraky 2023.8.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kraky 2023.8.17
File Size Uploaded
kraky-2023.8.17.tar.gz 19.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kraky 2023.8.17
File Interpreter ABI Platform
kraky-2023.8.17-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 32.4 kB

Release files / kraky-2023.8.17.tar.gz

Download URL kraky-2023.8.17.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f2ef894e2fc86a4011345b9156323077e0161d5e54f6900de70e92a345ab286d
BLAKE2b-256 checksum
How to use checksums
10c3a4c4cc458c539de36b027f495be5b03ed00f2acc28b909c5c676796df33a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / kraky-2023.8.17-py2.py3-none-any.whl

Download URL kraky-2023.8.17-py2.py3-none-any.whl
Size 13.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e47c35034794c72635e3c4d5e48e653e0b53bd9231b5b689a3c90d6055273bc5
BLAKE2b-256 checksum
How to use checksums
f9e2a77e3d5d2210b4b53d3c12419218b8a639d63666f947b546f3a17e9dbf12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page