Please note BitMEX does not support old browsers.
We recommend upgrading to the latest version of Opera, Firefox, or Chrome.
AllBTCUSDT82468.1-3.48%BTC/USDT83000.0-0.41%BTCUSD81708.6-1.56%BTCEUR74754.0-1.93%BTCETH43.398-0.42%BTCUSD_​BBX59922.0+0.73%BTCUSDTH2581957.5-1.95%BTCUSDTM2586117.5-2.28%BTCH2582117.5-2.39%BTCZ2594473.0-1.24%BTCU2589074.5-3.33%BTCM2586059.0-0.63%BTCJ2583492.5-1.77%ETHUSDT1885.00-1.50%ETHBTC0.02295-0.52%ETHUSD1886.57-1.56%ETH/BTC0.0800000+0.00%ETH/USDT4606.00+2.36%ETHUSDM251988.05-1.39%ETHUSDH251889.55-1.66%ETHH250.02313+0.39%ETHM250.02441+0.99%BMEXUSDT25.055+0.00%BMEX/USDT0.3129+3.95%AAVEUSDT166.38-2.62%AAVEUSD165.65-3.38%ACTUSDT0.32614+0.00%ADAUSDT0.7352+0.16%ADAUSD0.6853-4.57%ADAH250.00000849-2.08%ADAM250.00000890-1.66%AEVOUSDT0.3993+20.09%AI16ZUSDT0.2041-30.65%AIBTCUSDT0.6348-0.02%APEUSDT0.5174-0.29%APE/USDT0.516-0.58%APTUSDT6.097-0.16%APTUSD5.340-0.80%APUUSDT0.0002042+3.60%ATOM/USDT--.-+0.00%AVAXUSDT18.603+0.68%AVAXUSD18.426-0.04%AXS/USDT3.745+0.03%AXSUSD3.25-4.13%BANANAUSDT16.7287-3.16%MEMEMEXTUSDT64.39-4.88%BBX/USDT--.-+0.00%BCHUSDT333.00-2.25%BCHUSD331.80-2.27%BERAUSDT--.-+0.00%BIGTIMEUSDT0.04957+13.15%BIOUSDT0.7183+0.00%BLURUSDT0.1025-1.91%BLURUSD0.1027-2.75%BNBUSDT629.32-0.67%BNBUSD626.15-0.94%BOMEUSDT0.006857+9.36%100BONKUSDT0.0010361-4.95%BONK/USDT--.-+0.00%BRETTUSDT0.20735+0.00%BROCCOLIUSDT--.-+0.00%CATUSDT0.000007822-6.38%CHILLGUYUSDT--.-+0.00%CYBERUSDT1.3728+5.87%DOGEUSDT0.16459-4.68%DOGEUSD0.16470-4.31%DOGSUSDT0.000138-2.82%DOTUSDT4.262-2.18%DOTUSD4.291-1.99%DUCKUSDT0.003049-5.95%DYDXUSD0.6163-3.66%DYMUSDT0.3399+6.15%ENAUSDT0.9876+249.96%EOSUSD0.4914-0.43%FARTCOINUSDT0.2770-12.06%FILUSDT3.1122+4.12%FILUSD2.8390-4.07%FLOKIUSDT0.00005957-2.84%FTR/USDT0.015000+0.00%P_​FTXZ2630.66-0.29%GEMS/USDT--.-+0.00%GMEUSDT0.001558-0.64%GMTUSD0.0487-1.81%GOATUSDT--.-+0.00%GOAT/USDT--.-+0.00%GPSUSDT--.-+0.00%HIVEUSDT0.2559-6.84%HSKUSDTZ251.2000+0.00%HYPEUSDT13.133-11.74%INJUSDT9.2934-6.67%IPUSDT--.-+0.00%JUSDT0.2291-26.12%JAILSTOOLUSDT--.-+0.00%JUPUSDT0.5459-17.11%KAITOUSDT--.-+0.00%KLAYUSDT0.12294-0.16%LDOUSD0.9101-5.74%LDOUSDT0.9847-18.67%LINKUSDT13.661-0.86%LINK/USDT14.918+0.00%LINKUSD13.574-1.06%LTCUSDT88.43-5.02%LTCUSD88.35-5.19%LUNAUSDT0.1996-6.07%MANTAUSDT0.2728+6.19%MEUSDT9.0000+0.00%MELANIAUSDT--.-+0.00%MEMEUSDT0.002348-4.48%MERLUSD0.1301-1.96%MEWUSDT0.001842-4.71%1000000MOGUSDT2.4000+0.00%MOVEUSDT1.0700+0.00%MUBARAKUSDT--.-+0.00%MYROUSDT0.02012+11.84%NEARUSDT2.551-1.28%NEARUSD2.554-0.27%NOTUSDT0.002412+2.29%ONDOUSDT0.81520-4.32%OPUSD0.8507-3.16%OPUSDT0.9097-14.61%ORDIUSD8.944-5.84%PENGUUSDT0.00697+2.50%PEPEUSDT0.000006766-4.25%PEPEUSD0.000006777-4.41%PIUSDT--.-+0.00%PIXELUSDT0.1788+33.73%PNUTUSDT0.50860-49.14%POLUSDT0.2051-4.47%POL/USDT0.3707-0.99%POPCATUSDT0.8000+40.33%P_​POWELLK2643.53-0.55%PYTHUSDT0.1463-18.40%RAYUSDT1.747-25.37%REDUSDT--.-+0.00%REDUSDTZ250.9884-0.48%SUSDT0.4807-5.22%S/USDT0.4391+6.86%SAGAUSDT0.3932-9.07%SEIUSDT0.1919-3.62%SHELLUSDT--.-+0.00%SHIBUSDT0.000012367-4.27%SHIBUSD0.000012375-4.26%SOLUSDT123.65-3.35%SOLUSD122.75-3.43%SOL/USDT129.00-5.44%SOLVUSDT0.04304+2.23%STLS/USDT0.10607+0.07%STRKUSDT0.1785-1.71%SUIUSDT2.2542-1.40%SUIUSD2.266-3.94%TIAUSDT3.3244-6.64%TNSRUSDT0.4456-6.13%TONUSD3.6073+4.44%TONUSDT5.4167-8.90%TRUMP/USDT0.715-98.57%TRUMPOFFICIALUSDT12.646-6.34%TRXUSDT0.22359+1.96%TRXUSD0.22398+2.42%TRX/USDT0.09020+0.00%TSTUSDT--.-+0.00%TUTUSDT--.-+0.00%UNI/USDT7.545+0.00%USDTUSDC1.0003-0.16%USUALUSDT1.0700+0.00%VELOUSDT0.242500+0.00%VINEUSDT0.1645+0.00%VVVUSDT--.-+0.00%WUSDT0.3146+45.51%WEN/USDT--.-+0.00%WIFUSDT0.5129-14.72%WLDUSDT0.901+6.88%WLDUSD0.821-4.98%WLFIUSDTZ260.091+15.19%WOOUSDT0.2149+35.41%XAIUSDT0.25260+31.84%XAUTUSD3039.3+1.16%XRDUSDT0.00693-1.56%XRPUSDT2.3512-1.98%XRP/USDT2.2505-3.75%XRPUSD2.2322-4.33%XRPH250.00002759-2.16%XRPM250.00002893-2.03%ZKUSDT0.1939+69.34%ZROUSDT2.5715+8.92%Funding: 03:04:27 @ -0.2284%Time: 4:55:32 pm UTC

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))

#
# POST
#
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))

Troubleshooting

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 = hmac.new(bytes(secret, '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, '')) #

BitMEX is a P2P crypto-products trading platform.

BitMEX and the mobile apps issued under BMEX are wholly owned and operated by HDR Global Trading Limited, a Republic of Seychelles incorporated entity or its relevant authorised affiliates.

Trading in cryptocurrency derivatives involves significant risks. Please consider whether using BitMEX is appropriate for you.

Please read our Terms of Service, Risk Disclosure Statement and Privacy Notice.

US Persons are prohibited from accessing the services of the BitMEX trading platform.

Cryptocurrency charts by TradingView.