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
- Initialize the WebSocket client
- Create trigger functions using the decorator
- 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:
- Initialize: Create a
KrakenWebSocketAPIinstance - Triggers: Use
@kraken.trigger(ResponseType)to register functions that execute when specific message types arrive - Subscribe: Choose which channels to subscribe to using request schemas
- 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,BookUpdateResponseTickerSnapshotResponse,TickerUpdateResponseTradesSnapshotResponse,TradesUpdateResponseOHLCSnapshotResponse,OHLCUpdateResponseInstrumentsSnapshotResponse,InstrumentsUpdateResponseOrderSnapshotResponse,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_KEYKRAKEN_REST_API_PRIVATE_KEY
For complete API documentation, see Kraken WebSocket API v2 docs.
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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8d279217f7ae3aaec350cab0c58fcbc933ba64b85fabe1ea8b8abe375b2dbdf
|
|
| MD5 |
7059a472bf530b7a2f62cb24a71cd17a
|
|
| BLAKE2b-256 |
74c2348b08f6eb9bc6581b52792bc2d444acaa3853e82f8f1ef6d58220ee1c5d
|
File details
Details for the file kraken_sockets-0.1.2-py3-none-any.whl.
File metadata
- Download URL: kraken_sockets-0.1.2-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b6a474f570cbaf3b5c09f4d59834e5f96ea35973b7ede58aaf7f4baaa2033a
|
|
| MD5 |
a762ba3f030af945d805c23f6fca2210
|
|
| BLAKE2b-256 |
e1e5e0c90aa3b8ec4b28f30238ce1c8d31b70f896b47f110ab6f85b0ce7bbc80
|