API Bitmex

Bitmex

 

Is a cryptocurrency exchange and derivative trading platform.

 

The following APIs are supported:

 

  1. WebSocket streams: allows 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. Only are only private and related to user data, those methods requires 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.

 

Cal method Authenticate before subscribe to any Authenticated Topic.

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