Binance API data in Google Sheets

How to connect Binance API to Google Sheets using Apipheny

In this tutorial, you’ll learn how to connect the Binance REST API to Google Sheets in 5 steps using the Apipheny API integrator for Google Sheets:

  1. Install the Apipheny Add-on
  2. Get your Binance API key
  3. Create a Binance API URL with endpoint
  4. Add Binance API URL into the Apipheny Add-on
  5. Run the Binance API Request in Google Sheets

Step 1.) Install and open the Apipheny Add-on in Google Sheets

To pull data from the Binance API to Google Sheets, you’ll have to install and open the Apipheny Google Sheets add-on.

Apipheny is a no-code API integrator for Google Sheets that you can use to make unlimited API requests, connect to unlimited APIs, save API requests, schedule API requests, and more. Click here for more information about Apipheny on the homepage. There’s a 30-day free trial included, then it’s $19-$29/month.

1.) Install Apipheny by opening the following link in on desktop and then clicking the Install button on the page: https://gsuite.google.com/marketplace/app/apipheny/966163326746

2. After you’ve installed Apipheny, open a Google Sheet and then click on the Add-Ons option in the top menu. In the add-ons menu, you should see Apipheny.

Click Apipheny > Import API to open the Apipheny sidebar in your Google Sheets.

Step 2.) Get your Binance API Key

In order to access most Binance REST API endpoints, you will need an API key. To obtain an API key, follow the following instructions. If you already have your key you can skip this section.

1. After logging in to your Binance account, click API Management in the user center drop-down box:

2. If you did not install 2-factor authentication (2FA) when creating your Binance account, you will be asked to do add 2FA at this point:

Choose between Google authentication or SMS authentication
Choose between Google authentication or SMS authentication

In this example I chose SMS Authentication. Click the Send SMS button to receive a code on your mobile phone. After you have received the code, enter it in the SMS Verification Code section. You can also choose Google Authentication, which is more secure. After you add 2FA, this popup will disappear and you can continue obtaining your API key.

Two factor authentication Binance
Two factor authentication Binance

3. When the API management page finally opens, enter a name (label) for your private API key, and then click the Create button:

4. Next, fill in the Google Authentication Code or SMS Authentication Code again, to confirm the API Key creation for your account:


5. Once you have passed the 2FA Authentication, the system will send a confirmation email to the email address of your Binance account. You can go directly to your email or click the Go to email and verify button on the Binance page:

6. In the email, click the Confirm new API key button:

7. On the next page you will see your API key and Secret key. Remember to copy and paste your Secret Key somewhere safe, as it will not be shown again, due to security reasons. If you forget the Secret Key, you will need to delete the API key and then create a new one.

Step 3.) Choose a Binance API URL endpoint

To explore endpoint URLs and query requirements, go the Binance API documentation page here: https://binance-docs.github.io/apidocs/spot/en/#general-info

All Binance endpoint URLs are created by appending an endpoint-specific path to the root URL:

https://api.binance.com

For this example, we are using the API URL: https://api.binance.com/sapi/v1/margin/allPairs

If you want to use the same example URL as us, skip to the next section. If you want to create your own endpoint URL, keep reading.

For GET endpoints, parameters must be sent as a query string, while for POST, PUT, and DELETE endpoints, they may be sent either as a query string, or in the request body, with content type application/x-www-form-urlencoded.

No specific order is imposed on the parameters and both the query string and the request body approach can be used for the same query.

If your API endpoint needs to use an API key, then it must be sent through a dedicated X-MBX-APIKEY header:

Signed endpoints require an additional parameter called signature, a keyed HMAC SHA256 signature with your secretKey as the key and a concatenation of all the query’s parameters as the value passed to the HMAC operation.

Signed endpoints also require a timeStamp parameter, populated with the request’s millisecond timestamp:

A conclusive example for a signed endpoint is represented by the Order API endpoint

Step 4.) Add your Binance API URL into the Apipheny add-on

Back in your Google Sheet, make sure the Apipheny add-on is open, on the “Import” tab.

After you’ve found the endpoint you need in Step 3, copy the complete URL into the API URL Path field in the Apipheny add-on, followed by any GET parameters required for your query (see screenshot below).

Here’s the example URL we used:

https://api.binance.com/sapi/v1/margin/allPairs

At the top of the add-on select the HTTP method (GET or POST) required by your API endpoint. For this example we are using GET.

Into the Headers section in Apipheny, you should add two rows with the following keys and values:

Key 1:
Accept
Value 1: 
application/json
Key 2:
X-MBX-APIKEY
Value 2:
your-API-key

your-API-key is the value you got in Step 2.

The Accept and X-MBX-APIKEY headers are required, so you should add them in the dedicated table, below the API URL Path (JSON / CSV) field:

It doesn’t matter what order you add the headers in.

Step 5.) Run the Binance API Request

Lastly, click the Run button at the bottom of the Apipheny add-on and then wait for the Binance API data to be imported into your Google Sheet.

Binance API data in Google Sheets
Binance API data in Google Sheets

After making a successful request to the Binance API, try querying a different endpoint, or try using one of the more advance features in the Apipheny add-on, such as:

  • Save and schedule your API request
  • Make a POST request (if available)
  • Use the custom =APIPHENY() function to call the API request inside your spreadsheet
  • Create an API request by referencing the value of a cell in the API URL with three curly braces eg. {{{Sheet1!A1}}}

Related articles:

Related Posts

Leave a Comment