BitMEX
The BitMEX integration is still under active 开发.
Founded in 2014, BitMEX (Bitcoin Mercantile Exchange) is a cryptocurrency derivatives 交易平台 offering spot, perpetual contracts, traditional futures, and other advanced trading products. This integration supports live market 数据 ingest and order 执行 with BitMEX.
概览
This adapter is implemented in Rust, with optional Python bindings for ease of use in Python-based workflows. It does not require any external BitMEX 客户端 库 依赖.
There is no need for additional 安装 steps for BitMEX
.
The core components of the adapter are compiled as a static 库 and automatically linked during the build process.
示例
You can find live example scripts here.
Components
This 指南 assumes a trader is setting up for both live market 数据 feeds, and trade 执行. The BitMEX adapter includes multiple components, which can be used together or separately depending on the use case.
BitmexHttpClient
: Low-level HTTP API connectivity.BitmexWebSocketClient
: Low-level WebSocket API connectivity.BitmexInstrumentProvider
: Instrument parsing and loading functionality.BitmexDataClient
: A market data feed manager.BitmexExecutionClient
: An account management and trade execution gateway.BitmexLiveDataClientFactory
: Factory for BitMEX data clients (used by the trading node builder).BitmexLiveExecClientFactory
: Factory for BitMEX execution clients (used by the trading node builder).
Most users will simply define a 配置 for a 实时交易 节点 (as below), and won't need to necessarily work with these lower level components directly.
BitMEX 文档
BitMEX provides extensive 文档 for users:
- BitMEX API Explorer - Interactive API documentation.
- BitMEX API Documentation - Complete API reference.
- Contract Guides - Detailed contract specifications.
- Spot Trading Guide - Spot trading overview.
- Perpetual Contracts Guide - Perpetual swaps explained.
- Futures Contracts Guide - Traditional futures information.
It's recommended you refer to the BitMEX 文档 in conjunction with this NautilusTrader integration 指南.
Product 支持
Product Type | 数据 Feed | Trading | Notes |
---|---|---|---|
Spot | ✓ | ✓ | Limited pairs, unified wallet with derivatives. |
Perpetual Swaps | ✓ | ✓ | Inverse and linear contracts available. |
Futures | ✓ | ✓ | Traditional fixed expiration contracts. |
Quanto Futures | ✓ | ✓ | Settled in different currency than underlying. |
Options | - | - | Discontinued by BitMEX in April 2025. |
BitMEX discontinued their options products in April 2025 to focus on their core derivatives and spot offerings.
Spot trading
- Direct token/coin trading with immediate settlement.
- Major pairs including XBT/USDT, ETH/USDT, ETH/XBT.
- Additional altcoin pairs (LINK, SOL, UNI, APE, AXS, BMEX against USDT).
Derivatives
- Perpetual contracts: Inverse (e.g., XBTUSD) and linear (e.g., ETHUSDT).
- Traditional futures: Fixed expiration date contracts.
- Quanto futures: Contracts settled in a different currency than the underlying.
While BitMEX has added spot trading capabilities, their primary focus remains on derivatives. The platform uses a unified wallet for both spot and derivatives trading.
Symbology
BitMEX uses a specific naming convention for its trading symbols. Understanding this convention is crucial for correctly identifying and trading 金融工具.
Symbol format
BitMEX symbols typically follow these patterns:
- Spot pairs: Base currency + Quote currency (e.g.,
XBT/USDT
,ETH/USDT
). - Perpetual contracts: Base currency + Quote currency (e.g.,
XBTUSD
,ETHUSD
). - Futures contracts: Base currency + Expiry code (e.g.,
XBTM24
,ETHH25
). - Quanto contracts: Special naming for non-USD settled contracts.
BitMEX uses XBT
as the symbol for Bitcoin instead of BTC
. This follows the ISO 4217
currency code standard where "X" denotes non-national currencies. XBT and BTC refer to
the same asset - Bitcoin.
Expiry codes
Futures contracts use standard futures month codes:
F
= January,G
= February,H
= MarchJ
= April,K
= May,M
= JuneN
= July,Q
= August,U
= SeptemberV
= October,X
= November,Z
= December
Followed by the year (e.g., 24
for 2024, 25
for 2025).
NautilusTrader instrument IDs
Within NautilusTrader, BitMEX 金融工具 are identified using the native BitMEX symbol directly, combined with the venue identifier:
from nautilus_trader.model.identifiers import InstrumentId
# Spot pairs (note: no slash in the symbol)
spot_id = InstrumentId.from_str("XBTUSDT.BITMEX") # XBT/USDT spot
eth_spot_id = InstrumentId.from_str("ETHUSDT.BITMEX") # ETH/USDT spot
# Perpetual contracts
perp_id = InstrumentId.from_str("XBTUSD.BITMEX") # Bitcoin perpetual (inverse)
linear_perp_id = InstrumentId.from_str("ETHUSDT.BITMEX") # Ethereum perpetual (linear)
# Futures contract (June 2024)
futures_id = InstrumentId.from_str("XBTM24.BITMEX") # Bitcoin futures expiring June 2024
BitMEX spot symbols in NautilusTrader don't include the slash (/) that appears in the
BitMEX UI. Use XBTUSDT
instead of XBT/USDT
.
Order capability
BitMEX currently supports a limited set of order types in this integration, with additional functionality being actively developed.
Order types
Order Type | Supported | Notes |
---|---|---|
MARKET | ✓ | Executed immediately at current market price. |
LIMIT | ✓ | Executed only at specified price or better. |
STOP_MARKET | - | Currently under 开发. |
STOP_LIMIT | - | Currently under 开发. |
MARKET_IF_TOUCHED | - | Currently under 开发. |
LIMIT_IF_TOUCHED | - | Currently under 开发. |
TRAILING_STOP_MARKET | - | Not yet implemented. |
执行 instructions
Instruction | Supported | Notes |
---|---|---|
post_only | ✓ | Supported via ParticipateDoNotInitiate on LIMIT 订单. |
reduce_only | - | Currently under 开发. |
Post-only 订单 are implemented using BitMEX's ParticipateDoNotInitiate
执行
instruction, which ensures 订单 are added to the order book as maker 订单 only.
Time in force
Time in force | Supported | Notes |
---|---|---|
GTC | ✓ | Good Till Canceled (default). |
GTD | - | Not supported by BitMEX. |
FOK | - | Currently under 开发. |
IOC | - | Currently under 开发. |
Advanced order features
功能 | Supported | Notes |
---|---|---|
Order Modification | - | Currently under 开发. |
Bracket 订单 | - | Not yet implemented. |
Iceberg 订单 | - | Supported by BitMEX, not yet implemented. |
Batch operations
Operation | Supported | Notes |
---|---|---|
Batch Submit | - | Not yet implemented. |
Batch Modify | - | Not yet implemented. |
Batch Cancel | - | Not yet implemented. |
Position management
功能 | Supported | Notes |
---|---|---|
Query 头寸 | ✓ | 实时 position updates via WebSocket. |
Leverage control | - | Currently under 开发. |
Cross margin | ✓ | Default margin mode. |
Isolated margin | - | Currently under 开发. |
Order querying
功能 | Supported | Notes |
---|---|---|
Query open 订单 | ✓ | List all active 订单. |
Query order history | ✓ | Historical order 数据. |
Order status updates | ✓ | 实时 order state changes via WebSocket. |
Trade history | ✓ | 执行 and fill 报告. |
Rate limits
BitMEX implements a dual-layer rate limiting system:
REST API limits
- Primary rate limit:
- 120 requests per minute for authenticated users.
- 30 requests per minute for unauthenticated users.
- Uses a token bucket mechanism with continuous refill.
- Secondary rate limit:
- 10 requests per second burst limit for specific endpoints (订单管理).
- Applies to order placement, modification, and cancellation.
- Order limits:
- 200 open 订单 per symbol per account.
- 10 stop 订单 per symbol per account.
The adapter automatically respects these limits through built-in rate limiting with a 10 requests/second quota that handles both the burst limit and average rate 要求.
WebSocket limits
- 20 connections per hour per IP address
- 身份验证 required for private 数据 streams
Rate limit headers
BitMEX provides rate limit information in response headers:
x-ratelimit-limit
: Total allowed requestsx-ratelimit-remaining
: Remaining requests in current windowx-ratelimit-reset
: Unix timestamp when limits resetretry-after
: Seconds to wait if rate limited (429 response)
Exceeding rate limits will result in HTTP 429 responses and potential temporary IP bans. Multiple 4xx/5xx errors in quick succession may trigger longer bans.
Connection management
HTTP Keep-Alive
The BitMEX adapter utilizes HTTP keep-alive for optimal 性能:
- Connection pooling: Connections are automatically pooled and reused.
- Keep-alive timeout: 90 seconds (matches BitMEX server-side timeout).
- Automatic reconnection: Failed connections are automatically re-established.
- SSL session caching: Reduces handshake overhead for subsequent requests.
This 配置 ensures 低延迟 communication with BitMEX servers by maintaining persistent connections and avoiding the overhead of establishing new connections for each request.
Request expiration
BitMEX uses an API-expires
header for request 身份验证:
- Requests include a UNIX timestamp indicating when they expire.
- Default expiration window is 10 seconds from request creation.
- Prevents replay attacks and ensures request freshness.
配置
API credentials
BitMEX API credentials can be provided either directly in the 配置 or via 环境 variables:
BITMEX_API_KEY
: Your BitMEX API key.BITMEX_API_SECRET
: Your BitMEX API secret.
To generate API keys:
- Log in to your BitMEX account.
- Navigate to Account & 安全性 → API Keys.
- Create a new API key with appropriate permissions.
- For testnet, use testnet.bitmex.com.
配置 示例
A typical BitMEX 配置 for 实时交易 includes both testnet and mainnet options:
from nautilus_trader.adapters.bitmex.config import BitmexDataClientConfig
from nautilus_trader.adapters.bitmex.config import BitmexExecClientConfig
# Using environment variables (recommended)
testnet_data_config = BitmexDataClientConfig(
testnet=True, # API credentials loaded from BITMEX_API_KEY and BITMEX_API_SECRET
)
# Using explicit credentials
mainnet_data_config = BitmexDataClientConfig(
api_key="YOUR_API_KEY", # Or use os.getenv("BITMEX_API_KEY")
api_secret="YOUR_API_SECRET", # Or use os.getenv("BITMEX_API_SECRET")
testnet=False,
)
mainnet_exec_config = BitmexExecClientConfig(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
testnet=False,
)
Trading considerations
Contract specifications
- Inverse contracts: Settled in cryptocurrency (e.g., XBTUSD settled in XBT).
- Linear contracts: Settled in stablecoin (e.g., ETHUSDT settled in USDT).
- Contract size: Varies by instrument, check specifications carefully.
- Tick size: Minimum price increment varies by contract.
Margin 要求
- Initial margin 要求 vary by contract and market conditions.
- 维护 margin is typically lower than initial margin.
- Liquidation occurs when equity falls below 维护 margin.
Fees
- Maker fees: Typically negative (rebate) for providing liquidity.
- Taker fees: Positive fee for taking liquidity.
- Funding rates: Apply to perpetual contracts every 8 hours.
Known limitations
The BitMEX integration is actively being developed. Current limitations include:
- Limited order type 支持 (only MARKET and LIMIT 订单 for now).
- Post-only functionality pending full 实现.
- Stop 订单 and advanced order types not yet available.
- Batch operations not implemented.
- Margin mode switching not available.
We welcome contributions to extend the BitMEX adapter functionality. Please see our contributing guide for more information.