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())
In addition, one special logger logs every message received from the socket (except heartbeat) at the DEBUG
level: bittrade_cryptodotcom_websocket.connection.generic.raw
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(),
)
Development guidelines
*_http
methods
REST functions over http should be suffixed with _http
e.g. get_book_http
.
They should return an Observable containing the full json body; this is easily achieved via prepare_request
and send_request
.
Where possible models should be defined to describe the raw result and parsed result if available/useful.
Reactive operators may be provided for parsing, but they should never be included in the raw functionality of the *_http
function, only optional.
Any operator that maps to CCXT types should be suffixed with _ccxt
e.g. parse_book_ccxt
.
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
File details
Details for the file bittrade_cryptodotcom_websocket-0.1.15.tar.gz
.
File metadata
- Download URL: bittrade_cryptodotcom_websocket-0.1.15.tar.gz
- Upload date:
- Size: 25.6 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96f62e8acd9be0614d514504c90504fd11736ab736a827cbcfa0b9029aca8760 |
|
MD5 | 6066f773e4db192df56e44cbb7f07ae2 |
|
BLAKE2b-256 | 0f8beb73d90f5ed0e177557cd837d1bcc7a6c22d94a46d2c04149e087f8ecbed |
File details
Details for the file bittrade_cryptodotcom_websocket-0.1.15-py3-none-any.whl
.
File metadata
- Download URL: bittrade_cryptodotcom_websocket-0.1.15-py3-none-any.whl
- Upload date:
- Size: 44.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.5 Linux/5.4.72-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67bb6cc24183351059940132a7fb03ac67f5e8742a4f8895a6b11a1a72cde4f3 |
|
MD5 | 1727d51e697fcc3584478c7963d86939 |
|
BLAKE2b-256 | fb52fa3d230a762b33eb3cd276f76404a08956fa24f62aee0eea222f31df85e8 |