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: dict) -> None:
        print(message)

    # 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 messages.
  3. Run: Call await kraken_ws.run(subscriptions=[...]) to connect and start receiving data

Your handler function receives a pre parsed JSON -> python dictionary. See Kraken docs for the response schema.

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.1.tar.gz (5.5 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.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for kraken_sockets-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c724a4b1423b691d1c91c7a2e632382447cc5f9ba55fdeb70a9e3457d0740e3d
MD5 6cd185ad44847ea1b1cb0c49bde5e05f
BLAKE2b-256 bf0dfdc762c59cdc7b633d3875dedd8f2a9dcf4d6f7f98b85e9f4d01c418ed41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kraken_sockets-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd2f37941b821df5ae9338c99addea2f431d6d687aeed9a5e6a8f13bbbacbf90
MD5 9d370eb8425b2dc93e7d2707bbc447e5
BLAKE2b-256 894067c8d9e4051907125622a36f91994b8723a19ea88e54fa9d485a2abdc4f0

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