Skip to main content

Easy Kraken Websockets. Just wrap your triggers and build.

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 trigger functions using the decorator
  3. Run with your desired subscriptions
import asyncio
from kraken_sockets.api import KrakenWebSocketAPI
from schema.responses import TickerUpdateResponse, TradesUpdateResponse
from schema.requests.market_data_requests import TickerSubscriptionRequest, TradesSubscriptionRequest

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

    # 2. Set trigger functions for specific response types
    @kraken.trigger(TickerUpdateResponse)
    async def ticker_handler(response: TickerUpdateResponse) -> None:
        kraken.log(f"Last price: ${response.last}", "info")

    @kraken.trigger(TradesUpdateResponse)
    async def trades_handler(response: TradesUpdateResponse) -> None:
        for trade in response.trades:
            kraken.log(f"{trade.side} {trade.price} @ {trade.qty}", "info")

    # 3. Run with subscriptions
    subscriptions = [
        TickerSubscriptionRequest(["BTC/USD", "ETH/USD"]),
        TradesSubscriptionRequest(["BTC/USD"])
    ]

    await kraken.run(subscriptions)

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

How It Works

The trigger decorator system allows you to:

  1. Initialize: Create a KrakenWebSocketAPI instance
  2. Triggers: Use @kraken.trigger(ResponseType) to register functions that execute when specific message types arrive
  3. Subscribe: Choose which channels to subscribe to using request schemas
  4. Run: Call await kraken.run(subscriptions) to connect and start the async loop

Each trigger function receives a parsed response object matching the specified schema type.

Available Decorators

  • @kraken.trigger(ResponseType) - Execute function when specific response type is received
  • @kraken.user_logger - Register custom logging handler
  • @kraken.user_task - Add custom tasks to the async loop

Admin Responses:

  • HeartbeatResponse, PingResponse, StatusResponse

Market Data Responses:

  • BookSnapshotResponse, BookUpdateResponse
  • TickerSnapshotResponse, TickerUpdateResponse
  • TradesSnapshotResponse, TradesUpdateResponse
  • OHLCSnapshotResponse, OHLCUpdateResponse
  • InstrumentsSnapshotResponse, InstrumentsUpdateResponse
  • OrderSnapshotResponse, OrderUpdateResponse

Subscription Responses:

  • SubscriptionResponse, UnsubscribeResponse

Request Schemas

Request schemas are in schema.requests:

  • Market data: TickerSubscriptionRequest, TradesSubscriptionRequest, BookSubscriptionRequest, etc.
  • User data: OrdersSubscriptionRequest, BalancesSubscriptionRequest, ExecutionSubscriptionRequest

Private Endpoints

For authenticated endpoints, set environment variables:

  • KRAKEN_REST_API_KEY
  • KRAKEN_REST_API_PRIVATE_KEY

For complete API documentation, see Kraken WebSocket API v2 docs.

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.2.tar.gz (13.0 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.2-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for kraken_sockets-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e8d279217f7ae3aaec350cab0c58fcbc933ba64b85fabe1ea8b8abe375b2dbdf
MD5 7059a472bf530b7a2f62cb24a71cd17a
BLAKE2b-256 74c2348b08f6eb9bc6581b52792bc2d444acaa3853e82f8f1ef6d58220ee1c5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kraken_sockets-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c4b6a474f570cbaf3b5c09f4d59834e5f96ea35973b7ede58aaf7f4baaa2033a
MD5 a762ba3f030af945d805c23f6fca2210
BLAKE2b-256 e1e5e0c90aa3b8ec4b28f30238ce1c8d31b70f896b47f110ab6f85b0ce7bbc80

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