In this article:

Import Binance API Data to Google Sheets (Easiest Way 2024)

May 8, 2024

In this article we will show how to import Binance API data to google sheets using a custom apps script. Simply follow the steps below.

How to Import Binance API Data into Google Sheets

The custom apps script that we will use creates a new function called BINANCE. We will cover the syntax and what is possible with this script in more detail after the set up steps below.

1. Set Up Recalculation of Sheet

By default, Google Sheets recalculates all the formulas in the sheet upon every change in the content and upon reloading. To get real time price values, we need to set it to recalculate every minute. 

Click File, then select Settings.

Google sheets binance api, click file, select settings

A box labeled Settings for this spreadsheet will be loaded. Click the Calculation tab. A drop-down list of options will appear under the Recalculation tab. Select On change and every minute

Google sheets binance api, set recalculation settings‍

Once done, click Save settings

2. Click Extensions then select Apps Script

After setting up the recalculation settings of the sheet, click Extensions on the main menu, then select Apps Script

Google sheets binance api, click extensions, select apps script‍

Apps Script will be loaded in a new tab. 

Google sheets binance api, google apps script in the new tab

3. Download Script from Github

Access BINANCE.gs and appsscript.json from the following repository:

https://github.com/rvbautista/binance-to-google-sheets-v2

You can download it or keep them open in separate tabs.

Google sheets binance api, binance to google sheets script‍

Google sheets binance api, appsscript code snippet shown‍

4. Insert BINANCE.gs Code to Apps Script

Copy the BINANCE.gs code from the repository above. To do so, click inside the box, then press Ctrl+A (Windows) or ⌘+A (Mac), then Ctrl+C (Windows) or ⌘+C (Mac). After copying it, go to the Apps Script tab. Clear the default code loaded then paste the BINANCE.gs code to it. 

Google sheets binance api, binance.gs script pasted to apps script‍

Rename the file by doing the following:

  1. Hover the cursor over the Code.gs listed under Files on the left sidebar
  2. Click the three dots on the right end. 
  3. A drop-down box will appear. Click Rename.

Google sheets binance api, click three dots on the right side of file name, rename command highlighted

  1. Type BINANCE.

Google sheets binance api, BINANCE file name set‍

  1. Press Enter.

Google sheets binance api, file name of the script renamed‍

Click Save.

Google sheets binance api, save project icon highlighted

5. Update appsscript.json Manifest File

Each Google Sheets spreadsheet has its own associated appsscript.json. We will also modify it by replacing it with the one in Github. Hover your cursor over the icons on the left side of Apps Script, then select Project Settings.

Google sheets binance api, hoover cursor to left sidebar, click project settings‍

The Project Settings will be loaded. 

Google sheets binance api, project settings shown

Tick the checkbox besides Show “appsscripts.json” manifest file in editor.

Google sheets binance api, project settings shown, show appsscript.json file ticked‍

Once done, hover the cursor back to the icons on the left side of Apps Script. Select Editor.

Google sheets binance api, cursor hovered in the sidebar, editor selected‍

Appsscript.json will appear in the list of Files. Select it. 

Google sheets binance api, appsscript.json default code shown‍

Clear the code area again, then paste the code from Github appsscript.json file.

Google sheets binance api, new appsscript.json code pasted‍

Click Save.

Google sheets binance api, save project icon shown

6. Reload Google Sheets

You can close the Apps Script tab. Go back to the tab containing your Google Sheets, then reload the page by refreshing it. A new option in the main menu named Binance should appear.

Google sheets binance api, binance option in main menu shown‍

7. Authorize Add-On

On the main menu, click Binance. Select Authorize add-on! 

binance option in main menu selected, authorize add-on highlighted

A box labeled Authorization Required will appear. Click Continue

api, authorization required box loaded

A new window will be loaded, asking you to choose the Google account. Most of the time, only the account you are using to create the sheet will be listed. Select it.

api, choose account page

A warning saying that Google hasn’t verified the app will appear. Click the link labeled Advanced at the bottom of the message. A link labeled Go to Untitled project (unsafe) will appear. Click it. 

google hasnt veriried this app warning

A list of permissions needed by the app will be listed next. Click Allow.

 list of permissions needed by the script

The window will close, and a small box will appear on the lower-right corner of the sheet with the message Ready to rock, the add-on is authorized and running, enjoy!

message that the app is autrhorized shown on lower-right of google sheets‍

8. Use =BINANCE(data, coin) in the Sheet

Finally, you can now use the function in the Sheet! For our example, we want to import the current price of Bitcoin. The formula is

=BINANCE(“prices”, “BTC”)

And we add it to the cell where we want to place the value. 

binance formula input to a cell‍

Press Enter after placing the formula.

binance formula output shown

The script works! Note that this involves data that can be publicly accessed via the official Binance website. 

Binance API Syntax Explained

BINANCE is a powerful function that can access both the market data and the data you use in your orders. The most basic syntax has the following format:

=BINANCE(data, coin, options)

Where data is the specific information about the coin that you want to import, while options helps set options regarding the data you want imported.

Listed below are some ways of using it:

Current Value of Crypto

=BINANCE(“prices”, coin)

Where coin is the ticker code for the cryptos current value you want to import. Enclose the coin in double quotes. With this syntax, the value given will be in terms of USDT, one of the crypto coins pegged in USD. Example:

=BINANCE(“price”, “BTC”)

This will give the current value of 1 BTC in USDT. 

 import current crypto value‍

Current Value of Crypto Based on Another Crypto

If you want to compare the value against a different crypto, specify the other crypto using the following syntax:

=BINANCE(“prices”, coin, ref_coin)

Where ref_coin is the reference crypto used in defining the value of the coin. Enclose both the coin and the ref_coin in double quotes. For example, if you want to get the price of BTC in terms of BUSD, the formula will look like as follows:

=BINANCE(“prices”, “BTC”, “BUSD”)

import current crypto value based on another crypto‍

Import Latest Historical Crypto Data

To import historical crypto data, the syntax is as follows:

=BINANCE(“history”, coinpair)

Where coinpair is a combination of the crypto and the reference used. Enclose coinpair in double quotes. For example, if you want to get the history of BTC in terms of USDT, use the following formula:

=BINANCE(“history”, “BTCUSDT”)

It will give you a table containing the following information about the BTC-USDT exchange for the last 500 hours, with one hour interval each row:

  • Open time
  • Opening value for the hour
  • Highest value for the hour
  • Lowest value for the hour
  • Closing value for the hour
  • Close time
  • Volume for the given hour
  • Trades for the given hour

 import historical crypto

The only problem with this syntax is that the results are arranged in ascending order, pushing the latest results to the end of the range. You can remedy this by simply specifying more options in the formula. For example, you can specify the interval, the date range, and the limit in the number of results. These will be explained through more examples in the next subsections.

Import Historical Crypto Data, Range of Dates Specified

You can specify the range of dates of historical crypto data to import:

=BINANCE(“history”, coinpair, “start: start_date, end: end_date”)

Where the start_date and the end_date are in yyyy-mm-dd format. Enclose coinpair in double quotes. For example, we want to import BTC-USDT data from March 20, 2023 to March 23, 2023. The formula becomes

=binance("history", "BTCUSDT", "start: 2023-03-20, end: 2023-03-23")

Limit Number of Rows in Historical Crypto Data

If you want to import the latest historical crypto data but limit the entries to a certain number, use the following syntax:

=BINANCE(“history”, coinpair, “limit: rows”)

Where rows is the number of rows to add. It will begin from the latest value. For example, we want to import the latest 10 hourly values of BTC-USDT. The formula is then set as

=binance("history", "BTCUSDT", "limit: 10")

 import last 10 historical crypto data‍

Import Historical Data, Specifying Time Interval

You can specify the interval by using the following syntax:

=binance("history", coinpair, "interval: interval_length")

Where interval_length is the length of time interval:

  • 15m means the interval is every 15 minutes
  • 2h means the interval is every 2 hours
  • 3d means the interval is every 3 days

Enclose coinpair in double quotes. 

For example, we want to import the value of BTC-USDT exchange rates every 12 hours. Additionally, we also set that we want the latest 10 values. The formula is then set as

=binance("history", "BTCUSDT", "interval: 12h, limit: 10")

import historical crypto data, interval specified‍

Summary of the Last 24 Hours of Trading of Crypto

Finally, you can get the summary of the last 24 hours of trade of a specified crypto coin. The syntax is 

=BINANCE(“stats/24h”, coin)

Where coin is the ticker for a specific crypto coin. Enclose coin in double quotes.

This will give you the following values:

  • Price
  • Ask
    Bid
  • Open
  • High
  • Low
  • Prev Close
  • $ Change 24h
  • % Change 24h
  • Volume

 import 24 hour summary crypto data

If you enjoyed this article, you might also like our article on how to import Yahoo finance data into Google Sheets or our article on how to do conditional formatting in Google Sheets. 

If you want to learn how to create an email list from Google Sheets, we also suggest checking out our detailed guide.

Get Google Sheets productivity and automation tips delivered straight to your inbox
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
We'll email you 1-3 times a week — and never share your information.

Work less, automate more!

Use Lido to connect your spreadsheets to email, Slack, calendars, and more to automate data transfers and eliminate manual copying and pasting. View all use cases ->