Skip to main content

Reactive Websocket for Crypto.com

Project description

Crypto.com 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
  • Respond to ping
  • 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-cryptodotcom-websocket or poetry add bittrade-cryptodotcom-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_cryptodotcom_websocket import public_websocket_connection, subscribe_ticker
from bittrade_cryptodotcom_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_cryptodotcom_websocket').addHandler(logging.StreamHandler())

Private feeds

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

This means that you'll need to implement the signature token yourself. The library never has access to your API secret.

See examples/private_subscription.py for an example of implementation but it is generally as simple as:

authenticated_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_cryptodotcom_websocket -E rich

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

bittrade_cryptodotcom_websocket-0.1.3.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bittrade_cryptodotcom_websocket-0.1.3-py3-none-any.whl (42.8 kB view details)

Uploaded Python 3

File details

Details for the file bittrade_cryptodotcom_websocket-0.1.3.tar.gz.

File metadata

  • Download URL: bittrade_cryptodotcom_websocket-0.1.3.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.5 Linux/5.4.72-microsoft-standard-WSL2

File hashes

Hashes for bittrade_cryptodotcom_websocket-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fc7ffc05a8f2fcf1c6d317774a6e99e00d701c99d5d23aebe3a167ebb02a9def
MD5 176910e465c84f20fe27cce3a96613cf
BLAKE2b-256 e101b1b5d9d7e842eaf40fe253d016165ff9410f7d44adf75f438e5f5b13ad55

See more details on using hashes here.

File details

Details for the file bittrade_cryptodotcom_websocket-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bittrade_cryptodotcom_websocket-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 86b7e04bddb38f5509b7880d0d9274f6de537aa00b56bae457cc5ef2682cfafb
MD5 e040bebc7f209b035597b7a8ec558218
BLAKE2b-256 4d04001b47b1712ea54bd677c34d89136c4d83ff6de4546ae23cd0244ee44e35

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