API Bitmex

Bitmex

 

Is a cryptocurrency exchange and derivative trading platform.

 

The following APIs are supported:

 

  1. WebSocket streams: allows you to subscribe to some methods and get data in real-time. Events are pushed to clients by server to subscribers. Uses WebSocket as protocol.
  2. REST API: clients can request to server market and account data. Requires an API Key and Secret to authenticate and uses HTTPs as protocol.

 

Properties

Bitmex API has 2 types of methods: public and private. Public methods can be accessed without authentication, example: get ticker prices. Some are private and related to user data; those methods require the use of Bitmex API keys.

 

 

 

Most common uses

 

WebSocket API

 

  Subscribe / Unsubscribe

    

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. In some topics, you can pass a Symbol to filter events by symbol, example: trades, quotes...

 

The following subscription topics are available without authentication:

 

 

The following subjects require authentication:

 

 

 

Example of messages received:

 


{
      "table":"orderBookL2_25",
      "keys":["symbol","id","side"],
      "types":{"id":"long","price":"float","side":"symbol","size":"long","symbol":"symbol"}
      "foreignKeys":{"side":"side","symbol":"instrument"},
      "attributes":{"id":"sorted","symbol":"grouped"},
      "action":"partial",
      "data":[
        {"symbol":"XBTUSD","id":17999992000,"side":"Sell","size":100,"price":80},
        {"symbol":"XBTUSD","id":17999993000,"side":"Sell","size":20,"price":70},
        {"symbol":"XBTUSD","id":17999994000,"side":"Sell","size":10,"price":60},
        {"symbol":"XBTUSD","id":17999995000,"side":"Buy","size":10,"price":50},
        {"symbol":"XBTUSD","id":17999996000,"side":"Buy","size":20,"price":40},
        {"symbol":"XBTUSD","id":17999997000,"side":"Buy","size":100,"price":30}
      ]
}
 
{
      "table":"orderBookL2_25",
      "action":"update",
      "data":[
        {"symbol":"XBTUSD","id":17999995000,"side":"Buy","size":5}
      ]
    }
{
      "table":"orderBookL2_25",
      "action":"delete",
      "data":[
        {"symbol":"XBTUSD","id":17999995000,"side":"Buy"}
      ]
}
{
      "table":"orderBookL2_25",
      "action":"insert",
      "data":[
        {"symbol":"XBTUSD","id":17999995500,"side":"Buy","size":10,"price":45},
      ]
}

Authentication

    

If you wish to subscribe to user-locked streams, you must authenticate first. Note that invalid authentication will close the connection.

 

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 in your account.

 

Call method Authenticate before subscribing to any Authenticated Topic.

CancelAllAfter (Dead Man's Switch)

The CancelAllAfter method implements the Dead Man's Switch feature. When called with a timeout value (in milliseconds), it instructs the server to cancel all open orders if no subsequent CancelAllAfter call is received within the timeout period. This is useful to ensure orders are canceled in case of network disconnection.

REST API

 

Method Description
GetExecutions This returns all raw transactions, which includes order opening and cancelation, and order status changes.
GetExecutionsTradeHistory This returns more focused Transactions.
GetInstruments This returns all instruments and indices, including those that have settled or are unlisted. Use this endpoint if you want to query for individual instruments or use a complex filter.
GetOrders To get open orders only
PlaceOrder Place a raw order using TsgcHTTPBitmexOrder object.
PlaceMarketOrder Place a new MARKET order.
PlaceLimitOrder Place a new LIMIT order.
PlaceStopOrder Place a new STOP order.
PlaceStopLimitOrder Place a new STOPLIMIT order.
AmendOrder Modify an existing order.
CancelOrder Cancels an active Order.
CancelAllOrders Cancel All Active Orders.
CancelAllOrdersAfter Cancel All Orders after some time.
ClosePosition Close an open position.
GetOrderBook Get Current OrderBook in vertical format
GetPosition Get your positions.
SetPositionIsolate Enable isolated margin or cross-margin per position.
SetPositionLeverage Choose leverage per position.
SetPositionRiskLimit Update your risk limit.
SetPositionTransferMargin Transfer equity in or out of a position.
GetQuotes Get Quotes
GetTrades Get Trades
GetFunding Get funding data.
GetInsurance Get insurance fund data.
GetTradeBucketed Get bucketed trade data (OHLCV) with configurable bin sizes.
GetQuoteBucketed Get bucketed quote data with configurable bin sizes.
GetSettlement Get settlement data.
GetLiquidation Get liquidation orders.
GetInstrumentIndices Get instrument indices.
GetInstrumentCompositeIndex Get composite index data for instruments.
GetStats Get exchange-wide statistics.
GetStatsHistory Get historical exchange statistics.
GetStatsHistoryUSD Get historical USD exchange statistics.
GetUserMargin Get your account margin data.
GetUserWallet Get your wallet information.
GetUserWalletHistory Get your wallet transaction history.
GetUserWalletSummary Get a summary of your wallet.