Please note BitMEX does not support old browsers.
We recommend upgrading to the latest version of Opera, Firefox, or Chrome.

BitMEX trading is not available in your region

AllXBTUSDT28474.5+0.83%XBTUSD28480.0+0.87%XBTEUR26260.5+1.19%XBTJ2328447.0-0.19%XBTUSDTM2328613.0+0.48%XBTM2328727.0+0.99%XBTUSDTU2328302.0-4.02%XBTU2328887.0+0.99%XBTZ2328986.5+1.22%ETHUSDT1830.70+2.66%ETHUSD1831.70+2.59%ETHUSD_ETH1826.05+1.46%ETHUSDM231979.00+2.09%ETHM230.06507+3.22%ETHUSDTM231888.00+0.01%BMEXUSDT0.428+0.47%BMEXUSD0.427-0.93%ADAUSDT0.4030+6.04%ADAUSD0.4050+8.12%ADAM230.00001392+3.11%APEUSDT4.147+2.50%APTUSD11.318+1.17%APTUSDT11.386+1.30%ARBUSDT1.373+3.16%ARBUSD1.379+2.00%ARBUSDTM231.393-2.59%AVAXUSD17.583+2.00%AVAXUSDT17.639+1.20%AXSUSD8.34+1.71%BCHUSD123.90+1.76%BCHUSDT123.70+1.06%BLURUSD0.6400+19.23%BLURUSDT0.6070+19.96%BNBUSD316.97+0.23%BNBUSDT314.00+0.00%CROUSD0.06910+0.26%CROUSDT0.06900+0.00%DOGEUSDT0.07580+1.19%DOGEUSD0.07596+1.56%DOTUSDT6.349+3.32%DOTUSD6.328+3.92%EOSUSD1.1943+0.19%FLRUSD0.0352-7.37%FLRUSDT0.0367+0.00%GMTUSDT0.3903+1.40%GMTUSD0.3908+2.09%GMXUSD76.00+0.98%GMXUSDT75.30+0.00%KLAYUSDT0.22747-3.59%KLAYUSD0.22621-1.43%LINKUSD7.576+4.61%LTCUSDT89.63+1.03%LTCUSD89.61+1.04%LUNAUSDT1.2697-0.58%LUNAUSD1.2883+0.18%MATICUSDT1.1107+1.97%NEARUSD1.986+2.11%SOLUSDT20.86+2.55%SOLUSD20.93+2.60%USDTUSDC1.0000-1.04%XRPUSDT0.5308-0.34%XRPUSD0.5300-0.24%XRPM230.00001879-1.62%Funding: 03:52:43 @ 0.0100%Time: 4:07:16 PM UTC
BitMEX header logo
WebSocket API

BitMEX offers a complete pub/sub API with table diffing over WebSocket. You may subscribe to real-time changes on any available table.

Reference Connectors

For working code and examples, please see our WebSocket Connectors on GitHub.


Connect your websocket client to the primary websocket endpoint wss:// for trading related topics (see below).

Alternate endpoints depending on topic:

  • For platform topics, wss://

You can get a basic idea of how to use our websocket API by sending "help".

All Commands

A basic command is sent in the following format:

{"op": "<command>", "args": ["arg1", "arg2", "arg3"]}

The args array is optional on some commands. If you are only sending a single argument, the array is not necessary.

Note that placing and canceling orders is not supported via the Websocket. Please use the REST API for this. When using HTTP Keep-Alive, request/response round-trip time will be identical to Websocket.


BitMEX allows subscribing to real-time data. This access is not rate-limited once connected and is the best way to get the most up-to-date data to your programs.

To subscribe to topics, send them as a comma-separated list in your connection string. For example:


If you are already connected and wish to subscribe to a new topic, send a message with the following format:

{"op": "subscribe", "args": [<SubscriptionTopic>]}

You may subscribe to multiple topics at a time by sending an array of subscription topics.

The following subscription topics are available on the primary endpoint without authentication:

"funding",             // Updates of swap funding rates. Sent every funding interval (usually 8hrs)
"instrument",          // Instrument updates including turnover and bid/ask
"insurance",           // Daily Insurance Fund updates
"liquidation",         // Liquidation orders as they're entered into the book
"orderBookL2_25",      // Top 25 levels of level 2 order book
"orderBookL2",         // Full level 2 order book
"orderBook10",         // Top 10 levels using traditional full book push
"quote",               // Top level of the book
"quoteBin1m",          // 1-minute quote bins
"quoteBin5m",          // 5-minute quote bins
"quoteBin1h",          // 1-hour quote bins
"quoteBin1d",          // 1-day quote bins
"settlement",          // Settlements
"trade",               // Live trades
"tradeBin1m",          // 1-minute trade bins
"tradeBin5m",          // 5-minute trade bins
"tradeBin1h",          // 1-hour trade bins
"tradeBin1d",          // 1-day trade bins

The following subscription topics require authentication and are also available on the primary endpoint:

"affiliate",   // Affiliate status, such as total referred users & payout %
"execution",   // Individual executions; can be multiple per order
"order",       // Live updates on your orders
"margin",      // Updates on your current account balance and margin requirements
"position",    // Updates on your positions
"transact"     // Deposit/Withdrawal updates
"wallet"       // Bitcoin address balance data, including total deposits & withdrawals

The following subscriptions are only available on the /realtimePlatform endpoint:

"announcement",        // Site announcements
"chat",                // Trollbox chat
"connected",           // Statistics of connected users/bots
"publicNotifications", // System-wide notifications (used for short-lived messages)
"privateNotifications", // Individual notifications - currently not used (requires auth)

If you wish to get real-time order book data, we recommend you use the orderBookL2_25 subscription. orderBook10 pushes the top 10 levels on every tick, but transmits much more data. orderBookL2 pushes the full L2 order book, but the payload can get very large. orderbookL2_25 provides a subset of the full L2 orderbook, but is throttled. In the future, orderBook10 may be throttled, so use orderBookL2 in any latency-sensitive application. For those curious, the id on an orderBookL2_25 or orderBookL2 entry is a composite of price and symbol, and is always unique for any given price level. It should be used to apply update and delete actions.

When applicable, topics may be filtered to a given instrument by appending a colon and instrument name. For example, trade:XBTUSD will subscribe you to messages only for the XBTUSD instrument.

Some traffic:

> {"op": "subscribe", "args": ["orderBookL2_25:XBTUSD"]}
  < {"success":true,"subscribe":"orderBookL2_25:XBTUSD","request":{"op":"subscribe","args":["orderBookL2_25:XBTUSD"]}}
  < {
  < {
  < {
  < {

Upon subscription, you will receive an image of the existing data, so you can get started. This comes through as a partial action.

You may receive other messages before the partial comes through. In that case, drop any messages received until you have received the partial.

Some notes on this response:

  • After the subscription acknowledgement, you’ll receive a message with "action": "partial". This is an image of the table, after which you can apply deltas.
    • If you receive any messages before the partial, ignore them.
  • The partial also contains some table information, like keys and types. Depending on your application, this data may be useful.
    • Columns listed in keys always come back on an insert, delete, or update. Use them to look up which items to modify in your storage.

For an example of this in action, see our official NodeJS Delta Parser.

You may unsubscribe using the 'unsubscribe' operation. The formatting is identical to 'subscribe'.


A number of data streams are publicly available (see below). If you wish to subscribe to user-locked streams, you must authenticate first. Note that invalid authentication will close the connection.

API Keys

BitMEX API usage requires an API Key.

Permanent API Keys can be locked to IP address ranges and revoked at will without compromising your main credentials. They also do not require renewal.

To use API Key auth, you must generate an API Key.

To use an API Key with websockets, you can either:

  • Sign the initial upgrade request in the same manner you would sign other REST calls (api-* headers), or
  • After connection, send an "authKeyExpires".

In both cases, use a signature as if you were signing GET /realtime. See this Python implementation for an example and working code.

If you have questions about authenticating with an API Key, please see the API Key Authentication Documentation.

// signature is hex(HMAC_SHA256(secret, 'GET/realtime' + expires))
// expires must be a number, not a string.
{"op": "authKeyExpires", "args": ["<APIKey>", <expires>, "<signature>"]}


Some WebSocket libraries are better than others at detecting connection drops. If your websocket library supports hybi-13, or ping/pong, you may send a ping at any time and the server will return with a pong.

Due to changes in browser power-saving modes, we no longer support expectant pings via the WebSocket API.

If you are concerned about your connection silently dropping, we recommend implementing the following flow:

  • After receiving each message, set a timer a duration of 5 seconds.
  • If any message is received before that timer fires, restart the timer.
  • When the timer fires (no messages received in 5 seconds), send a raw ping frame (if supported) or the literal string 'ping'.
  • Expect a raw pong frame or the literal string 'pong' in response. If this is not received within 5 seconds, throw an error or reconnect.

Dead Man’s Switch (Auto Cancel)

BitMEX offers “Dead Man’s Switch” functionality to help prevent unexpected losses from network malfunctions. If you are putting up significant risk on BitMEX, it can be nerve-wracking to think of what might happen if you or your datacenter loses connectivity.

Via REST at /order/cancelAllAfter or via WebSocket via the example below, one can set a millisecond timeout. This will start a timer. If cancelAllAfter is not called again before time runs out, all of your existing orders on all symbols will be canceled.

To cancel this operation and keep your orders open, pass a timeout of 0.

Advanced users of BitMEX should use this operation. A common use pattern is to set a timeout of 60000, and call it every 15 seconds. This gives you sufficient wiggle room to keep your orders open in case of a network hiccup, while still offering significant protection in case of a larger outage. Of course, the parameters are up to you.

We recommend not setting a timeout of less than 5 seconds to avoid being rate limited or having your orders unexpectedly canceled in case of network congestion.

For example:

// Places a dead man's switch at 60 seconds.
> {"op": "cancelAllAfter", "args": 60000}
  < {"now":"2015-09-02T14:18:43.536Z","cancelTime":"2015-09-02T14:19:43.536Z",
// Cancels the switch.
> {"op": "cancelAllAfter", "args": 0}
  < {"now":"2015-09-02T14:19:11.617Z","cancelTime":0,"request":{"op":"cancelAllAfter","args":0}}

Rate Limits

The following actions are ratelimited:

  • Subscription: Consumes one token from your request limiter.
  • Connection: 60 per hour, on a separate limiter.
  • Dead Man’s Switch (cancelAllAfter): Consumes one token from your request limiter.

If you exceed your ratelimit on a subscription or cancelAllAfter call, you will see a message like:

{"status":429,"error":"Rate limit exceeded, retry in 1 seconds.","meta":{"retryAfter":1},"request":{"op":"subscribe","args":"orderBookL2_25"}}

If you are ratelimited from connecting, the message is slightly different (example includes headers):

HTTP/1.1 429 Too Many Requests
Cache-Control: no-store, no-cache, must-revalidate, max-age=0
Pragma: no-cache
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1506983924
Retry-After: 29
Content-Type: application/json
Content-Length: 55
Date: Mon, 02 Oct 2017 21:43:49 GMT
Connection: keep-alive

{"error":"Rate limit exceeded, retry in 29 seconds."}

Response Format

Websocket responses may be of the following three types:

Success: (Emitted upon a successful subscription to a topic)

{"subscribe": subscriptionName, "success": true}

Error: (Emitted upon a malformed request or an attempt to request a locked resource)

{"error": errorMessage}

Data: (Emitted when data is available or requested)

This definition follows the typing conventions used in Flowtype and TypeScript. Fields suffixed with ? are not always present. See the comments for more details.

  // Table name / Subscription topic.
  // Could be "trade", "order", "instrument", etc.
  "table": string,

  // The type of the message. Types:
  // 'partial'; This is a table image, replace your data entirely.
  // 'update': Update a single row.
  // 'insert': Insert a new row.
  // 'delete': Delete a row.
  "action": 'partial' | 'update' | 'insert' | 'delete',

  // An array of table rows is emitted here. They are identical in structure to data returned from the REST API.
  "data": Object[],

  // The below fields define the table and are only sent on a `partial`

  // Attribute names that are guaranteed to be unique per object.
  // If more than one is provided, the key is composite.
  // Use these key names to uniquely identify rows. Key columns are guaranteed
  // to be present on all data received.
  "keys"?: string[],

  // This lists the shape of the table. The possible types:
  // "symbol" - In most languages this is equal to "string"
  // "guid"
  // "timestamp"
  // "timespan"
  // "float"
  // "long"
  // "integer"
  // "boolean"
  "types"?: {[key: string]: string},

  // When multiple subscriptions are active to the same table, use the `filter` to correlate which datagram
  // belongs to which subscription, as the `table` property will not contain the subscription's symbol.
  "filter"?: {account?: number, symbol?: string},

Reference Implementation

We have a reference implementation of the websocket as part of our reference Market Maker.

Of interest is the __on_message function, which handles updating tables in memory.

Data Example

Outgoing messages are prefixed with >. Incoming messages are prefixed with <.

Using the python tool wsdump:

~/g/f/w/bin (master|✔) $ python \
Press Ctrl+C to quit

  < {"info":"Welcome to the BitMEX Realtime API.","version":"1.1.0",

> "help"

  < {"info":"See and for more documentation.",...}

> {"op": "subscribe", "args": ["trade:XBTUSD","instrument:XBTUSD"]}

  < {"success":true,"subscribe":"trade:XBTUSD",
  < {"success":true,"subscribe":"instrument:XBTUSD",

  < {"table":"trade","action": "partial", ...}
  < {"table":"instrument","action": "partial", ...}

  < {"table":"instrument","action":"update","data":[{"symbol":"XBTUSD","fairPrice":380.52,
  < {"table":"instrument","action":"update","data":[{"symbol":"XBTUSD","openValue":673520400,

Data Samples

These include a few messages you might not see often in your testing; they are replicated here so you know how to handle them.


This assumes a 1-contract XBTUSD position with a liquidation price of 1140.1. At the time of this snap, the mark price jumped down to 1136.88.

# First, the position will update to a 'posState' of 'Liquidation'.
# Notice that the mark price is below the liquidation price. On a long, that means liquidation.
< {"table":"position",
    "currentTimestamp":"2017-04-04T22:07:42.442Z", "currentQty":1,"markPrice":1136.88,"markValue":-87960,
    "simpleQty":0.001,"liquidationPrice":1140.1, "timestamp":"2017-04-04T22:07:45.442Z"

# Then, the liquidation execution is inserted. Notice that 'text' is 'Liquidation'.
< {"table":"execution",
    "lastLiquidityInd":"RemovedLiquidity", "simpleOrderQty":null,"orderQty":1,"price":1134.37,"displayQty":null,

# Then, the position enters 'Liquidated' state. Notice the 'currentQty' is still 1.
< {"table":"position",

# Quickly thereafter, the position resets.
< {"table":"position",


The following shows the deleverage of a 2000-contract XBTUSD position.

# First, the position updates to a 'posState' of 'Deleverage'.
< {"table":"position",

# Then, a 'Deleverage' execution is inserted. Notice the 'text'.
< {"table":"execution",

# Quickly thereafter, the position resets.
< {"table":"position",


A special note on the orderBookL2 table, which is the canonical table for orderbook updates and the only way to retrieve all levels:

This orderbook is keyed by a unique ID, not price, so that all levels are unique across all symbols. This may be unintuitive at first but ensures that each level across the entire system is uniquely keyed. Therefore, when you retrieve an orderBookL2 update, it may look like this:


Notice that this does not include the price, which you should already have set on the level. The process for handling updates, inserts, deletes, and partials on this stream is exactly the same as any other stream and requires no special handling. However, some tooling may make assumptions about book entries, like keying them by price.

In that case, there are a few ways to handle this:

  1. Keep a local hashmap of ids you’ve seen to their price. When you receive an update or delete, look up the price in this map. This is simple but will consume some memory.
  2. Use the following formula to reverse-engineer the ID:
ID = (100000000 * symbolIdx) - (price / instrumentTickSize)
price = ((100000000 * symbolIdx) - ID) * instrumentTickSize


  • symbolIdx is the index of the instrument in the list of instruments
  • instrumentTickSize as the instrument’s tickSize property.
    • Due to in-flight changes of tickSize on some XBT contracts, an override may need to be applied. See below.

This can be written as:

// This is a compatibility change as the tick sizes of live instruments changed in-flight. If you are listing
// these instruments, you must use their original tick as part of your calculations. If not, this can be ignored,
// and you can use `instrument.tickSize` directly.
const LEGACY_TICKS = {XBTUSD: 0.01};
function instrumentTickSize(instrument) {
  return legacyTicks[instrument.symbol] || instrument.tickSize;

// You should have a copy of the full instruments list on startup.
// Fetch from:,tickSize&start=0&count=500
const instrumentsList = fetchInstrumentsFromBitMEX();
function getInstrumentAndIdx(symbol) {
  const instrument = instrumentsList.find((i) => i.symbol === symbol);
  const instrumentIdx = instrumentsList.indexOf(instrument);
  return [instrument, instrumentIdx];

// To get a price from an ID:
export function priceFromID(id, symbol) {
  const [instrument, instrumentIdx] = getInstrumentAndIdx(symbol);
  return (100000000 * instrumentIdx - id) * instrumentTickSize(instrument);

// And reversed:
export function IDFromPrice(price, symbol) {
  const [instrument, instrumentIdx] = getInstrumentAndIdx(symbol);
  return 100000000 * instrumentIdx - price / instrumentTickSize(instrument);

Applied to our update above, where the ID was 8798952400, you should get a resulting price of 10476:

price = ((1e8 * symbolIdx) - ID) * instrumentTickSize
10476 = ((100000000 * 88) - 8798952400) * 0.01


This is intended for advanced users only.

The BitMEX Websocket supports a very simple multiplexing scheme. Use this in place of many individual connections.

The most common use case is to keep a stream open for market data, and multiple streams for individual subaccounts.

Multiplexing has a different endpoint. Use /realtimemd (that’s “realtime-mux-demux”) for multiplexing capabilities.

The protocol is very simple:

Packet Format:



  • type: See “Packet Types” below.
  • id: Client-selected unique ID for this stream. This can be arbitrary; consider using a unique identifier like userID.
  • topic: Client-selected non-unique purpose for this stream. This is required but can be any string you wish.
    • Note: All returned messages will include the id and topic. Unsubscribing is done via id.
  • payload: For MESSAGE types, the payload is exactly equal to any message one would send via a non-multiplexed stream.

Packet Types:

  • MESSAGE: 0
    • When a stream is opened, use this type to send a message on a given topic.
    • Use to open a stream. Both id and topic may contain any data but must be unique.
    • Use to close a stream. id must match the one used for the subscription.

Outgoing messages are prefixed with >. Incoming messages are prefixed with <.

# Create stream with an id of `hudsyg1q5dda4`, topic of `user_1`
> [1, "hudsyg1q5dda4", "user_1"]
# A welcome message greets you.
< [0, "hudsyg1q5dda4", "user_1",{"info":"Welcome to the BitMEX Realtime API.",...}]

# The stream is created! The stream acts exactly like any other WS connection, just framed with type and id.

# Authenticate inside that stream - see `authentication` above
> [0, "hudsyg1q5dda4", "user_1", {"op": "authKeyExpires", "args": ["pV1CPhfZWUlZM93v..."]}]
< [0, "hudsyg1q5dda4", "user_1", {"success":true}]

# Subscribe to a private table.
> [0, "hudsyg1q5dda4", "user_1", {"subscribe": "position"}]
# One message confirms the subscription,
< [0, "hudsyg1q5dda4", "user_1", {"success":true,"subscribe":"position","request":{"subscribe":"position"}}]
# And another sends the first partial.
< [0, "hudsyg1q5dda4", "user_1", {"table":"position","action":"partial","keys":["account","symbol", ...]}]

# Data will flow from here on out.

# To close a stream:
> [2, "hudsyg1q5dda4", "user_1"]
# A confirmation echo is sent from the server.
< [2, "hudsyg1q5dda4", "user_1"]