Back to Developer Tutorials
Spreadsheets & Apps Script• 6 min read•Updated: October 2026

How to Import Real-Time IPO & GMP Data into Google Sheets

Many financial analysts and investors maintain their portfolio tracking models in Google Sheets. With this copy-paste Google Apps Script snippet, you can introduce custom spreadsheet formulas like =GET_IPO_GMP() to stream live market prices and expected listing returns directly into your sheets.

1Open the Apps Script Editor

Open any Google Sheet, navigate to Extensions > Apps Script from the top navigation menu, and delete any default placeholder code.

2Paste the Custom Functions Code

Replace the contents with the following script and insert your ApiKey and ApiSecret:

Code.gs
javascript
/**
 * Google Apps Script for IPO API PRO
 * Paste this in Extensions -> Apps Script in your Google Spreadsheet
 */

const API_KEY = "YOUR_ACTUAL_API_KEY";
const API_SECRET = "YOUR_ACTUAL_API_SECRET";

/**
 * Custom formula to fetch live Grey Market Premium (GMP) for any active IPO
 * Usage in Sheet: =GET_IPO_GMP("Shah Investor") or =GET_IPO_GMP() for all
 * 
 * @param {string} companyQuery Optional company name filter
 * @return Array of IPO names, cap prices, and live GMP
 * @customfunction
 */
function GET_IPO_GMP(companyQuery) {
  const url = "https://api.ipoapipro.in/api/gmp/live-rates";
  
  const options = {
    method: "get",
    headers: {
      "ApiKey": API_KEY,
      "ApiSecret": API_SECRET,
      "Accept": "application/json"
    },
    muteHttpExceptions: true
  };

  try {
    const response = UrlFetchApp.fetch(url, options);
    const json = JSON.parse(response.getContentText());
    
    if (!json.isSuccess || !json.data) {
      return "Error: Unable to fetch live GMP feed";
    }

    const output = [["Company Name", "Issue Price (₹)", "GMP (₹)", "Est. Listing Price", "Gain (%)"]];
    const data = json.data;

    for (let i = 0; i < data.length; i++) {
      const item = data[i];
      if (!companyQuery || item.companyName.toLowerCase().includes(companyQuery.toLowerCase())) {
        output.push([
          item.companyName,
          item.ipoPrice,
          item.gmpPrice,
          item.estimatedListingPrice,
          item.estimatedListingPercentage + "%"
        ]);
      }
    }

    return output.length > 1 ? output : "No matching IPO found";
  } catch (e) {
    return "Error: " + e.message;
  }
}

/**
 * Custom formula to fetch upcoming Mainboard IPO listings
 * Usage: =GET_MAINBOARD_IPOS(5)
 * 
 * @param {number} limit Number of records to return
 * @customfunction
 */
function GET_MAINBOARD_IPOS(limit) {
  limit = limit || 10;
  const url = "https://api.ipoapipro.in/api/ipo/mainboard?pageNumber=1&perPageRow=" + limit;
  
  const options = {
    method: "get",
    headers: {
      "ApiKey": API_KEY,
      "ApiSecret": API_SECRET
    }
  };

  const response = UrlFetchApp.fetch(url, options);
  const json = JSON.parse(response.getContentText());
  const rows = [["Company", "Exchange", "Price Band", "Lot Size", "Open Date", "Close Date"]];

  json.data.forEach(function(ipo) {
    rows.push([
      ipo.companyName,
      ipo.exchanged,
      "₹" + ipo.minimumPrice + " - ₹" + ipo.maximumPrice,
      ipo.lotSize,
      ipo.startDate,
      ipo.endDate
    ]);
  });

  return rows;
}

3Use the Formulas in Your Spreadsheet

Save the script project and return to your spreadsheet. In cell A1, simply enter:

=GET_IPO_GMP()

Google Sheets will automatically expand the returned multi-row matrix into columns showing Company Name, Issue Price, Live GMP, Estimated Listing Price, and Expected Listing Return Percentage.

Related Endpoints Used in this Guide