Tracking gold bullion

Can I track the price of my gold bullion via Tiller?

Tiller Feeds pulls data from your linked banking institutions. There are no hooks or feeds into commodities. There may be other ways, feeds, or formulas to pull in semi-real-time commodity values.

1 Like

Here you go - You just need to change the kg. Used this from the Zillow posting
var apiKey = “UPDATETHIS”;
var currencies = [“USD”];

function GoldPriceInsert() {
// load the moment library for date/time handling
eval(
UrlFetchApp.fetch(
“https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js”
).getContentText()
);

// get the Balance History sheet
var balanceHistorySheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(
“Balance History”
);
// get the Balance History header row
var header = balanceHistorySheet
.getRange(1, 1, 2, balanceHistorySheet.getMaxColumns())
.getValues()[0];

var columns = {};
var rows = ;

// create a lookup for Balance History column headers
for (var columnIndex = 0; columnIndex < header.length; columnIndex++)
columns[header[columnIndex].toString().trim().toLowerCase()] = columnIndex;

// Get today’s date
const today = new Date();

// step through each currencies in the array
for (var i = 0; i < currencies.length; i++) {
// scrape vinAudit’s information
const currency = currencies[i];
var estimate = GoldPriceFetch(
apiKey,
currencies
);

if (estimate) {
  var row = [];

  // initialize a new row array
  for (var j = 0; j < header.length; j++) row.push("");

  function safeSetVal(columnName, value) {
    if (columnName.length && columns.hasOwnProperty(columnName))
      row[columns[columnName]] = value;
  }

  // build a balance history row where column header's exist in the active spreadsheet
  const today = moment();
  const time = today.format("h:mm A");
  const { currencies, goldPricePerKg } = estimate;
  safeSetVal("date", today.format("M/D/YYYY"));
  safeSetVal("date added", today.format("M/D/YYYY"));
  safeSetVal("week", today.startOf("week").format("YYYY-MM-DD"));
  safeSetVal("month", today.startOf("month").format("YYYY-MM-DD"));
  safeSetVal("time", time);
  safeSetVal("balance", goldPricePerKg);
  safeSetVal("account", "1kg Gold Bar");
  safeSetVal("account #", currencies);
  safeSetVal("account status", "ACTIVE");
  safeSetVal("account id", "manual:d52be8a4-2bc1-4ce7-bfe0-c0115b066cc7");
  safeSetVal("index", currencies);
  safeSetVal("institution", "metalpriceapi");
  safeSetVal("type", "PROPERTY");
  safeSetVal("class", "Asset");
  safeSetVal("miles", "");

  // push the new row into the array of rows to add
  rows.push(row);
}

}

// if new rows were created, add them to the sheet…
if (rows.length) {
// add new rows to the sheet
balanceHistorySheet
.getRange(
balanceHistorySheet.getLastRow() + 1,
1,
rows.length,
rows[0].length
)
.setValues(rows);

// re-sort the Balance History sheet by date
if (columns.hasOwnProperty("date"))
  balanceHistorySheet.getDataRange().sort([
    {
      column: columns["date"] + 1,
      ascending: false,
    },
  ]);

}
}

function GoldPriceFetch(apiKey, currencies) {
// create a url to query the metalpriceapi web service
var url = “https://api.metalpriceapi.com/v1/latest?api_key=” + apiKey + “&base=XAU&currencies=” + currencies;
// Fetch data from the API
var json = UrlFetchApp.fetch(url).getContentText();
var data = JSON.parse(json);
// Extract the gold price per troy ounce
const goldPricePerTOz = data.rates.USD;
// Calculate the price of a 1 kg bar = 32.1507 troy ounce
const goldPricePerKg = goldPricePerTOz * 32.1507;
// return an object with relevant values
return {goldPricePerKg};
}

1 Like