Skip to main content

Kraken Websocket

[NOT RELEASED] This is very much a work in progress, despite being on pypi. Most things might be wrongly documented; API will change

Features

  • Reconnect with incremental backoff (per Kraken's recommendation)
  • Automatically reset subscription for private feeds when sequence is out of whack
  • request/response factories e.g. add_order_factory make websocket events feel like calling an API
  • ... but provides more info than a simple request/response; for instance, add_order goes through each stage submitted->pending->open or canceled, emitting a notification at each stage

Installing

pip install bittrade-kraken-websocket or poetry add bittrade-kraken-websocket

General considerations

Observables/Reactivex

The whole library is build with Reactivex.

Though Observables seem complicated at first, they are the best way to handle - and (synchronously) test - complex situations that arise over time, like an invalid sequence of messages or socket disconnection and backoff reconnects.

For simple use cases, they are also rather easy to use as shown in the examples folder or in the Getting Started below

Concurrency

Internally the library uses threads. For your main program you don't have to worry about threads; you can block the main thread.

Getting started

Connect to the public feeds

from bittrade_kraken_websocket import public_websocket_connection, subscribe_ticker
from bittrade_kraken_websocket.operators import keep_messages_only, filter_new_socket_only

# Prepare connection - note, this is a ConnectableObservable, so it will only trigger connection when we call its ``connect`` method
socket_connection = public_websocket_connection()
# Prepare a feed with only "real" messages, dropping things like status update, heartbeat, etc…
messages = socket_connection.pipe(
    keep_messages_only(),
)
socket_connection.pipe(
    filter_new_socket_only(),
    subscribe_ticker('USDT/USD', messages)
).subscribe(
    print, print, print  # you can do anything with the messages; here we simply print them out
)
socket_connection.connect()

(This script is complete, it should run "as is")

Logging

We use Python's standard logging. You can modify what logs you see as follows:

logging.getLogger('bittrade_kraken_websocket').addHandler(logging.StreamHandler())

Private feeds

Similar to bittrade-kraken-rest, this library attempts to get as little access to sensitive information as possible.

Currently, you need to set the token onto the EnhancedWebsocket; this means we have no access to your Api key and secret. Since the token is connection based and can't be reused, this protects you as much as Kraken's current authentication method allows.

See examples/private_subscription.py for an example of implementation

new_sockets = connection.pipe(
    filter_new_socket_only(),
    operators.map(add_token),
    operators.share(),
)

Examples

Most examples in the examples folder make use of the development module helpers and the rich logging. You will need to install the dependencies from the rich group to use them:

poetry add bittrade_kraken_websocket -E rich

Metadata

Release files for bittrade-kraken-websocket 0.3.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bittrade-kraken-websocket 0.3.11
File Size Uploaded Provenance
bittrade_kraken_websocket-0.3.11.tar.gz 21.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bittrade-kraken-websocket 0.3.11
File Interpreter ABI Platform
bittrade_kraken_websocket-0.3.11-py3-none-any.whl Python 3 none any Details

Total release size: 55.2 kB

Release files / bittrade_kraken_websocket-0.3.11.tar.gz

Download URL bittrade_kraken_websocket-0.3.11.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3ae971fc1e2e0a6d8332e0d149080f96cfef87916562324bae09280d361998b0
BLAKE2b-256 checksum
How to use checksums
56958ec1f966f0174ce9c33bbdc4e93ec20cc1613a30f472812b02fdf975ff38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.5 Darwin/22.4.0

Release files / bittrade_kraken_websocket-0.3.11-py3-none-any.whl

Download URL bittrade_kraken_websocket-0.3.11-py3-none-any.whl
Size 33.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9669a1b9e18275a7530ab55f16570f32d903384f8625b7b00c6f33c81e7a4972
BLAKE2b-256 checksum
How to use checksums
6589fcda3cec5d199270bee23a016b3f789ec8c7bd7f05a854bfdfedd89b5319
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.5 Darwin/22.4.0

Security for bittrade-kraken-websocket 0.3.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page