Skip to main content

Easy Kraken Websockets. Just wrap your message handler and go.

Project description

kraken-sockets

Access Kraken's WebSocket API v2 for real-time market information and trading data.

Quick Start

  1. Initialize the WebSocket client
  2. Create a message handler using the decorator
  3. Run with your desired subscriptions
import asyncio
from kraken_ws.api import KrakenWebSocketAPI
from schema.market_data_subscriptions import TickerSubscriptionMessage

async def main():
    # 1. Initialize
    kraken_ws = KrakenWebSocketAPI()

    # 2. Wrap your handler
    @kraken_ws.message_handler
    async def my_handler(message: str | bytes) -> None:
        print(message)  # Message is already an object from

    # 3. Run with subscriptions, alternatively you can call .subscribe() during your own execution
    subscriptions = [TickerSubscriptionMessage(["BTC/USD", "ETH/USD"])]
    await kraken_ws.run(subscriptions=subscriptions)

if __name__ == "__main__":
    asyncio.run(main())

How It Works

The example.py demonstrates the three-step process:

  1. Initialize: Create a KrakenWebSocketAPI instance
  2. Handler: Use @kraken_ws.message_handler decorator on your async function to process incoming JSON messages
  3. Run: Call await kraken_ws.run(subscriptions=[...]) to connect and start receiving data

Your handler function receives raw JSON messages from Kraken's WebSocket streams. Parse and process them according to your needs.

Message Structure

For complete documentation on message formats and available subscriptions, see the Kraken WebSocket API v2 docs.

Private Endpoints

For authenticated endpoints, set environment variables by replacing .env.example with your .env with keys.:

  • KRAKEN_REST_API_KEY
  • KRAKEN_REST_API_PRIVATE_KEY

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kraken_sockets-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kraken_sockets-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file kraken_sockets-0.1.0.tar.gz.

File metadata

  • Download URL: kraken_sockets-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for kraken_sockets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8210edb6e3409329f14667cf9e2da73682ae51b01d3856d397ed004e20f17f01
MD5 981948cda783e693c63dcb60124a52de
BLAKE2b-256 7e3a18d267b156902170a341bb7f751f3503494787795d9e4fb1f2d58b76e59d

See more details on using hashes here.

File details

Details for the file kraken_sockets-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kraken_sockets-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9efe7fb50537782964e4b54ea66d5f575d1e4d0f345edd4e51227b2a309e594e
MD5 41a17c6324528f5c1a85b40db95c5aaf
BLAKE2b-256 6b8c850529eb30e41c9305daf1d4e5f231878723d3b1a487944525fe0eecbf5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page