Skip to main content

FoRK: Sample adapter for connecting to the BitMEX Websocket API.

Project description

# 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+.

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

bitmex-ws-onix-0.3.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

bitmex_ws_onix-0.3.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file bitmex-ws-onix-0.3.1.tar.gz.

File metadata

  • Download URL: bitmex-ws-onix-0.3.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for bitmex-ws-onix-0.3.1.tar.gz
Algorithm Hash digest
SHA256 54ae4e67b8f74d17797f18a12c449425024edd06ce047a14195ada04e9f4b027
MD5 f4e94818dcd0edccc3e53ec86ea75338
BLAKE2b-256 11deac216519beee91bd43b78729d8f328acdb624986649d1d9420e52a4dd9a6

See more details on using hashes here.

File details

Details for the file bitmex_ws_onix-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: bitmex_ws_onix-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for bitmex_ws_onix-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 691c1899cbfa7fcefe0871a6969bf88ee20c9c238dc0a0e5a9efdba81c40442e
MD5 67e3753611ff975b9003f362c81459ff
BLAKE2b-256 05359db3d63722c8b23ec13be46b49667da04e75a63b5776f88b061aec1ff79d

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