How to Upload Crypto Prices to Google Sheets

How to Upload Crypto Prices to Google Sheets

Google Sheets is Google’s alternative to Microsoft’s Excel, and allows, among other things, the import of crypto prices.

In fact, Google Sheets is used online, as SaaS (Software-as-a-Service), so it is by definition connected to the network. Excel, on the other hand, is standalone software that runs on the user’s machine even offline.

Being connected, Google Sheets can connect to other data sources, even updating in real time.

How to import crypto prices into Google Sheets

Although it is not easy, data from external sources can be imported into Google Sheets, and among the data that can be imported in this way are updated prices from crypto markets.

It is necessary to use a solution that utilizes IMPORTXML function, and there is also a video tutorial showing how to proceed.

This tutorial is short but not complete, so much so that there is also another one that is more complete but also longer.

The data source

The source of the data is the website CoinMarketCap (CMC), from which XML data can be extracted that can be imported into Google Sheets.

To proceed, it is necessary to open one by one the individual CMC sheets for all the cryptocurrencies you wish to import the prices of.

Of these you must copy the URL, which for example for Bitcoin is

Using the URL of the CMC card, it is possible to import the data on the card into any Google Sheets document using the IMPORTXML function.

See also  TRON DAO Team Leaves Consensus 2023 With High Crypto Expectations - Cryptopolitan

This function has two arguments, separated by commas, that allow you to specify the URL of the data source and the data you intend to import.

To import the updated price, for example, use the argument “//div[contains(@class,’priceValue’)]”.

In other words, to display the updated price of Bitcoin in a specific cell in a Google Sheets document, you need to write the following code in that cell:

=IMPORTXML(“ “//div[contains(@class,’priceValue’)]”)

This is a workaround because the data source is actually an HTML page, and not an XML file as the IMPORTXML function wants. However, that function can also read an HTML document.

The argument used to retrieve the updated price is actually nothing more than telling the IMPORTXML function to retrieve the contents of a specific DIV element in the page’s HTML code, specifically the one labeled with the priceValue class.

This way you can theoretically tell the IMPORTXML function to display the content of any HTML element on the page found online at the specified url in the cell it is inserted into.

This solution actually allows all content on that page to be imported, as long as the container can be uniquely identified. HTML elements called DIVs are containers, and to see the HTML code of any web page you usually just need to type ctrl+u.

In the specific case of CMC, HTML code is created dynamically from JavaScript code, so with ctrl+u you see the JavaScript code, and not the HTML. But usually by right-clicking on an element on the page, you can select the “Inspect Element” option to see the HTML code for that element in the sidebar.

See also  Dogetti, PancakeSwap and Solana are considered buyable cryptoassets

How to automatically upload updated crypto data to Google Sheets

After using this solution, the updated data will be imported every time the Google Sheets document is opened.

However, by clicking File/Preferences and then selecting the Calculation tab, you can set a refresh timer of one minute or one hour to get the data updated even without having to close and reopen the file.

In this way, it is possible to have data updated every minute regarding all the prices of all the cryptocurrencies on CMC, provided you include the specific url of the tab for each one.

The problem is that sometimes CMC changes the HTML code of its pages, and if it does, the solution will stop working and the data will no longer be displayed.

Since it is quite likely that this may happen sooner or later, in the event that the data imported in this way disappears from the Google Sheets document, it will be necessary to update all the IMPORTXML functions used.

In particular, there may be a need to update the url, or to update the class name of the DIV whose content you want to retrieve.

Alternative data sources

This technique also works with any other updated HTML file that can be found on the web, as long as it is public.

The hard part is going and finding a way to be able to tell the IMPORTXML function uniquely which HTML element to go and get, but thanks to the “Inspect Element” option, it’s not that hard to look for a name, ID , or class that allows you to identify an item accurately.

See also  Crypto in pain as markets fear what the Fed Chair has to say this week on inflation

However, there remains the issue of whether the HTML code has been modified, because it is not uncommon for HTML code to be updated, or even garbled.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *