Websocket implementation for BitMEX cryptocurrency derivatives exchange.
Project description
BitMEX Trio-Websocket
Websocket implementation for BitMEX cryptocurrency derivatives exchange.
- Free software: MIT license
- Documentation: https://bitmex-trio-websocket.readthedocs.io.
Features
- Connects to BitMEX websockets for a given symbol or lists of symbols.
- Supports authenticated connections using api keys.
- Fully async using async generators. No callbacks or event emitters.
- Based on trio and trio-websocket.
Installation
This library requires Python 3.7 or greater. It could probably be made to run with Python 3.6, since this is the minimal version where async generators are supported. To install from PyPI:
pip install bitmex-trio-websocket
Client example
import trio
from bitmex_trio_websocket import BitMEXWebsocket
async def main():
bws = BitMEXWebsocket('mainnet', 'XBTUSD')
async for message in bws.start():
print(message)
trio.run(main)
This will print a sequence of tuples of the form (item, symbol|None, table, action), where -
item is the full object resulting from inserting or merging the changes to an item.
symbol is the symbol that was changed or None if the table isn't a symbol table.
table is the table name.
action is the action that was taken.
Note, that delete actions are simply applied and consumed, with no output sent.
API
Creates a new websocket object.
endpoint str
Network to connect to. Options: 'mainnet', 'testnet'.
symbol Optional[Union[str, Iterable[str]]]
Symbols to subscribe to. Each symbol is subscribed to the following channels: ['instrument', 'quote', 'trade', 'tradeBin1m']. If not provided, no instrument channels are subscribed for this connection. This may be useful if you only want to connect to authenticated channels.
api_key Optional[str]
Api key for authenticated connections. If a valid api key and secret is supplied, the following channels are subscribed: ['margin', 'position', 'order', 'execution'].
api_secret Optional[str]
Api secret for authenticated connections.
Returns an async generator object that yields messages from the websocket.
This attribute contains the storage object for the websocket. The storage object has two properties data and keys. data contains the table state for each channel as a dictionary with the table name as key. The tables themselves are flat lists. keys contains a list of keys by which to look up values in each table. There is a helper function findItemByKeys in the storage unit, which assists in finding particular items in each table. Tables are searched sequentially until a match is found, with is somewhat inefficient. However since there is never a lot of records in each table (at most 200), this is reasonably fast in practice and not a bottleneck.
When connected, contains the underlying trio-websocket object. Can be used to manage the connection.
See - https://trio-websocket.readthedocs.io/en/stable/api.html#connections
Credits
Thanks to the Trio and Trio-websocket libraries for their awesome work.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
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
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 bitmex-trio-websocket-0.2.8.tar.gz.
File metadata
- Download URL: bitmex-trio-websocket-0.2.8.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.8.0 Linux/4.15.0-1028-gcp
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0378f72e0ed8b1db664a293452f58cf140c3731f0a716d3cb60c357e3bd3671f
|
|
| MD5 |
c26ac1a2b75a95b499641de7955f5f00
|
|
| BLAKE2b-256 |
092794513c2ee2eaf07dc785637086c1acffe0103b8dc8aedb489029b53f97c7
|
File details
Details for the file bitmex_trio_websocket-0.2.8-py3-none-any.whl.
File metadata
- Download URL: bitmex_trio_websocket-0.2.8-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.8.0 Linux/4.15.0-1028-gcp
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd8efa2e36f298862e5e2a39b3b143ed4989c19d1d589b22db77a78e2e8f8857
|
|
| MD5 |
38c3020754554dbaf4aaffb7bc984c28
|
|
| BLAKE2b-256 |
d8edb4eedbd9dd530d8de391b5fd5df7e2f1e0cff60f6e8be94291ca4c36ca68
|