SDKs overview
Bitmex provides Software Development Kits (SDKs) and client libraries designed to facilitate programmatic interaction with its trading platform. These resources enable developers to integrate Bitmex functionalities, such as order placement, account management, and real-time market data access, directly into custom applications. The platform supports both REST API endpoints for transactional operations and WebSocket APIs for real-time data streaming, as detailed in the Bitmex WebSocket API introduction.
The availability of SDKs simplifies the development process by abstracting the underlying HTTP requests and WebSocket protocols, allowing developers to focus on trading logic rather than low-level API communication. Official SDKs are maintained directly by Bitmex, while a range of community-contributed libraries extends support to additional programming languages and specific use cases. All interactions require API keys for authentication, which can be generated and managed within a Bitmex account, as outlined in the Bitmex REST API documentation.
Integrating with a cryptocurrency exchange's API often involves managing security, rate limits, and data serialization. SDKs are designed to handle these aspects, providing methods for signing requests, managing connection states, and parsing responses. For example, common API security practices, such as HMAC authentication, are often encapsulated within SDK functions, reducing the potential for implementation errors. Developers leveraging these tools can build automated trading bots, portfolio management systems, or custom trading interfaces that interact directly with the Bitmex exchange.
Official SDKs by language
Bitmex officially supports SDKs for Python and Node.js. These SDKs are maintained by the Bitmex team and provide comprehensive access to both the REST and WebSocket APIs. They include functionalities for authentication, rate limit handling, and data parsing, aligning with the specifications in the Bitmex API reference.
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | bitmex-market-maker |
pip install bitmex-market-maker |
Official, actively maintained for market making strategies |
| Node.js | bitmex-api-node |
npm install bitmex-api-node |
Official, actively maintained |
The Python bitmex-market-maker package, while named for market making, provides general API client functionality and examples that can be adapted for various trading strategies. It includes components for managing orders, positions, and user data. The Node.js bitmex-api-node library offers similar capabilities for JavaScript environments, enabling real-time data subscriptions via WebSockets and execution of REST API calls.
Installation
Installation of the official Bitmex SDKs typically involves using standard package managers for Python and Node.js. Developers should ensure they have the respective language runtime and package manager installed.
Python SDK
To install the official Python SDK, bitmex-market-maker, use pip:
pip install bitmex-market-maker
It is recommended to use a virtual environment to manage dependencies for Python projects. For example, creating and activating a virtual environment before installation can prevent conflicts with system-wide packages. The Bitmex API documentation provides further context on the Python client usage.
Node.js SDK
To install the official Node.js SDK, bitmex-api-node, use npm or yarn:
npm install bitmex-api-node
Alternatively, using yarn:
yarn add bitmex-api-node
Ensure Node.js and npm (or yarn) are properly installed on your system before attempting these commands. The Node.js client typically requires a recent version of Node.js for full compatibility and performance.
Quickstart example
This example demonstrates how to use the official Python SDK to fetch recent trades from Bitmex. This requires valid API keys (apiKey and apiSecret) configured for your account, which can be found in your Bitmex API Keys settings. For security, these should ideally be loaded from environment variables or a configuration file rather than hardcoded.
Python Quickstart
First, ensure the bitmex-market-maker (or a compatible Bitmex client library) is installed. The example uses a common client structure to interact with the Bitmex REST API.
import bitmex
import os
# Replace with your actual API key and secret, or load from environment variables
API_KEY = os.getenv('BITMEX_API_KEY', 'YOUR_BITMEX_API_KEY')
API_SECRET = os.getenv('BITMEX_API_SECRET', 'YOUR_BITMEX_API_SECRET')
# Initialize Bitmex client for testnet (or mainnet)
# For mainnet, change base_url to 'https://www.bitmex.com/api/v1/'
client = bitmex.bitmex(test=True, api_key=API_KEY, api_secret=API_SECRET)
try:
# Fetch recent trades for XBTUSD
# The 'count' parameter specifies the number of trades to retrieve
# The 'reverse' parameter set to True fetches the most recent trades first
trades = client.Trade.Trade_get(symbol='XBTUSD', count=10, reverse=True).result()
print("Recent XBTUSD Trades:")
for trade in trades[0]:
print(f"Timestamp: {trade['timestamp']}, Price: {trade['price']}, Size: {trade['size']}, Side: {trade['side']}")
except Exception as e:
print(f"An error occurred: {e}")
print("\nFetching Wallet Balance for authenticated user:")
try:
# Authenticated call to get wallet balance
wallet_balance = client.User.User_getWallet().result()
if wallet_balance:
print(f"Wallet Balance (XBt): {wallet_balance[0]['amount'] / 100000000} XBT") # Convert satoshis to XBT
else:
print("Could not retrieve wallet balance.")
except Exception as e:
print(f"Error fetching wallet balance: {e}")
This Python snippet first initializes a Bitmex client, configured for either the testnet or mainnet depending on the test parameter. It then makes an unauthenticated call to retrieve the 10 most recent trades for the XBTUSD pair using the Trade_get method. Following this, it makes an authenticated call using User_getWallet to retrieve the user's wallet balance. Successful execution will print a list of trades and the wallet balance. Note that API key management is crucial for production environments, typically involving secure storage and retrieval methods.
Community libraries
Beyond the official SDKs, the Bitmex developer community has contributed various libraries and wrappers in different programming languages. These community-driven projects can offer alternative implementations, specialized functionalities, or support for languages not officially covered by Bitmex. While not officially supported, they are often used by developers for specific trading strategies or integrations.
- PHP: Several unofficial PHP clients are available, often found on GitHub, providing an interface for server-side applications. These typically replicate the REST and WebSocket API calls in a PHP-friendly manner.
- Java/Kotlin: Community libraries for Java and Kotlin often leverage existing HTTP client frameworks to interact with the Bitmex API, providing type-safe and idiomatic interfaces.
- Go: Go language wrappers can be found that offer concurrent and efficient ways to interact with Bitmex, particularly for high-frequency trading applications.
- C#: .NET developers can find C# libraries that integrate with Bitmex, often supporting both synchronous and asynchronous API calls.
When using community libraries, it is important to review their source code, check for active maintenance, and understand their licensing. The quality and security of these libraries can vary. Developers often consult the Mozilla WebSockets API documentation for understanding core WebSocket concepts when evaluating community WebSocket clients.
Examples of community libraries often focus on specific features, such as advanced order types not directly exposed by basic client methods, or integration with specific trading frameworks. Some libraries might also include historical data fetching tools or backtesting capabilities. Developers should always refer to the Bitmex official API documentation to ensure compatibility and correctness when using any third-party library, as API specifications can evolve.