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

AllXBTUSDT27201.5-1.79%XBTUSD27217.5-1.79%XBTEUR25461.0-1.32%XBTUSDTM2327205.5-2.52%XBTM2327300.5-1.86%XBTUSDTU2327361.5+16.30%XBTU2327391.5-1.87%XBTZ2327661.0-2.19%ETHUSDT1874.40-1.36%ETHUSD1876.40-1.45%ETHUSD_ETH1860.10-2.20%ETHUSDM231900.80-1.95%ETHUSDTM231877.95+4.73%ETHM230.06900+0.60%BMEXUSDT0.403-4.95%BMEXUSD0.403-4.73%ADAUSD0.3747-1.21%ADAUSDT0.3743-1.14%ADAM230.00001375+0.00%1TAIDOGEUSD268.0-4.29%1TAIDOGEUSDT356.8+0.00%APEUSDT3.142-1.16%APTUSD8.422-0.18%ARBUSDT1.149-7.64%ARBUSD1.164-5.83%ARBUSDTM231.127+0.00%AVAXUSDT14.074-2.80%AVAXUSD14.138-2.66%AXSUSD6.88-3.10%BCHUSD113.25-0.57%BCHUSDT113.15-1.31%BLURUSDT0.3766-27.76%BLURUSD0.4771-4.58%BNBUSD306.91-1.56%BNBUSDT305.16-2.08%BOBUSD0.0000216-16.28%CROUSD0.05963-1.13%DOGEUSDT0.07159-1.04%DOGEUSD0.07173-0.94%DOTUSD5.301-2.73%DOTUSDT5.316-2.15%EOSUSD0.8945-1.97%FLOKIUSDT0.00003070-7.14%FLOKIUSD0.00003136-4.48%FLRUSD0.0235-4.47%GMTUSDT0.2519-4.22%GMTUSD0.2595-1.29%GMXUSD54.05-4.12%GMXUSDT55.55-0.09%KLAYUSD0.18570-3.16%LINKUSD6.478-2.07%LTCUSDT90.45-1.85%LTCUSD90.55-1.85%LUNAUSDT0.8309-4.68%LUNAUSD0.8314-3.28%MATICUSDT0.8935-0.74%NEARUSD1.564-3.28%ORDIUSD8.492-10.13%PEPEUSDT0.000001260-2.10%PEPEUSD0.000001266-2.17%RNDRUSD2.500-3.85%SOLUSDT20.79-2.21%SOLUSD20.80-2.26%SUIUSDT0.977-2.50%SUIUSD0.971-3.48%TURBOUSD0.000233-20.21%USDTUSDC1.0029+1.19%XRPUSDT0.5145-1.47%XRPUSD0.5149-1.09%XRPM230.00001858-1.75%Funding: 03:51:17 @ 0.0078%Time: 12:08:42 AM UTC
BitMEX header logo
API Keys Usage

Below we outline the technical and usage details of an API Key.

If you are logged in, please follow this link to manage your active keys.

API Key Permissions

By default, API Keys can only read basic data, such as positions, margin, orders, and executions. They cannot submit orders or withdraw.

Permissions may be added to a key to make it more useful. It is good security practice to only add the permissions that you need, and no more. The available permissions are as follows:

  • Default (no permissions): Most GET routes are viewable as is authenticating with the websocket, but no changes can be made to the account, including orders, positions, and so on.
  • order: All /order and /position functions are available.
  • orderCancel: Only /order/cancel, /order/cancelAll and /order/cancelAllAfter (and the associated WebSocket operation) are usable.
    • Note: orderCancel is mutually exclusive with order. You may only enable one of the two. orderCancel is intended for risk/audit processes, not for trading.
  • withdraw: Enables /user/requestWithdrawal. Unless the withdrawal is made to a saved address with the Skip Confirm featured turned on, an email withdrawal will still be required.

API Keys cannot be used to create other API Keys, or to modify the user in any way, including preferences, authentication, two-factor, or KYC data.

Authenticating with an API Key

Authentication is done by sending the following HTTP headers:

api-expires: A UNIX timestamp after which the request is no longer valid. This is to prevent replay attacks.

UNIX timestamps are in seconds. For example, 2018-02-08T04:30:37Z is 1518064237.

This timestamp is compared against our system time before reaching the trading engine. It cannot be used as a mechanism to cancel submission of an order that is waiting in queue to be processed.

api-key: Your public API key. This the id param returned when you create an API Key via the API.

api-signature: A signature of the request you are making. It is calculated as hex(HMAC_SHA256(apiSecret, verb + path + expires + data)). See the example calculations below.

Our reference market maker bot features a working implementation of our API key authentication.

Note: Previous versions of this document described an api-nonce value, which is a value that should increase between the bounds of 0 and 253. This scheme is no longer supported. It has significant problems with multithreaded clients and should not be used. Do not use it for new applications.

The ‘data’ param

The data part of the HMAC construction should be exactly equal to the raw body you send to the server. You can send JSON or form encoding, just ensure you use the exact same body string in the HMAC. Generally you will want to prepare the request in your language of choice, then use the same raw body string for the HMAC construction as in the request body.

Full sample calculation

Use these calculations as test cases in your code.

apiKey = 'LAqUlngMIQkIUjXMUreyu3qn'
apiSecret = 'chNOOS4KvNXR_Xq4k4c9qsfoKWvnDecLATCRlcBwyKDYnWgO'

# Simple GET
verb = 'GET'
path = '/api/v1/instrument'
expires = 1518064236 # 2018-02-08T04:30:36Z
data = ''

# HEX(HMAC_SHA256(apiSecret, 'GET/api/v1/instrument1518064236'))
# Result is:
# 'c7682d435d0cfe87c16098df34ef2eb5a549d4c5a3c2b1f0f77b8af73423bf00'
signature = HEX(HMAC_SHA256(apiSecret, verb + path + str(expires) + data))

# GET with complex querystring (value is URL-encoded)
verb = 'GET'
# Note url-encoding on querystring - this is '/api/v1/instrument?filter={"symbol": "XBTM15"}'
# Be sure to HMAC *exactly* what is sent on the wire
path = '/api/v1/instrument?filter=%7B%22symbol%22%3A+%22XBTM15%22%7D'
expires = 1518064237 # 2018-02-08T04:30:37Z
data = ''

# HEX(HMAC_SHA256(apiSecret, 'GET/api/v1/instrument?filter=%7B%22symbol%22%3A+%22XBTM15%22%7D1518064237'))
# Result is:
# 'e2f422547eecb5b3cb29ade2127e21b858b235b386bfa45e1c1756eb3383919f'
signature = HEX(HMAC_SHA256(apiSecret, verb + path + str(expires) + data))

verb = 'POST'
path = '/api/v1/order'
expires = 1518064238 # 2018-02-08T04:30:38Z
data = '{"symbol":"XBTM15","price":219.0,"clOrdID":"mm_bitmex_1a/oemUeQ4CAJZgP3fjHsA","orderQty":98}'

# HEX(HMAC_SHA256(apiSecret, 'POST/api/v1/order1518064238{"symbol":"XBTM15","price":219.0,"clOrdID":"mm_bitmex_1a/oemUeQ4CAJZgP3fjHsA","orderQty":98}'))
# Result is:
# '1749cd2ccae4aa49048ae09f0b95110cee706e0944e6a14ad0b3a8cb45bd336b'
signature = HEX(HMAC_SHA256(apiSecret, verb + path + str(expires) + data))


If you are receiving "Signature Not Valid" messages, check the following:

  • Check that your signatures match the sample signatures above.
  • If there is a request body, make sure your Content-Length and Content-Type are valid.
  • Ensure your request body is being properly sent. Try a few sample requests against httpbin.
  • Ensure you are signing the exact string that is being sent to the server. Certain JSON serializers have unstable key ordering, so serialize to a string first, sign that string, and then send the same string in the request body.

Sample Code

We have created several example connectors that implement the above authentication:

A Python snippet:

import time
import hashlib
import hmac
import urllib.parse

# Generates an API signature.
# A signature is HMAC_SHA256(secret, verb + path + expires + data), hex encoded.
# Verb must be uppercased, url is relative, expires must be unix timestamp (in seconds)
# and the data, if present, must be JSON without whitespace between keys.
def generate_signature(secret, verb, url, expires, data):
    """Generate a request signature compatible with BitMEX."""
    # Parse the url so we can remove the base and extract just the path.
    parsedURL = urllib.parse.urlparse(url)
    path = parsedURL.path
    if parsedURL.query:
        path = path + '?' + parsedURL.query

    if isinstance(data, (bytes, bytearray)):
        data = data.decode('utf8')

    message = bytes(verb + path + str(expires) + data, 'utf-8')
    print("Computing HMAC: %s" % message)

    signature =, 'utf-8'), message, digestmod=hashlib.sha256).hexdigest()
    return signature

# Testing
expires = 1518064236
# Or you might generate it like so:
# expires = int(round(time.time()) + 5)

# Prints 'c7682d435d0cfe87c16098df34ef2eb5a549d4c5a3c2b1f0f77b8af73423bf00'
print(generate_signature('chNOOS4KvNXR_Xq4k4c9qsfoKWvnDecLATCRlcBwyKDYnWgO', 'GET', '/api/v1/instrument', expires, '')) #