Crypto Tutorials: Binance | Bitfinex | Bitmex | BscScan | Cardano | Coinbase | Coingecko | Coinmarketcap | CoinAPI | Coinranking | Etherscan | | Glassnode | Huobi | LiveCoinWatch | Kraken | Kucoin | Magic Eden | Messari | Nomics | OpenSea | PancakeSwap | Rarible | Rarify | Solanart

    How to connect Bitmex to your Google Sheet

    Bitmex is a cryptocurrency exchange. We can use the Bitmex API to pull data from Bitmex into Google Sheets. In this tutorial, you will learn how to connect the Bitmex REST API to Google Sheets in 5 steps:

    1. Install the Apipheny Add-on
    2. Obtain a Bitmex API Key
    3. Choose a Bitmex API Endpoint
    4. Enter your Bitmex API request into Apipheny
    5. Run the Bitmex API request

    ⭐️ Related article: how to place a buy order on Bitmex from your Google Sheet

    Step 1.) Install and open the Apipheny add-on for Google Sheets

    Apipheny is a free API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to API data sources, easily.

    1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install

    2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.

    In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.

    open apipheny

    Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new

    Step 2.) Obtain a Bitmex API Key

    After logging into your Bitmex account, click the API tab and then click the API Key Management option from the menu on the left:

    Access the API settings in your Bitxmex account
    Access the API settings in your Bitxmex account

    The API Keys page will then be displayed. Complete the Name field, choose Key Permissions from the drop-down list, and then click the Create API Key button:

    Fill in the details and then click the "Create API Key" button
    Fill in the details and then click the “Create API Key” button

    The API key (ID and Secret) will be displayed on the screen:

    Bitmex API key
    Bitmex API key

    Copy and paste your ID and the Secret to safe place because you’ll need them in the next steps.

    Step 3.) Choose a Bitmex API endpoint

    In this section, we’ll show you how to browse the Bitmex API documentation to find the Bitmex API URL and API endpoint that retrieves the information you need from your Bitmex account.

    If you already know your API URL and endpoint, or you want to use the same example URL and endpoint as us, just skip to Step 4.

    First, open the Bitmex API documentation page: https://www.bitmex.com/api/explorer/

    On this page you’ll find a short description, the base URL, the return types, and all the API endpoints, organized into sections:

    Bitmex API documentation
    Bitmex API documentation
    Bitmex API documents
    Bitmex API documents

    All API calls to Bitmex should be made to this base URL:

    https://www.bitmex.com/api/v1

    All endpoints should be appended to this base URL.

    An example API section in the Bitmex API documentation is Announcement, which includes two endpoints: /announcement and /announcement/urgent:

    Bitmex API endpoint examples
    Bitmex API endpoint examples

    The /announcement endpoint uses the following API URL:

    https://www.bitmex.com/api/v1/announcement

    Each endpoint’s documentation contains a description of the endpoint’s purpose, the response class, the content type, the available API URL parameters, and the possible response messages:

    Bitmex API endpoint documentation example
    Bitmex API endpoint documentation example

    Step 4.) Enter your Bitmex API request into Apipheny

    Now go back to your Google Sheet and make sure that the Apipheny add-on is open on the “Import” tab. With the Import tab open, enter these details into the add-on:

    Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your API endpoint. For this example, we are using the GET method.

    API URL: In Step 3, we explained how you can find the Bitmex REST API endpoint that you need. Now copy and paste your complete Bitmex API URL into the Apipheny add-on, where it says API URL Path, followed by any parameters required for your query (if applicable).

    For this example, we are using the Get /user endpoint, which retrieves your user’s details. This is what the whole URL looks like:

    https://www.bitmex.com/api/v1/user

    If you’re following the same example as us, you can copy and paste this URL into the “API URL” field in the add-on.

    Headers: In the Headers section of Apipheny, add 4 rows with the following keys and values:

    Header 1
    Key:
    Api-signature
    Value:
    your_api_signature_value
    
    Header 2
    Key:
    Api-key
    Value:
    your_api_key_value
    
    Header 3
    Key:
    Accept
    Value:
    application/json
    
    Header 4
    Key:
    api-expires
    Value:
    your_api_expires_value

    The api-signature is a signature of the request you are making. It is calculated as hex(HMAC_SHA256(apiSecret, verb + path + expires + data)), where:

    • The apiSecret is the Secret value obtained previously on Step 2
    • The verb is the method we are using (GET)
    • Expires represents the date you want the request to expire converted in milliseconds
    • The path value represents the path to your endpoint, in this case /api/v1/user
    • 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. In this case, I didn’t send anything to the server, so I didn’t add a value for this parameter in the formula.

    To calculate the expires value, we use the https://www.unixtimestamp.com/index.php website. You input the date you want to convert and then click the Convert button. Copy the value in milliseconds to a safe place.

    To calculate the signature, we used this site: https://www.freeformatter.com/hmac-generator.html#ad-output.

    In the Copy-paste the string here field, we will type the verb, path and expires values, concatenated without any spaces.

    In the Secret Key field, we will input the api-secret we previously obtained in Step 2.

    Click the COMPUTE HMAC button to display the result. This is the value for your_api_signature_value. Copy the result in a safe place, because you’ll need it shortly.

    HMAC generator/tester tool
    HMAC generator/tester tool

    your_api_key_value is the value of the api key you previously obtained in Step 2.

    your_api_expires_value is the value of the expires variable (in milliseconds) that you obtained earlier in this step.

    Now that we have all the necessary details, we could write them into the Apipheny add-on like so:

    Bitmex API URL and Headers entered into the Apipheny add-on in Google Sheets
    Bitmex API URL and Headers entered into the Apipheny add-on in Google Sheets

    Step 5.) Run the Bitmex API request in your Google Sheet

    Finally, the last step is to click the Run button at the bottom of the Apipheny add-on and then wait for the Bitmex API data to be imported into your Google Sheet. Here’s what our request looked like when completed:

    That’s it! You’ve successfully connected your Bitmex account to Google Sheets using the Bitmex API, Google Sheets API, and the Apipheny add-on.

    After making a successful request to the Bitmex API, try querying a different Bitmex API endpoint, or try using one of the more advanced features in the Apipheny add-on.


    ⭐️ Related article: how to place a buy order on Bitmex from your Google Sheet