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 property 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.
======= History
0.2.3 (2019-11-24)
- Added documentation.
0.2.1 (2019-11-24)
- First release on PyPI.
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
Hashes for bitmex-trio-websocket-0.2.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d32cc4194d4136015ca234acbed99efcdebd22e4d8320e4337bd72e2067a2364 |
|
MD5 | 00bd57d45e45afda7af9d34cb82fcd23 |
|
BLAKE2b-256 | 7e4ee0f6b3f6af189b1e1b945341584ad72e93ee1fff1d660262b5486106ca46 |
Hashes for bitmex_trio_websocket-0.2.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e60035dedec23e4c9384333b75c3ccd7a8b6f82c27a873b1adabd4751a63f76 |
|
MD5 | 5b66219f2694fb6101c26cd94bb60f0c |
|
BLAKE2b-256 | 82a54ca0261178ff5d941a2beea6da7d56322cb713c722b9a9c86caa5ff70a77 |