Skip to main content

# Python Adapter for BitMEX Realtime Data

This is a reference adapter for receiving realtime data from the BitMEX API. See [the BitMEX documentation](https://testnet.bitmex.com/app/wsAPI) for more information on the websocket API.

# Installation

pip install bitmex-ws

# Quickstart

BitMEXWebsocket is the main entry point to connect to the BitMEX websocket API. The API supports both authenticated and unauthenticated clients. Some endpoints require credentials, for more info see [the documentation on authentication.](https://testnet.bitmex.com/app/wsAPI#Authentication)

To get started, instantiate a connection:

from bitmex_websocket import BitMEXWebsocket ws = BitMEXWebsocket(endpoint=”https://testnet.bitmex.com/api/v1”, symbol=”XBTUSD”, api_key=None, api_secret=None)

If you want to subscribe to authenticated data streams, [create an API key](https://testnet.bitmex.com/app/apiKeys) and supply the corresponding values in api_key and api_secret. BitMEX has two systems - testnet for simulated trading and testing, and www for live trading. API keys are specific to one system. If you created the key on testnet, make sure your connection string points to testnet as well.

Once you are connected, you can retrieve data via the connector’s methods. The latest data will be streamed to the client - no need to poll the server.

ws.get_instrument() ws.get_ticker() ws.funds() ws.market_depth() ws.open_orders() ws.recent_trades()

main.py has a full example of how to connect to BitMEX:

$ python main.py 2018-02-01 11:51:53,355 - bitmex_websocket - INFO - Connecting to wss://testnet.bitmex.com/realtime?subscribe=execution:XBTUSD,instrument: … 2018-02-01 11:51:53,356 - bitmex_websocket - INFO - Not authenticating. 2018-02-01 11:51:54,357 - bitmex_websocket - INFO - Connected to WS. 2018-02-01 11:51:54,360 - bitmex_websocket - INFO - Got all market data. Starting. 2018-02-01 11:51:54,364 - root - INFO - Ticker: {‘last’: 8947.0, ‘sell’: 8948.0, ‘buy’: 8947.0, ‘mid’: 8947.0} 2018-02-01 11:51:54,369 - root - INFO - Market Depth: [{‘id’: 15500000950, ‘side’: ‘Sell’, ‘size’: 384, ‘price’: 999990.5, ‘symbol’: ‘XBTUSD’ … 2018-02-01 11:51:54,370 - root - INFO - Recent Trades: [{‘side’: ‘Sell’, ‘size’: 29856, ‘price’: 8947, ‘symbol’: ‘XBTUSD’, ‘timestamp’: …

# Compatibility This module supports Python 3.5+.

Metadata

Release files for bitmex-ws-alpha 0.4.2

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

Source distribution (sdist)

Source distribution for bitmex-ws-alpha 0.4.2
File Size Uploaded
bitmex-ws-alpha-0.4.2.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bitmex-ws-alpha 0.4.2
File Interpreter ABI Platform
bitmex_ws_alpha-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.1 kB

Release files / bitmex-ws-alpha-0.4.2.tar.gz

Download URL bitmex-ws-alpha-0.4.2.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d209aa646156b45e00d24825e1e9a16baa712413e148568d2c076663996db46d
BLAKE2b-256 checksum
How to use checksums
b12af081d84c849f019f29d1d64b07978099ecdf678a16c1191abfcf2abdac73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

Release files / bitmex_ws_alpha-0.4.2-py3-none-any.whl

Download URL bitmex_ws_alpha-0.4.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c8f66f5ee94ac3aa712c3d6ef92fe44bb94df7696784b778822b2dfaf6ccef6
BLAKE2b-256 checksum
How to use checksums
f4f7d53a17e1faabe6885daae2ba006877b9e7a235231157c8b2b5a9c0fe9b7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

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