Site icon EASY2DIGITAL

Financial Ratio TTM Generator Function Script Applied in Google App Scripts

financial ratio ttm

Google Sheets is one of the most popular platforms to manage data, such as performance trackers, financial models, and so on. In this article, I would walk through how to integrate with Easy2Digital API with Google Apps scripts to create a function. I would take the financial ratio TTM API as an example. By the end of this article, you can use this function to fetch API data based on your needs.

Ingredients on Financial Ratio TTM Functions

Google Sheet, Google Apps Script, Javascript, Easy2Digital Financial APIs

Table of Contents

Define a function with two arguments: Company Symbol and Specific Financial Data

In this function used in Google Sheets, we would have two arguments to determine the output. One is the stock symbol name, the other is the financial ratio data you aim to fetch. Here are the code sample added to create a function in the Google Apps Scripts as follows:

function easy2digitalTTM(symbol, dataSet) {

return…;

 }

Method, Data Type, and Easy2Digital API Token

As well as Python requests, we need to get the data from calling the API in this function. Furthermore, the Easy2Digtal API data format is JSON. so here is the variable code sample:

var features = {

   'method': 'get',

   'contentType': 'application/json',

 };

Then, API requires a token key to access your account. So here is the variable added to your Easy2Digital API token. If you are interested in this API, please subscribe to Easy2Digital newsletter by leaving “Financial TTM API free”, we’ll send you asap.

 var token = ""

UrlFetchApp.fetch

This service allows scripts to communicate with other applications or access other resources on the web by fetching URLs. A script can use the URL Fetch service to issue HTTP and HTTPS requests and receive responses. The URL Fetch service uses Google’s network infrastructure for efficiency and scaling purposes. In this method, at least it requires filling in two arguments. One is the HTTPS, the other is the method and content type we set earlier.

 TTM = UrlFetchApp.fetch("https://easy2digital.onrender.com/api/1/financialRatioTTM?symbol=" + symbol + "&token=" + token, features)

Jsonify

As well as the Python approach, we need to jsonify the data response as follows:

 let financialTTM = JSON.parse(TTM)[0][dataSet]

Create an array and assign the fetched value to it

Now the data is ready, so the next step is to create a list or more lists to place the value (In Google Apps Script, a list is equal to a column or a row).

In this case, we just need to create one list and place the value in the 1st position (or the 1st cell). Here are the codes as follows:

var results = new Array(1);

let dataValue = financialTTM;

 results[0] = dataValu

 return results;

 }

When things are going well, here is the result of using this function where you can see the P/B TTM value is placed into the specific cell and it’s being updated automatically in real-time.

Full Javascript and Easy2Digital API Token of Financial Ratio TTM Functions Used in Google Sheets

If you are interested in Google Apps Script – Financial Ratio TTM Functions Used in Google Sheets, please subscribe to our newsletter by adding the message “Google Apps Script, Financial Ratio TTM”. We would send you the script immediately to your mailbox.

I hope you enjoy reading Google Apps Script – Financial Ratio TTM Functions Used in Google Sheets. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

Google API Endpoint Recommendation

Google Shopping Product Scraper API

Price: US$18

Google Shopping SERP scraper crawls the product information from Google Shopping channel. API allows to filter by platform country domain, user location, language. Users can scrape the product information using a keyword query. The scraped dataset include product name, pricing, shipping fees, brand name, product page URL etc.

More API options from the Google collection. 

SAVE UP TO 50% and EXPLORE MORE!

Exit mobile version