Binance API data in Google Sheets

👉 Looking for a cryptocurrency portfolio tracker? Click here to learn more about CoinStats, a crypto portfolio manager that you can use to track your holdings from multiple wallets and exchanges.

⭐️ Crypto API Tutorials: Coingecko API | Coinmarketcap API | CoinAPI | Binance API | Bitmex API | Best Crypto APIs

How to connect Binance to Google Sheets

Binance is one of the world’s most popular cryptocurrency exchanges, and their API is one of the most popular crypto exchange APIs. If you haven’t signed up for Binance yet, click here to sign up and register a new account.

We can use Binance’s API to import data from Binance into Google Sheets. 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. Choose your Binance API endpoint
  3. Enter your Binance API request into Apipheny

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

To pull data from the Binance API to Google Sheets, first 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.

1.) Install Apipheny by clicking the Install button on this page.

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.) Choose a Binance API URL endpoint

An “endpoint” is a specific API URL that returns the specific data you want from Binance. In this section we show you how to browse the Binance API documentation to find the URL that returns the specific data you need. If you’d like to see specific examples of URLs you can use, just skip to the next section.

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

If you are experiencing problems with the above API root, please use an alternate as outlined in the general API information section of the official Binance documentation.

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 to learn how.

To research the different endpoint URLs you can use, visit the documentation here: https://binance-docs.github.io/apidocs/spot/en/#general-info

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.

Official Binance Documentation Page
Official Binance Documentation Page

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

Endpoint Security Type
Endpoint Security Type

Signed endpoints

Signed” Binance API endpoints that require HMAC SHA256 will not currently work with our add-on, but endpoints that do not require HMAC SHA256 will work, such as the /allPairs endpoint we covered above. Some Binance API endpoints require HMAC SHA256 and others don’t. This tutorial goes through an example that doesn’t require HMAC SHA256.

The reason signed endpoints don’t currently work with our app is because they 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:

Signed Endpoints
Signed Endpoints

An example of a signed endpoint is the Order API endpoint

Order API  Endpoint - Part 1
Order API Endpoint – Part 1
Order API Endpoint - Part 2
Order API Endpoint – Part 2

You can tell if an endpoint is signed or not because when you look at the documentation for that endpoint, it will say “(HMAC SHA256)” next to the URL.

Step 3.) Enter your Binance API URL into the apipheny Add-on

a.) For Public Endpoints

Public endpoints can be accessed without an API key.

To identify the public endpoints you have to look for those which don’t require an API key or a signature in their documentation. We are interested in the ones that have “NONE” as “security type” in the table below:

Security TypeDescription
NONEEndpoint can be accessed freely.
TRADEEndpoint requires sending a valid API-Key and signature.
MARGINEndpoint requires sending a valid API-Key and signature.
USER_DATAEndpoint requires sending a valid API-Key and signature.
USER_STREAMEndpoint requires sending a valid API-Key.
MARKET_DATAEndpoint requires sending a valid API-Key.
Security type table

The security type for each endpoint can be found next to its title, inside round brackets “( )”.

If an endpoint doesn’t have round brackets next to its title and doesn’t have a HMAC SHA256 reference, it means that its security type is NONE and is a public endpoint that can be accessed without an API key or a signature.

The only category from the Binance API documentation that contains public endpoints, that requires no API key is Market Data Endpoints.

Market Data Endpoints Category
Market Data Endpoints Category

An example public endpoint that requires no key is Symbol Price Ticker, which gets the latest price for one or multiple symbols. It uses the GET method and the URL for this endpoint is:

https://api.binance.com/api/v3/ticker/price

To use this endpoint, just copy and paste this URL into the Apipheny add-on. After you enter the URL into the add-on, click the “Run” button at the bottom of the Apipheny add-on and each crypto’s current price will be imported into your Google Sheet, as shown in the screenshot:

Symbol Price Ticker Endpoint
Symbol Price Ticker Endpoint

MORE EXAMPLE BINANCE API URLS

Check Server Time, which tests connectivity to the Rest API and gets the current server time. It uses the GET method and its URL is https://api.binance.com/api/v3/time

To use this endpoint, just copy and paste this URL into Apipheny. After you enter the URL into the add-on, click the “Run” button at the bottom of the Apipheny add-on and the data will be imported into your Sheet, as shown in this screenshot:

Check Server Time Endpoint
Check Server Time Endpoint

Order Book, which provides a listing of the ongoing orders in the system. It uses the GET method and its URL is https://api.binance.com/api/v3/depth?symbol=<your_symbol>

When using this endpoint, do not forget to replace <your_symbol> with an actual symbol. I choose BTCUSDT value for this example.

Order Book Endpoint
Order Book Endpoint

Symbol Order Book Ticker, which gets the latest orders for one or multiple symbols. It uses the GET method and its URL is https://api.binance.com/api/v3/ticker/bookTicker

Symbol Order Book Ticker Endpoint
Symbol Order Book Ticker Endpoint

Recent Trades List, which returns a list of most recent trades on the platform. It uses the GET method and its URL is https://api.binance.com/api/v3/trades?symbol=<your_symbol>

Do not forget to replace <your_symbol> with an actual symbol. I choose ETHBTC value for this example:

Recent Trade List Endpoint
Recent Trade List Endpoint

b.) For Authenticated Endpoints

In order to access most Binance REST API endpoints, you will need an API key. To obtain an API key, follow the instructions below. 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:

Binance Account Dashboard
Binance Account Dashboard

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 and SMS Authentication
Choose Between Google Authentication and 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
Two-Factor Authentication

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

Create a Label For Your API Key
Create a Label For Your API Key

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

SMS or Google Authentication Code
SMS or Google Authentication Code

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:

Confirmation Email
Confirmation Email

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

API Key Confirmation
API Key Confirmation

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.

API Key and Secret Key Section
API Key and Secret Key Section

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

In this section, we show you how to enter your Binance API request into Apipheny. This section explains how to enter an API request that requires an API key. For API endpoints that don’t require an API key (section 3a.), you can just enter your URL into Apipheny and click “Run”.

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 endpoint we used that requires an API key:

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, like so:

Insert the API URL and Headers Into Apipheny
Insert the API URL and Headers Into Apipheny

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 Posts

Leave a Comment