# Asset Sales Targets and Tracking With CoinMarketCap API ( API is optional )

You can use this spreadsheet either with or without the CoinMarketCap API. If interested in using the API as well, you can find that code and instructions at the bottom.Use this spreadsheet to track each individual assets sale points and holdings with percentages, fixed values, and automatic calculations with the use of the CoinMarketCap API for price, supply, and market cap tracking. Duplicate this sheet for each asset that you're monitoring and establishing sale points and ladders for. In the sales targets table, you only have to set the X ( sales point multiplier ) and % ( Percentage of holdings to allocate to the sale point. ) If not using certain rows for sale points, clear the % cell and set the multiplier to 1 or more.

For this spreadsheet to work properly you should include the apps script in Extensions > Apps Script. Copy and paste the code below into the apps script code editor, then hit save and run. If you want to use the CoinMarketCap asset statistics then create a CoinMarketCap account and look for your account's API key. Plug the API key in at the top. The spreadsheet does not need these statistics to serve it's purpose however. The rest of the code is going to autofill certain cell columns and rows as needed and should be kept.

{% file src="/files/KmgH9O9bwRqMRE5fhXOe" %}

<figure><img src="/files/goW52ljiwldItax5VOSV" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/BtNmb5D1bEWp6Zh88NZi" alt=""><figcaption></figcaption></figure>

## Ensure that you save and run it in extensions > apps script. It's going to ask for permission and the confirmation with your google account. Show advanced, and navigate to the confirmation page by selecting the sheet link below advanced.

```
var apiKey = ''; // Coinmarketcap API key for asset data ( not required )

function onEdit(e) {
  var sheet = e.source.getActiveSheet();
  var range = e.range;
  var startRow = range.getRow();
  var numRows = range.getNumRows();
  var startCol = range.getColumn();

  // Handle edits in Column G (7), any row(s)
  if (startCol === 7) {
    replaceEmptyWithOneIfEmptyBatch(sheet, startRow, numRows);
  }

  // Handle edits in Column N (14), any row(s)
  if (startCol === 14) {
    for (var i = 0; i < numRows; i++) {
      var row = startRow + i;
      var targetP = sheet.getRange(row, 16);
      var targetO = sheet.getRange(row, 15);
      var value = sheet.getRange(row, 14).getValue();

      if (value === "Long term") {
        targetO.clearContent();
        targetO.setValue(0);
        targetP.setFormula("=F" + row + "-(F" + row + "*G$6)");
      } else if (value === "Short term") {
        targetP.clearContent();
        targetP.setValue(0);
        targetO.setFormula("=F" + row + "-(F" + row + "*F$6)");
      } else {
        targetP.clearContent();
        targetO.clearContent();
        targetP.setValue(0);
        targetO.setValue(0);
      }
    }
  }
}

function replaceEmptyWithOneIfEmptyBatch(sheet, startRow, numRows) {
  var range = sheet.getRange(startRow, 7, numRows, 1);
  var values = range.getValues();
  var changed = false;

  for (var i = 0; i < values.length; i++) {
    if (values[i][0] === "" || values[i][0] === null) {
      values[i][0] = 1;
      changed = true;
    }
  }

  if (changed) {
    range.setValues(values);
  }
}








function fetchCryptoData(symbol) {
  var url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=" + symbol.toUpperCase();
  var headers = {
    "X-CMC_PRO_API_KEY": apiKey,
    "Accept": "application/json"
  };
  var options = { "headers": headers, "muteHttpExceptions": true };
  var response = UrlFetchApp.fetch(url, options);
  var json = JSON.parse(response.getContentText());
  if (json.status.error_code === 0 && json.data && json.data[symbol.toUpperCase()]) {
    return json.data[symbol.toUpperCase()];
  } else {
    return null;
  }
}
function getCryptoPrice(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.quote.USD.price : "Error";
}
function getCryptoVolume24h(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.quote.USD.volume_24h : "Error";
}
function getCryptoPercentChange1h(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.quote.USD.percent_change_1h : "Error";
}
function getCryptoPercentChange24h(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.quote.USD.percent_change_24h : "Error";
}
function getCryptoPercentChange7d(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.quote.USD.percent_change_7d : "Error";
}
function getCryptoMarketCap(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.quote.USD.market_cap : "Error";
}
function getCirculatingSupply(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.circulating_supply : "Error";
}
function getTotalSupply(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.total_supply : "Error";
}
function getMaxSupply(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.max_supply : "Error";
}
function getLastUpdated(symbol) {
  var data = fetchCryptoData(symbol);
  return data ? data.last_updated : "Error";
}

```

​

[<br>](https://app.gitbook.com/o/kEv10oIZUnagumfomaki/s/fwYk6FfVyS5wxhqFdZxB/~/diff/~/changes/268/~/revisions/sicM9du9v6EBvehKoP4S/software-and-development/google-spreadsheets)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jroy-1.gitbook.io/what-if-difference/software-and-development/projects/spreadsheets/asset-sales-targets-and-tracking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
