Count theses per token over the last hour
Count theses per token over the last hour.
A small analytics job: which tokens are people writing theses about right now? Three ways, from a one-off script to an always-current counter.
One-off: page through the last hour
since: "1h" bounds the query; cursor pagination walks every page. This costs one request per 100 theses.
count.tsTypeScript
import { FomoData } from "@fomodata/sdk";
const fomo = new FomoData({ apiKey: process.env.FOMODATA_API_KEY });
const counts = new Map<string, number>();
let cursor: string | undefined;
do {
const page = await fomo.theses.list({ since: "1h", limit: 100, cursor });
for (const thesis of page.data) {
const symbol = thesis.token.symbol;
counts.set(symbol, (counts.get(symbol) ?? 0) + 1);
}
cursor = page.next_cursor ?? undefined;
} while (cursor);
const top = [...counts.entries()]
.sort((a, b) => b[1] - a[1])
.slice(0, 10);
console.table(top.map(([token, theses]) => ({ token, theses })));Per token: ask for velocity
If you already know which tokens you care about, one call per token returns the last-hour count, the previous hour and the change, computed by FomoData.
velocity.tsTypeScript
const v = await fomo.tokens.velocity("$RUN");
// { last_5m: 2, last_1h: 12, previous_1h: 5, change_pct: 140, metrics_scope: "ingested", … }Always current: a rolling window
For dashboards, keep a rolling one-hour window fed by the stream. No polling, and it's accurate to the second. Seed it with step 1 on startup.
rolling.tsTypeScript
const window = new Map<string, number[]>(); // symbol → timestamps (ms)
fomo.streams.subscribe({
event: "thesis.created",
onEvent(event) {
const symbol = event.data.token.symbol;
const now = Date.now();
const recent = (window.get(symbol) ?? []).filter((t) => now - t < 3_600_000);
recent.push(now);
window.set(symbol, recent);
}
});
// theses per token over the last hour, always current
export const lastHour = () =>
[...window].map(([token, ts]) => ({ token, theses: ts.length }));Read the numbers right
metrics_scope: "ingested"
Counts cover theses FomoData has ingested, not Fomo's all-time totals. Use them as relative signals. See data sources.
- Your plan's history window bounds how far back step 1 can look.
- With a test key the numbers come from sandbox fixtures and your own test theses.