Skip to main content

WS and HTTP clients for Kraken exchange API

Project description

kraken-connector

Release Build status codecov License Python 3.11+ PyPI

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.typed marker, strict mypy, attrs-based models with to_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

MIT

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_connector-0.2.0.tar.gz (151.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_connector-0.2.0-py3-none-any.whl (316.3 kB view details)

Uploaded Python 3

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

Hashes for kraken_connector-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3cdb4c3c03bb11f584fa5fd0144c9fe7ae527ab0343c71826565945f0c47d030
MD5 713d445b0a275120a5e68c4fea027efe
BLAKE2b-256 2702297b3a2c57a5fff9133f9cc81c8e323b4d21dce3fce81ca3a8e59dddb61c

See more details on using hashes here.

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

Hashes for kraken_connector-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d20a2037554c9fb2b830f953a79005f24c791266eaa45b4a98a3bc461a049f73
MD5 09c46774947990fe4e6f5d8d78894e28
BLAKE2b-256 f4401a05f093ccf7ea4839c5a62686dac9cfdffa2eff7390bd1c1dd5bad4366c

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