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
- Initialize the WebSocket client
- Create a message handler using the decorator
- 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:
- Initialize: Create a
KrakenWebSocketAPIinstance - Handler: Use
@kraken_ws.message_handlerdecorator on your async function to process incoming JSON messages - 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_KEYKRAKEN_REST_API_PRIVATE_KEY
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8210edb6e3409329f14667cf9e2da73682ae51b01d3856d397ed004e20f17f01
|
|
| MD5 |
981948cda783e693c63dcb60124a52de
|
|
| BLAKE2b-256 |
7e3a18d267b156902170a341bb7f751f3503494787795d9e4fb1f2d58b76e59d
|
File details
Details for the file kraken_sockets-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kraken_sockets-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9efe7fb50537782964e4b54ea66d5f575d1e4d0f345edd4e51227b2a309e594e
|
|
| MD5 |
41a17c6324528f5c1a85b40db95c5aaf
|
|
| BLAKE2b-256 |
6b8c850529eb30e41c9305daf1d4e5f231878723d3b1a487944525fe0eecbf5d
|