---
id: I0046
title: "Excel SOL price ticker"
url: https://carbium.sh/library/integrate/excel-sol-price-ticker
collection: Integrations
category: Spreadsheets and workspaces
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Excel SOL price ticker

A Node script reads the SOL price from Carbium every 15 seconds and writes it to a CSV file. Excel loads that file through Power Query and refreshes a ticker cell on a timer, with each reading stamped by time and slot.

## What you end up with

The goal is one Excel cell that shows the current SOL price and changes while the workbook is open. A small Node script reads the price from Carbium and writes it to a CSV file. Excel loads that file through Power Query and refreshes it on a timer.

The script depends on `@solana/kit` alone and never talks to Microsoft. The workbook needs no add-in and no macro, only a query and a formula.

| Part | Where | What happens |
|---|---|---|
| Read | `node main.ts` | One `prices` call and one `getSlot` call every 15 seconds. |
| Write | `sol_price.csv` | Replaced whole on each reading: a header and one row. |
| Load | Data, Get Data, From File, From Text/CSV | The file becomes a table named `sol_price`. |
| Refresh | Query Properties, Refresh every | The table reloads on the minute count you set. |
| Show | `=INDEX(sol_price[price],1)` | The latest price sits in any cell you choose. |

## The Solana side: one price call and one slot

Carbium answers price and quote calls on the [same endpoint as plain RPC](https://carbium.sh/docs#endpoints), `https://services.carbium.sh`. The quote plane has four methods: `quote`, `swap`, `health` and `prices`. The script calls `prices` with a `fetch` POST and carries the key in the `x-api-key` header, the same header the `@solana/kit` transport sends for the slot call.

A key without the [QUOTE scope](https://carbium.sh/docs#quote) is refused on quote calls with 401 and code -32001, so give the key that scope in your account before the first run.

The script makes one `prices` call with an empty params list and reads the SOL price from the answer.

Each reading also carries a slot from `getSlot` at confirmed commitment. The `time` column dates each row and the slot places it on the chain, which is enough to line it up against other chain data.

`getSlot` is a [cheap cached read](https://carbium.sh/docs#rpc) and metered RPC work, with a 1-cell admission charge a call. The quote plane [spends no credits](https://carbium.sh/docs#limits). Four readings a minute stay far under the cheap-read rate of every plan, which starts at 5 req/s on Free.

## The Excel side: load once, refresh on a timer

Start the script first, so `sol_price.csv` exists in its folder. Then, in desktop Excel:

1. Open Data, Get Data, From File, From Text/CSV, pick `sol_price.csv` and choose Load. Excel creates a table named `sol_price` with the columns `time`, `slot` and `price`.
2. Right-click the query in Queries and Connections, open Properties, tick Refresh every and enter a minute count. The smallest value is 1. Tick Refresh data when opening the file too.
3. In a cell, enter `=INDEX(sol_price[price],1)`. Put `=INDEX(sol_price[time],1)` beside it, so a stale ticker shows its age.
4. To chart the day, load `sol_history.csv` the same way and insert a line chart on its `price` column.

> Load the file through the query and leave it closed as a workbook. On Windows a CSV open in Excel is locked, the script cannot replace it, and the cell keeps its last value until you close the file.

The script writes a temporary file and renames it over `sol_price.csv`, so a refresh never reads a half written row. The history file gets one appended row per reading and starts when you first run the script.

## The script

Install the one dependency with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`. Node 24 strips the types on load. `CARBIUM_KEY` is required, and the script exits with a message when it is unset. `CARBIUM_RPC_URL` is optional. The one argument is the pause between readings in seconds, 15 by default, and 0 takes a single reading and exits.

`main.ts` (run: `node main.ts`)

```ts
// I0046 · Excel SOL price ticker
// https://carbium.sh/library/integrate/excel-sol-price-ticker
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";
import { appendFileSync, existsSync, renameSync, writeFileSync } from "node:fs";

const key: string = process.env.CARBIUM_KEY ?? "";
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));
const SOL_MINT = "So11111111111111111111111111111111111111112";
const seconds = Number(process.argv[2] ?? 15); // 0 takes one reading and exits
const HEADER = "time,slot,price\n";

type Prices = { solUsd?: unknown; rows?: unknown[][] };

// One prices call with no params: solUsd is the SOL price, the SOL row of rows is the fallback.
async function price(): Promise<number> {
  const res = await fetch(url, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": key },
    body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "prices", params: [] }),
  });
  const body = (await res.json().catch(() => ({}))) as { result?: Prices; error?: unknown };
  if (!res.ok || body.error) throw new Error(`HTTP ${res.status} ${JSON.stringify(body.error ?? "")}`);
  const n = Number(body.result?.solUsd ?? body.result?.rows?.find((r) => r[0] === SOL_MINT)?.[1]);
  if (!(n > 0)) throw new Error("the prices answer carries no SOL price");
  return n;
}

async function tick() {
  const [p, s] = await Promise.allSettled([price(), rpc.getSlot({ commitment: "confirmed" }).send()]);
  if (p.status === "rejected") return console.error(`price failed: ${p.reason}`);
  if (s.status === "rejected") console.error(`slot failed: ${s.reason}`);
  const row = `${new Date().toISOString()},${s.status === "fulfilled" ? s.value : ""},${p.value}\n`;
  try {
    writeFileSync("sol_price.tmp", HEADER + row);
    renameSync("sol_price.tmp", "sol_price.csv"); // Excel never reads a half written file
    if (!existsSync("sol_history.csv")) writeFileSync("sol_history.csv", HEADER);
    appendFileSync("sol_history.csv", row);
  } catch (e) {
    console.error(`write failed: ${e}`);
  }
  console.log(row.trim());
}

do {
  await tick();
  if (seconds > 0) await new Promise((r) => setTimeout(r, seconds * 1000));
} while (seconds > 0);
```

## Run it and keep it running

Export `CARBIUM_KEY` and run `node main.ts` in the folder your query points at. Every reading prints one line, `time,slot,price`, and every failure prints to stderr. Stop it with Ctrl+C.

A failed reading does not stop the loop. The price call and the slot call run side by side, and each failure is printed on its own. A price failure skips the write, so the file keeps the last good row. Limits are [per account](https://carbium.sh/docs#limits), so your other keys draw on the same budget. The script treats a 429 as one failed reading, and the next tick is the retry.

To run it without a terminal, start it from Windows Task Scheduler at log on, or from a systemd user unit on Linux, with the working folder set to the one the query reads. The script keeps no state apart from the two files, so a restart carries on where the history ended.

## Where it ends

- The cell is polled. The script reads every 15 seconds, but Excel refreshes no more often than once a minute, so the cell can trail the file by up to a minute.
- The `price` column holds the SOL price the `prices` call returns.
- SOL only. A second token needs its own mint and its own column.
- Excel for the web does not read a file from your disk, so the ticker works in desktop Excel.
- The script has to be running. A sleeping machine writes no rows, and the history shows the gap.
- It reads a price and moves no funds. A swap goes through the `quote` and `swap` methods, and `swap` [builds an unsigned transaction](https://carbium.sh/docs#swap) you sign and send yourself.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The script prints `price failed` with HTTP 401. | The key is unknown or lacks the QUOTE scope. Attach the [whole key](https://carbium.sh/docs#errors) in `CARBIUM_KEY` and give it the QUOTE scope in your account. A quote call from a key without the scope answers 401 with code -32001. |
| The script prints `slot failed` and the slot column is empty. | The `getSlot` call failed, for example on a 429 or a wrong `CARBIUM_RPC_URL`. The price is still written with an empty slot, and the next tick tries again. |
| The script prints `price failed` with -32601. | The method name is wrong or not served. Do not retry; [check the method](https://carbium.sh/docs#errors) and confirm the call says `prices`. |
| The script prints `price failed` with HTTP 429. | The account's budget is spent, often by other keys on it. Raise the pause between readings or wait. The next tick retries by itself. |
| The script prints readings but the Excel cell never changes. | The query has no refresh timer, or it points at a different folder than the one the script writes to. Check Properties on the query and the file path under Data Source Settings. Refresh All forces one reload. |
| The script prints `write failed` with EBUSY or EPERM. | Another program holds the file, usually the CSV opened in Excel as a workbook. Close it, and the next reading replaces the file. |

## Questions

### How often can the cell update?

As often as the Excel refresh timer fires, with a floor of one minute. The script can read every few seconds, and the history file keeps every reading for a chart.

### Can a cell call Carbium directly with WEBSERVICE?

`WEBSERVICE` sends a GET and cannot carry the JSON body or the `x-api-key` header the call needs. Power Query's `Web.Contents` can POST with headers, but the key would then sit inside the workbook, readable by anyone you send it to. The script keeps it in an environment variable.

### Does the ticker spend credits?

The [quote plane spends none](https://carbium.sh/docs#limits). `getSlot` is [metered RPC work](https://carbium.sh/docs#rpc) with a 1-cell admission charge a call.

### Can the CSV live in a OneDrive or network folder my workbook already uses?

Yes. Run the script from that folder, or copy it there, and load the file from the same path with From Text/CSV. The script still has to rename a temporary file over the CSV, so the folder must let it write and rename.

## Related

- [Google Sheets balances](https://carbium.sh/library/integrate/google-sheets-balances) (Integrations, I0016)
- [SOL balances for many accounts](https://carbium.sh/library/howsolana/sol-balances-for-many-accounts) (How to use Solana, HS0016)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#quote](https://carbium.sh/docs#quote)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#swap](https://carbium.sh/docs#swap)
