BitMEX was founded in 2014 by Arthur Hayes, Ben Delo, and Samuel Reed in Hong Kong, originally incorporating in Seychelles. The exchange launched the XBT/USD perpetual swap contract in 2016 — the first cryptocurrency perpetual futures contract, which has since become the dominant trading instrument in crypto derivatives with hundreds of billions in daily volume across all exchanges that copied BitMEX's design. BitMEX's perpetual swap contract enabled 100x leveraged Bitcoin trading with no expiry date — a novel instrument that combined the economic exposure of futures with the indefinite duration of spot trading, maintained at the spot price through the funding rate mechanism.
BitMEX's Innovations and Their Industry Impact
BitMEX's technical innovations defined derivatives exchange design for a decade: (1) The Perpetual Swap — a futures contract with no settlement date, maintained at spot price through a funding rate exchange between longs and shorts every 8 hours. (2) Auto-Deleveraging (ADL) — when the insurance fund is insufficient to absorb a liquidated position, winning traders are automatically reduced to provide liquidity. (3) Insurance Fund — a fund accumulated from partial liquidation proceeds, used to cover situations where liquidated positions are taken over below the bankruptcy price, preventing cascading socialized losses. All major derivatives exchanges (Binance, Bybit, OKX, Hyperliquid) use variants of these BitMEX-pioneered mechanisms.
Setting Up API Keys for a Trading Bot on BitMEX
BitMEX requires identity verification (KYC) for full trading access. API keys allow programmatic order management with configurable permissions and IP restrictions.
Step 1: Complete Account Verification
Log in at bitmex.com. Navigate to Account Settings -> Identification. Complete KYC with government ID and address proof. Full verification is required for API key creation and unrestricted trading.
Step 2: Create API Keys
Go to Account Settings -> API Keys -> New API Key. Configure permissions with minimum privilege:
- Key Permissions: Order (place/cancel orders) — select this
- Withdraw — NEVER enable for a trading bot
- CIDR IP Whitelist: Enter your VPS IP (e.g., 187.124.235.132) — required, not optional
Step 3: Store Credentials Securely
export BITMEX_API_KEY="your_api_key_here"
export BITMEX_API_SECRET="your_api_secret_here"
Step 4: Connect with Python
import os
import time
import hashlib
import hmac
import requests
BITMEX_API_KEY = os.environ.get("BITMEX_API_KEY")
BITMEX_API_SECRET = os.environ.get("BITMEX_API_SECRET")
BASE_URL = "https://www.bitmex.com"
if not BITMEX_API_KEY or not BITMEX_API_SECRET:
raise RuntimeError("BitMEX credentials not set in environment variables")
def bitmex_signature(secret: str, verb: str, path: str, expires: int, data: str = "") -> str:
# BitMEX HMAC-SHA256 signature: verb + path + expires + data
message = verb + path + str(expires) + data
return hmac.new(
secret.encode("utf-8"),
message.encode("utf-8"),
hashlib.sha256
).hexdigest()
def get_position(symbol: str = "XBTUSD") -> dict:
# Fetch current position for a symbol
verb, path = "GET", "/api/v1/position"
expires = int(time.time()) + 60
headers = {
"api-key": BITMEX_API_KEY,
"api-signature": bitmex_signature(BITMEX_API_SECRET, verb, path, expires),
"api-expires": str(expires),
"Content-Type": "application/json",
}
resp = requests.get(
f"{BASE_URL}{path}",
headers=headers,
params={"filter": f'{{"symbol": "{symbol}"}}'},
timeout=10,
)
resp.raise_for_status()
return resp.json()
def place_limit_order(symbol: str, side: str, qty: int, price: float) -> dict:
# Place a limit order. side: 'Buy' or 'Sell'. qty in contracts (1 XBT contract = $1 USD).
import json
verb, path = "POST", "/api/v1/order"
expires = int(time.time()) + 60
body = json.dumps({"symbol": symbol, "side": side, "orderQty": qty, "price": price, "ordType": "Limit"})
headers = {
"api-key": BITMEX_API_KEY,
"api-signature": bitmex_signature(BITMEX_API_SECRET, verb, path, expires, body),
"api-expires": str(expires),
"Content-Type": "application/json",
}
resp = requests.post(f"{BASE_URL}{path}", headers=headers, data=body, timeout=10)
resp.raise_for_status()
return resp.json()
if __name__ == "__main__":
positions = get_position("XBTUSD")
print("Current XBTUSD position:", positions)
BitMEX API security checklist:
- Order permission only — never Withdraw
- CIDR IP whitelist: VPS IP only (mandatory in BitMEX's API form)
- Credentials: OS environment variables only
- BitMEX uses HMAC-SHA256 with timestamp expiry — always set
api-expiresto avoid replay attacks - Test on Testnet (testnet.bitmex.com) before trading real funds
BitMEX: Pioneer of Crypto Perpetual Swaps
BitMEX invented the crypto perpetual swap contract — the XBT/USD perpetual with a funding rate mechanism that keeps the contract price anchored to spot without expiry — and this product structure has become the standard for virtually every crypto derivatives exchange that followed. While BitMEX has lost significant market share to Binance Futures, Bybit, and OKX, it retains a user base of professional traders who value its deep liquidity on BTC/USD and institutional-grade API infrastructure. The funding rate mechanism on BitMEX's perpetuals adjusts every 8 hours based on the spread between perp and spot prices, incentivizing traders to take positions that push the contract back toward spot when it deviates significantly.
BitMEX's insurance fund accumulated from partial liquidations protects the platform from auto-deleveraging (where profitable traders are force-closed to cover bankrupt positions) — a large insurance fund reduces the frequency of socializing losses across profitable traders. The BMEX token was launched as a platform loyalty token providing fee discounts, early product access, and staking yields. BitMEX underwent significant legal and regulatory challenges in 2020 (DOJ charges against founders), which accelerated its market share loss, but it has remained operational as a derivatives platform under new management. Use our crypto tools and DennTech blog for BitMEX and derivatives exchange analysis.
BitMEX's testnet environment is one of the most comprehensive simulation environments for crypto derivatives — providing realistic paper trading with identical mechanics to the live platform at no cost. This testnet is widely used by trading bot developers to test strategies and API integrations before deploying with real capital. BitMEX's API documentation is among the most thorough in the derivatives exchange space, with detailed WebSocket streaming, REST endpoints, and authentication examples that have made BitMEX's API a standard reference implementation that other exchanges have modeled their own APIs after.
BitMEX introduced auto-deleveraging (ADL) as a mechanism for handling large underwater positions without requiring a large insurance fund — when the insurance fund is insufficient to cover a bankrupt position, profitable traders in the opposite direction are selectively auto-deleveraged at the bankruptcy price. While ADL is unpopular among traders (profitable positions can be force-closed without warning), it prevents the risk mutualization problems that plagued earlier crypto futures platforms. BitMEX's index price for BTC/USD is calculated as the weighted average of spot prices from multiple reference exchanges, providing manipulation resistance for settlement calculations.