WS and HTTP clients for Kraken exchange API
Project description
kraken-connector
A typed Python client for the Kraken cryptocurrency exchange, covering both the REST API and WebSocket API v2. Built on httpx for HTTP, websockets for streaming, and attrs for data models.
Features
- REST API -- typed request/response models across 7 endpoint groups (market data, account data, trading, funding, earn, subaccounts, websocket auth)
- WebSocket v2 -- async client with typed channel models for ticker, OHLC, trades, order book, executions, and balances
- Trading -- all 8 WS v2 trading methods (add, edit, cancel, batch add, batch cancel, cancel all, cancel all after, amend)
- Order book management -- local order book state with incremental updates and CRC32 checksum validation
- Automatic reconnection -- configurable backoff with subscription and sequence tracking across reconnects
- Rate limiting -- caller-controlled token-bucket limiter matching Kraken's tier-based rate limits
- Retry -- configurable retry transport with exponential backoff for transient network errors
- Request logging -- optional request/response logging via Python's stdlib
logging - Fully typed --
py.typedmarker, strict mypy, attrs-based models withto_dict()/from_dict()
Requirements
Python 3.11+
Installation
pip install kraken-connector
Quick Start
REST API
from kraken_connector import HTTPClient
from kraken_connector.api.market_data import get_server_time
client = HTTPClient("https://api.kraken.com")
response = get_server_time.sync(client=client)
print(response)
WebSocket
import asyncio
from kraken_connector.ws import KrakenWSClient
from kraken_connector.ws.subscribe import TickerParams
from kraken_connector.ws.envelopes import WSDataMessage
async def main():
async with KrakenWSClient() as client:
await client.subscribe(TickerParams(symbol=["BTC/USD"]))
async for msg in client:
if isinstance(msg, WSDataMessage) and msg.channel == "ticker":
print(msg.data)
asyncio.run(main())
See the documentation for guides on authentication, rate limiting, trading, order book management, error handling, and more.
Development
See CONTRIBUTING.md for development setup and guidelines.
License
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
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_connector-0.2.0.tar.gz.
File metadata
- Download URL: kraken_connector-0.2.0.tar.gz
- Upload date:
- Size: 151.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.26.9 CPython/3.11.15 Linux/6.17.0-1013-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cdb4c3c03bb11f584fa5fd0144c9fe7ae527ab0343c71826565945f0c47d030
|
|
| MD5 |
713d445b0a275120a5e68c4fea027efe
|
|
| BLAKE2b-256 |
2702297b3a2c57a5fff9133f9cc81c8e323b4d21dce3fce81ca3a8e59dddb61c
|
File details
Details for the file kraken_connector-0.2.0-py3-none-any.whl.
File metadata
- Download URL: kraken_connector-0.2.0-py3-none-any.whl
- Upload date:
- Size: 316.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.26.9 CPython/3.11.15 Linux/6.17.0-1013-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d20a2037554c9fb2b830f953a79005f24c791266eaa45b4a98a3bc461a049f73
|
|
| MD5 |
09c46774947990fe4e6f5d8d78894e28
|
|
| BLAKE2b-256 |
f4401a05f093ccf7ea4839c5a62686dac9cfdffa2eff7390bd1c1dd5bad4366c
|