You can download it or keep them open in separate tabs.
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.
Rename the file by doing the following:
Hover the cursor over the Code.gs listed under Files on the left sidebar
Click the three dots on the right end.
A drop-down box will appear. Click Rename.
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.
The Project Settings will be loaded.
Tick the checkbox besides Show “appsscripts.json” manifest file in editor.
Once done, hover the cursor back to the icons on the left side of Apps Script. Select Editor.
Appsscript.json will appear in the list of Files. Select it.
Clear the code area again, then paste the code from Github appsscript.json file.
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.
7. Authorize Add-On
On the main menu, click Binance. Select Authorize add-on!
A box labeled Authorization Required will appear. Click Continue.
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.
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.
A list of permissions needed by the app will be listed next. Click Allow.
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!
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
And we add it to the cell where we want to place the value.
Press Enter after placing the formula.
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
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:
This will give the current value of 1 BTC in USDT.
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 Latest Historical Crypto Data
To import historical crypto data, the syntax is as follows:
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:
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:
Opening value for the hour
Highest value for the hour
Lowest value for the hour
Closing value for the hour
Volume for the given hour
Trades for the given hour
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:
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