⭐️ This procedure assumes you have already successfully completed this tutorial: How to connect Bitmex to Google Sheets

Make sure you have installed Apipheny and have already successfully imported Bitmex API data into your Google Sheet and are familiar with such processes before commencing this next stage.

How to place a buy order on a crypto exchange from Google Sheets

In this tutorial we will show you how to connect your Google Sheet to a Bitmex Testnet account and place a market order in a simulated trading environment.

These steps will show you how to setup and place market orders on Bitmex Testnet. If you successfully complete the steps then it should be relatively easy to transition to a live account on Bitmex.

Step 1.) Obtain a Bitmex Testnet API Key

Login (or register) on the Bitmex Testnet: https://testnet.bitmex.com/

Next, select Information > API Documentation > API Key Management and then create your API Key and Secret. Note both values down for use in later steps.

Step 2.) Choose a Bitmex Testnet API endpoint

Open the Bitmex Testnet API documentation page: https://testnet.bitmex.com/api/explorer/

Note that the base URL for Testnet is: https://testnet.bitmex.com/api/v1

To enable us to place at market orders we will use the following endpoint on Testnet: https://testnet.bitmex.com/api/v1/order

Note: make sure the v in the url is lower case

Step 3.) Enter your Bitmex Testnet 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 POST

API URL: Now copy and paste the following URL into Apipheny, where it says API URL Path:

https://testnet.bitmex.com/api/v1/order

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

Header 1
Key:
api-key
Value:
your_api_key (obtained in Step 1)
Header 2
Key:
accept
Value:
application/json
Header 3
Key:
api-expires
Value:
api_expires_value (see below to calculate)
Header 4
Key:
api-signature
Value:
api_signature_value (see below to calculate)

To calculate the api_expires_value, we used https://www.unixtimestamp.com/index.php. You input the date you want to convert and then click the Convert button. Copy the value in milliseconds and input as the value in Header 3. In this case we used a value of 1678360193.

POST Body:

In Apipheny, below the Headers section, you will see a section titled POST Body (when you choose the POST method).

The POST body will contain your order details and it will also need to be incorporated in the api_signature_value calculation of Header 4.

In order to complete an at market Buy order on Testnet, copy and paste the following string in the POST Body:

{"symbol":"XBTUSD","orderType":"market","orderQty":100}

Make sure there are no spaces, and commas and quotation marks are in the right place. In addition, when filling in the POST Body, do it exactly as detailed in the screenshot shown below.

The api_signature_value 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 in Step 1
  • The verb is the method we are using (POST)
  • The path value represents the path to your Bitmex Testnet endpoint, in this case /api/v1/order
  • Expires represents the date you want the request to expire converted in milliseconds (calculated as per above)
  • The data part of the HMAC construction is the POST Body string detailed above and should be exactly the same.

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

  • In the Copy-paste the string here field, we entered the verb, path, expires, and POST Body values, concatenated without any spaces
  • In the Secret Key field, we input the api-secret we previously obtained in Step 1
  • Make sure you select SHA256 under Select a message digest algorithm
  • Also, before clicking COMPUTE HMAC we clicked our cursor at the end of the Copy-paste string to make sure we did not leave any spaces

Click the COMPUTE HMAC button to display the result. This is the value for your_api_signature_value.  Copy the result to the value for Header 4.

Here’s what it looked like for us:

Here is the output of our HMAC generation:

The Computed HMAC value should be placed in the value for Header 4

OK, nearly there. The screenshot on the next page shows how the Apipheny add-on should be completed. Make sure you carefully replicate this.

The screenshot below shows your Google Sheet ready to place an at market Buy order for $100 via the Apipheny add-on.

Step 4.) Run the Bitmex Testnet 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 at market order to be executed and Bitmex Testnet API data to be imported back into your Google Sheet. Here’s what our request looked like when completed:

That’s it! That’s how to connect your Bitmex Testnet account to Google Sheets using the Bitmex Testnet API and the Apipheny add-on and how to place a market Buy order directly from your Google Sheets.

If you have received an invalid signature error – go back and check you have carefully followed the instructions exactly. Simply missing a comma, adding a space, or incorrect punctuation can cause an error.

If these steps have worked for you then you can try further experimentation. For example, a sell order would use -100 as the orderQty. The good thing about using Apipheny with Testnet is that you can experiment as much as you want in a safe and simulated environment.  

Wishing you good luck!


Crypto API Tutorials:

Binance API | Bitfinex API | Bitmex API | BscScan API | Cardano API | Coinbase API | Coingecko API | Coinmarketcap API | CoinAPI | Etherscan API | Glassnode API | Messari API | Nomics API | OpenSea API | PancakeSwap API | Rarible API

You might also like:

  • CoinStats: a portfolio manager app for tracking crypto holdings from multiple wallets and exchanges
  • Best Crypto APIs: a comprehensive list of the best APIs for cryptocurrency traders, hodlers, and devs


API Tutorials



API Knowledge

What is an API?
What is an API URL?
What are parameters?
What is an endpoint?
What is an API key/token?
What is basic authentication?
What are headers?
What is a GET request?
What is a POST request?