Skip to content

Latest commit

 

History

History

javascript

bit_mex_api

BitMexApi - JavaScript client for bit_mex_api

REST API for the BitMEX Trading Platform If you are building automated tools, please subscribe to the BitMEX API RSS Feed for changes. The feed will be updated regularly and is the most reliable way to get downtime and update announcements. View Changelog - #### Getting Started Base URI: https://www.bitmex.com/api/v1 ##### Fetching Data All REST endpoints are documented below. You can try out any query right from this interface. Most table queries accept count, start, and reverse params. Set reverse=true to get rows newest-first. Additional documentation regarding filters, timestamps, and authentication is available in the main API documentation. All table data is available via the Websocket. We highly recommend using the socket if you want to have the quickest possible data without being subject to ratelimits. ##### Return Types By default, all data is returned as JSON. Send ?_format=csv to get CSV data or ?_format=xml to get XML data. ##### Trade Data Queries This is only a small subset of what is available, to get you started. Fill in the parameters and click the Try it out! button to try any of these queries. - Pricing Data - Trade Data - OrderBook Data - Settlement Data - Exchange Statistics Every function of the BitMEX.com platform is exposed here and documented. Many more functions are available. ##### Swagger Specification ⇩ Download Swagger JSON - ## All API Endpoints Click to expand a section.

This SDK is automatically generated by the Swagger Codegen project:

  • API version: 1.2.0
  • Package version: 1.2.0
  • Build package: io.swagger.codegen.languages.JavascriptClientCodegen

Installation

npm

To publish the library as a npm, please follow the procedure in "Publishing npm packages".

Then install it via:

npm install bit_mex_api --save
Local development

To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json (and this README). Let's call this JAVASCRIPT_CLIENT_DIR. Then run:

npm install

Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR:

npm link

Finally, switch to the directory you want to use your bit_mex_api from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('bit_mex_api') in javascript files from the directory you ran the last command above from.

git

If the library is hosted at a git repository, e.g. https://github.com/GIT_USER_ID/GIT_REPO_ID then install it via:

    npm install GIT_USER_ID/GIT_REPO_ID --save

For browser

The library also works in the browser environment via npm and browserify. After following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following (assuming main.js is your entry file, that's to say your javascript file where you actually use this library):

browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Getting Started

Please follow the installation instruction and execute the following JS code:

var BitMexApi = require('bit_mex_api');

var defaultClient = BitMexApi.ApiClient.instance;

// Configure API key authorization: apiExpires
var apiExpires = defaultClient.authentications['apiExpires'];
apiExpires.apiKey = "YOUR API KEY"
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//apiExpires.apiKeyPrefix['api-expires'] = "Token"

// Configure API key authorization: apiKey
var apiKey = defaultClient.authentications['apiKey'];
apiKey.apiKey = "YOUR API KEY"
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//apiKey.apiKeyPrefix['api-key'] = "Token"

// Configure API key authorization: apiSignature
var apiSignature = defaultClient.authentications['apiSignature'];
apiSignature.apiKey = "YOUR API KEY"
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//apiSignature.apiKeyPrefix['api-signature'] = "Token"

var api = new BitMexApi.APIKeyApi()

var opts = { 
  'reverse': false // {Boolean} If true, will sort results newest first.
};

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
api.aPIKeyGet(opts, callback);

Documentation for API Endpoints

All URIs are relative to https://www.bitmex.com/api/v1

Class Method HTTP request Description
BitMexApi.APIKeyApi aPIKeyGet GET /apiKey Get your API Keys.
BitMexApi.AddressApi addressGet GET /address Get your addresses.
BitMexApi.AddressApi addressNew POST /address Creates a new saved address.
BitMexApi.AnnouncementApi announcementGet GET /announcement Get site announcements.
BitMexApi.AnnouncementApi announcementGetUrgent GET /announcement/urgent Get urgent (banner) announcements.
BitMexApi.ChatApi chatGet GET /chat Get chat messages.
BitMexApi.ChatApi chatGetChannels GET /chat/channels Get available channels.
BitMexApi.ChatApi chatGetConnected GET /chat/connected Get connected users.
BitMexApi.ChatApi chatGetPinnedMessage GET /chat/pinned Get pinned message for a channel.
BitMexApi.ChatApi chatNew POST /chat Send a chat message.
BitMexApi.ExecutionApi executionGet GET /execution Get all raw executions for your account.
BitMexApi.ExecutionApi executionGetTradeHistory GET /execution/tradeHistory Get all balance-affecting executions.
BitMexApi.FundingApi fundingGet GET /funding Get funding history.
BitMexApi.GlobalNotificationApi globalNotificationGet GET /globalNotification Get your current GlobalNotifications.
BitMexApi.GuildApi guildArchive POST /guild/archive Archive a guild
BitMexApi.GuildApi guildEdit PUT /guild Edit guild new guild
BitMexApi.GuildApi guildGet GET /guild Get all guilds
BitMexApi.GuildApi guildJoin POST /guild/join Request to Join a private guild or join a public guild
BitMexApi.GuildApi guildKick POST /guild/kick Kick member from guild
BitMexApi.GuildApi guildLeave POST /guild/leave Leave guild or cancel guild join request
BitMexApi.GuildApi guildNew POST /guild Creates a new guild
BitMexApi.GuildApi guildShareTrades POST /guild/shareTrades Toggle share trades for your account, which controls whether your guild members can see your orders and positions in their UI
BitMexApi.InstrumentApi instrumentGet GET /instrument Get instruments.
BitMexApi.InstrumentApi instrumentGetActive GET /instrument/active Get all active instruments and instruments that have expired in <24hrs.
BitMexApi.InstrumentApi instrumentGetActiveAndIndices GET /instrument/activeAndIndices Helper method. Gets all active instruments and all indices. This is a join of the result of /indices and /active.
BitMexApi.InstrumentApi instrumentGetActiveIntervals GET /instrument/activeIntervals Return all active contract series and interval pairs.
BitMexApi.InstrumentApi instrumentGetCompositeIndex GET /instrument/compositeIndex Show constituent parts of an index.
BitMexApi.InstrumentApi instrumentGetIndices GET /instrument/indices Get all price indices.
BitMexApi.InstrumentApi instrumentGetUsdVolume GET /instrument/usdVolume Get a summary of exchange statistics in USD.
BitMexApi.InsuranceApi insuranceGet GET /insurance Get insurance fund history.
BitMexApi.LeaderboardApi leaderboardGet GET /leaderboard Get current leaderboard.
BitMexApi.LeaderboardApi leaderboardGetName GET /leaderboard/name Get your alias on the leaderboard.
BitMexApi.LiquidationApi liquidationGet GET /liquidation Get liquidation orders.
BitMexApi.OrderApi orderAmend PUT /order Amend the quantity or price of an open order.
BitMexApi.OrderApi orderCancel DELETE /order Cancel order(s). Send multiple order IDs to cancel in bulk.
BitMexApi.OrderApi orderCancelAll DELETE /order/all Cancels all of your orders.
BitMexApi.OrderApi orderCancelAllAfter POST /order/cancelAllAfter Automatically cancel all your orders after a specified timeout.
BitMexApi.OrderApi orderClosePosition POST /order/closePosition Close a position. [Deprecated, use POST /order with execInst: 'Close']
BitMexApi.OrderApi orderGetOrders GET /order Get your orders.
BitMexApi.OrderApi orderNew POST /order Create a new order.
BitMexApi.OrderBookApi orderBookGetL2 GET /orderBook/L2 Get current orderbook in vertical format.
BitMexApi.PorlApi porlGetNonce GET /porl/nonce Get your Proof of Reserves nonce and data.
BitMexApi.PorlApi porlGetSnapshots GET /porl/snapshots Get Proof of Reserves historical snapshots
BitMexApi.PositionApi positionGet GET /position Get your positions.
BitMexApi.PositionApi positionIsolateMargin POST /position/isolate Enable isolated margin or cross margin per-position.
BitMexApi.PositionApi positionTransferIsolatedMargin POST /position/transferMargin Transfer equity in or out of a position.
BitMexApi.PositionApi positionUpdateLeverage POST /position/leverage Choose leverage for a position.
BitMexApi.PositionApi positionUpdateRiskLimit POST /position/riskLimit Update your risk limit.
BitMexApi.QuoteApi quoteGet GET /quote Get Quotes.
BitMexApi.QuoteApi quoteGetBucketed GET /quote/bucketed Get previous quotes in time buckets.
BitMexApi.SchemaApi schemaGet GET /schema Get model schemata for data objects returned by this API.
BitMexApi.SchemaApi schemaWebsocketHelp GET /schema/websocketHelp Returns help text & subject list for websocket usage.
BitMexApi.SettlementApi settlementGet GET /settlement Get settlement history.
BitMexApi.StatsApi statsGet GET /stats Get exchange-wide and per-series turnover and volume statistics.
BitMexApi.StatsApi statsHistory GET /stats/history Get historical exchange-wide and per-series turnover and volume statistics.
BitMexApi.StatsApi statsHistoryUSD GET /stats/historyUSD Get a summary of exchange statistics in USD.
BitMexApi.TradeApi tradeGet GET /trade Get Trades.
BitMexApi.TradeApi tradeGetBucketed GET /trade/bucketed Get previous trades in time buckets.
BitMexApi.UserApi userCancelPendingWithdrawal DELETE /user/withdrawal Cancel pending withdrawal
BitMexApi.UserApi userCancelWithdrawal POST /user/cancelWithdrawal Cancel a withdrawal.
BitMexApi.UserApi userCheckReferralCode GET /user/checkReferralCode Check if a referral code is valid.
BitMexApi.UserApi userCommunicationToken POST /user/communicationToken Register your communication token for mobile clients
BitMexApi.UserApi userConfirm POST /user/confirmEmail Confirm your email address with a token.
BitMexApi.UserApi userConfirmWithdrawal POST /user/confirmWithdrawal Confirm a withdrawal.
BitMexApi.UserApi userCreateSubAccount POST /user/addSubaccount Creates a new sub-account.
BitMexApi.UserApi userCreateUnstakingRequests POST /user/unstakingRequests Create unstaking request
BitMexApi.UserApi userDeleteUnstakingRequests DELETE /user/unstakingRequests Cancel unstaking request
BitMexApi.UserApi userGet GET /user Get your user model.
BitMexApi.UserApi userGetAffiliateStatus GET /user/affiliateStatus Get your current affiliate/referral status.
BitMexApi.UserApi userGetCSA GET /user/csa Get your account's CSA status.
BitMexApi.UserApi userGetCommission GET /user/commission Get your account's commission status.
BitMexApi.UserApi userGetDepositAddress GET /user/depositAddress Get a deposit address.
BitMexApi.UserApi userGetDepositAddressInformation GET /user/depositAddressInformation Get a deposit address.
BitMexApi.UserApi userGetExecutionHistory GET /user/executionHistory Get the execution history by day.
BitMexApi.UserApi userGetMargin GET /user/margin Get your account's margin status. Send a currency of "all" to receive an array of all supported currencies.
BitMexApi.UserApi userGetQuoteFillRatio GET /user/quoteFillRatio Get 7 days worth of Quote Fill Ratio statistics.
BitMexApi.UserApi userGetQuoteValueRatio GET /user/quoteValueRatio Get Quote Value Ratio statistics over the last 3 days
BitMexApi.UserApi userGetStaking GET /user/staking Get the current user staking amount.
BitMexApi.UserApi userGetStakingInstruments GET /user/staking/instruments List staking instruments
BitMexApi.UserApi userGetStakingTiers GET /user/staking/tiers List staking tiers for a given currency
BitMexApi.UserApi userGetTradingVolume GET /user/tradingVolume Get your 30 days USD average trading volume
BitMexApi.UserApi userGetUnstakingRequests GET /user/unstakingRequests Get the current user unstaking requests
BitMexApi.UserApi userGetWallet GET /user/wallet Get your current wallet information.
BitMexApi.UserApi userGetWalletHistory GET /user/walletHistory Get a history of all of your wallet transactions (deposits, withdrawals, PNL).
BitMexApi.UserApi userGetWalletSummary GET /user/walletSummary Get a summary of all of your wallet transactions (deposits, withdrawals, PNL).
BitMexApi.UserApi userGetWalletTransferAccounts GET /user/getWalletTransferAccounts Get the list of accounts you can transfer funds between.
BitMexApi.UserApi userLogout POST /user/logout Log out of BitMEX.
BitMexApi.UserApi userRequestWithdrawal POST /user/requestWithdrawal Request a withdrawal to an external wallet.
BitMexApi.UserApi userSavePreferences POST /user/preferences Save user preferences.
BitMexApi.UserApi userUpdateSubAccount POST /user/updateSubaccount Updates the sub-account name.
BitMexApi.UserApi userWalletTransfer POST /user/walletTransfer Execute a transfer to a paired account.
BitMexApi.UserAffiliatesApi userAffiliatesGet GET /userAffiliates Get user's affiliates to a given depth
BitMexApi.UserEventApi userEventGet GET /userEvent Get your user events
BitMexApi.WalletApi walletGetAssetsConfig GET /wallet/assets Get Assets Config
BitMexApi.WalletApi walletGetNetworksConfig GET /wallet/networks Get Networks Config

Documentation for Models

Documentation for Authorization

apiExpires

  • Type: API key
  • API key parameter name: api-expires
  • Location: HTTP header

apiKey

  • Type: API key
  • API key parameter name: api-key
  • Location: HTTP header

apiSignature

  • Type: API key
  • API key parameter name: api-signature
  • Location: HTTP header