-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkets.js
More file actions
306 lines (292 loc) · 14.9 KB
/
Copy pathmarkets.js
File metadata and controls
306 lines (292 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/**
* Markets / Heatmap mode — live financial tickers as GPU wall tiles.
* Sorted/grouped by sector (genre), exchange, world region.
* Colors by % change (green up / red down). Similar to TradingView/Yahoo heatmaps.
*
* Uses public Yahoo Finance quote API (no key). Chunks + polite backoff.
*/
(function (global) {
// Curated list of current liquid tickers across sectors, exchanges, regions.
// Order is "importance" order for default load (majors first). Expand as needed.
const TICKER_LIST = [
// IT (US)
{ symbol: "AAPL", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "MSFT", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "NVDA", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "GOOGL", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "AVGO", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "META", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "AMD", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "ADBE", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "CRM", sector: "Information Technology", exchange: "NYSE", region: "US" },
{ symbol: "INTC", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "ORCL", sector: "Information Technology", exchange: "NYSE", region: "US" },
{ symbol: "IBM", sector: "Information Technology", exchange: "NYSE", region: "US" },
{ symbol: "CSCO", sector: "Information Technology", exchange: "NASDAQ", region: "US" },
{ symbol: "ACN", sector: "Information Technology", exchange: "NYSE", region: "US" },
// IT (Intl ADRs + listings)
{ symbol: "TSM", sector: "Information Technology", exchange: "NYSE", region: "Asia" },
{ symbol: "ASML", sector: "Information Technology", exchange: "NASDAQ", region: "Europe" },
{ symbol: "SAP", sector: "Information Technology", exchange: "NYSE", region: "Europe" },
// Consumer Discretionary
{ symbol: "AMZN", sector: "Consumer Discretionary", exchange: "NASDAQ", region: "US" },
{ symbol: "TSLA", sector: "Consumer Discretionary", exchange: "NASDAQ", region: "US" },
{ symbol: "HD", sector: "Consumer Discretionary", exchange: "NYSE", region: "US" },
{ symbol: "MCD", sector: "Consumer Discretionary", exchange: "NYSE", region: "US" },
{ symbol: "NKE", sector: "Consumer Discretionary", exchange: "NYSE", region: "US" },
{ symbol: "LOW", sector: "Consumer Discretionary", exchange: "NYSE", region: "US" },
{ symbol: "SBUX", sector: "Consumer Discretionary", exchange: "NASDAQ", region: "US" },
{ symbol: "BKNG", sector: "Consumer Discretionary", exchange: "NASDAQ", region: "US" },
{ symbol: "TJX", sector: "Consumer Discretionary", exchange: "NYSE", region: "US" },
{ symbol: "GM", sector: "Consumer Discretionary", exchange: "NYSE", region: "US" },
// Consumer Staples
{ symbol: "PG", sector: "Consumer Staples", exchange: "NYSE", region: "US" },
{ symbol: "COST", sector: "Consumer Staples", exchange: "NASDAQ", region: "US" },
{ symbol: "WMT", sector: "Consumer Staples", exchange: "NYSE", region: "US" },
{ symbol: "KO", sector: "Consumer Staples", exchange: "NYSE", region: "US" },
{ symbol: "PEP", sector: "Consumer Staples", exchange: "NASDAQ", region: "US" },
{ symbol: "PM", sector: "Consumer Staples", exchange: "NYSE", region: "US" },
// Financials
{ symbol: "JPM", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "V", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "MA", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "BAC", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "GS", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "MS", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "BLK", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "AXP", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "SCHW", sector: "Financials", exchange: "NYSE", region: "US" },
{ symbol: "PYPL", sector: "Financials", exchange: "NASDAQ", region: "US" },
{ symbol: "RY", sector: "Financials", exchange: "NYSE", region: "Canada" },
{ symbol: "HSBC", sector: "Financials", exchange: "NYSE", region: "Europe" },
// Health Care
{ symbol: "UNH", sector: "Health Care", exchange: "NYSE", region: "US" },
{ symbol: "LLY", sector: "Health Care", exchange: "NYSE", region: "US" },
{ symbol: "JNJ", sector: "Health Care", exchange: "NYSE", region: "US" },
{ symbol: "ABBV", sector: "Health Care", exchange: "NYSE", region: "US" },
{ symbol: "MRK", sector: "Health Care", exchange: "NYSE", region: "US" },
{ symbol: "PFE", sector: "Health Care", exchange: "NYSE", region: "US" },
{ symbol: "TMO", sector: "Health Care", exchange: "NYSE", region: "US" },
{ symbol: "AZN", sector: "Health Care", exchange: "NASDAQ", region: "Europe" },
{ symbol: "NVO", sector: "Health Care", exchange: "NYSE", region: "Europe" },
// Energy
{ symbol: "XOM", sector: "Energy", exchange: "NYSE", region: "US" },
{ symbol: "CVX", sector: "Energy", exchange: "NYSE", region: "US" },
{ symbol: "COP", sector: "Energy", exchange: "NYSE", region: "US" },
{ symbol: "SLB", sector: "Energy", exchange: "NYSE", region: "US" },
{ symbol: "BP", sector: "Energy", exchange: "NYSE", region: "Europe" },
// Industrials
{ symbol: "GE", sector: "Industrials", exchange: "NYSE", region: "US" },
{ symbol: "HON", sector: "Industrials", exchange: "NASDAQ", region: "US" },
{ symbol: "CAT", sector: "Industrials", exchange: "NYSE", region: "US" },
{ symbol: "UPS", sector: "Industrials", exchange: "NYSE", region: "US" },
{ symbol: "BA", sector: "Industrials", exchange: "NYSE", region: "US" },
{ symbol: "RTX", sector: "Industrials", exchange: "NYSE", region: "US" },
{ symbol: "LMT", sector: "Industrials", exchange: "NYSE", region: "US" },
// Communication Services
{ symbol: "DIS", sector: "Communication Services", exchange: "NYSE", region: "US" },
{ symbol: "NFLX", sector: "Communication Services", exchange: "NASDAQ", region: "US" },
{ symbol: "CMCSA", sector: "Communication Services", exchange: "NASDAQ", region: "US" },
{ symbol: "T", sector: "Communication Services", exchange: "NYSE", region: "US" },
{ symbol: "VZ", sector: "Communication Services", exchange: "NYSE", region: "US" },
// Utilities / Real Estate / Materials
{ symbol: "NEE", sector: "Utilities", exchange: "NYSE", region: "US" },
{ symbol: "AMT", sector: "Real Estate", exchange: "NYSE", region: "US" },
{ symbol: "PLD", sector: "Real Estate", exchange: "NYSE", region: "US" },
{ symbol: "LIN", sector: "Materials", exchange: "NYSE", region: "US" },
// ETFs (broad exposure)
{ symbol: "SPY", sector: "ETFs", exchange: "NYSE", region: "US" },
{ symbol: "QQQ", sector: "ETFs", exchange: "NASDAQ", region: "US" },
{ symbol: "IWM", sector: "ETFs", exchange: "NYSE", region: "US" },
{ symbol: "DIA", sector: "ETFs", exchange: "NYSE", region: "US" },
{ symbol: "GLD", sector: "ETFs", exchange: "NYSE", region: "US" },
{ symbol: "TLT", sector: "ETFs", exchange: "NASDAQ", region: "US" },
// Crypto exposure
{ symbol: "COIN", sector: "Cryptocurrency", exchange: "NASDAQ", region: "US" },
{ symbol: "MSTR", sector: "Cryptocurrency", exchange: "NASDAQ", region: "US" },
{ symbol: "RIOT", sector: "Cryptocurrency", exchange: "NASDAQ", region: "US" },
// Asia / Other notables
{ symbol: "BABA", sector: "Consumer Discretionary", exchange: "NYSE", region: "Asia" },
{ symbol: "PDD", sector: "Consumer Discretionary", exchange: "NASDAQ", region: "Asia" },
{ symbol: "TM", sector: "Consumer Discretionary", exchange: "NYSE", region: "Asia" },
{ symbol: "SONY", sector: "Consumer Discretionary", exchange: "NYSE", region: "Asia" },
{ symbol: "7203.T", sector: "Consumer Discretionary", exchange: "TYO", region: "Asia" },
{ symbol: "9983.T", sector: "Consumer Discretionary", exchange: "TYO", region: "Asia" }
];
const SECTORS = [
"Information Technology",
"Financials",
"Health Care",
"Consumer Discretionary",
"Energy",
"Communication Services",
"Consumer Staples",
"Industrials",
"Utilities",
"Real Estate",
"Materials",
"Cryptocurrency",
"ETFs",
"Other"
];
const quoteCache = new Map(); // sym -> quote snapshot
let lastFetchTs = 0;
// Small demo seeds so first paint in heatmap mode always looks alive (real quotes replace on refresh)
const DEMO_QUOTES = {
AAPL: { price: 227.12, changePct: 0.87, volume: 41230000, marketCap: 3450000000000, name: "Apple Inc." },
MSFT: { price: 418.5, changePct: -0.32, volume: 18500000, marketCap: 3110000000000, name: "Microsoft" },
NVDA: { price: 118.2, changePct: 2.45, volume: 285000000, marketCap: 2900000000000, name: "NVIDIA" },
GOOGL: { price: 165.8, changePct: 1.05, volume: 22400000, marketCap: 2050000000000, name: "Alphabet" },
META: { price: 502.1, changePct: -1.12, volume: 9800000, marketCap: 1280000000000, name: "Meta Platforms" },
TSLA: { price: 248.0, changePct: 3.8, volume: 112000000, marketCap: 790000000000, name: "Tesla" },
JPM: { price: 198.4, changePct: 0.55, volume: 9100000, marketCap: 570000000000, name: "JPMorgan" },
XOM: { price: 109.2, changePct: -0.9, volume: 15200000, marketCap: 480000000000, name: "Exxon" },
UNH: { price: 512.0, changePct: 0.21, volume: 4200000, marketCap: 470000000000, name: "UnitedHealth" }
};
for (const [s, q] of Object.entries(DEMO_QUOTES)) {
quoteCache.set(s, { ...q, fetched: Date.now() - 60000 });
}
function colorForChangePct(pct) {
if (pct == null || Number.isNaN(pct)) return "#444444";
const v = Math.max(-12, Math.min(12, Number(pct)));
if (v >= 0) {
// green ramp
const t = Math.min(1, v / 7.5);
const r = Math.round(20 + (0 - 20) * t);
const g = Math.round(120 + (255 - 120) * t);
const b = Math.round(80 + (140 - 80) * t);
return "#" + [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
} else {
// red ramp
const t = Math.min(1, -v / 7.5);
const r = Math.round(160 + (210 - 160) * t);
const g = Math.round(35 + (35 - 35) * t);
const b = Math.round(45 + (55 - 45) * t);
return "#" + [r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("");
}
}
function sleep(ms) {
return new Promise((r) => setTimeout(r, ms));
}
async function fetchQuotes(symbols) {
const out = {};
if (!symbols || !symbols.length) return out;
const chunkSize = 40;
for (let i = 0; i < symbols.length; i += chunkSize) {
const chunk = symbols.slice(i, i + chunkSize);
const symStr = chunk.join(",");
const url = `https://query1.finance.yahoo.com/v7/finance/quote?symbols=${encodeURIComponent(symStr)}`;
try {
const res = await fetch(url, {
headers: {
Accept: "application/json",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
Referer: "https://finance.yahoo.com/"
},
cache: "no-store"
});
if (!res.ok) throw new Error("HTTP " + res.status);
const json = await res.json();
const results = json?.quoteResponse?.result || [];
for (const r of results) {
const sym = r.symbol;
const snap = {
price: r.regularMarketPrice ?? null,
change: r.regularMarketChange ?? null,
changePct: r.regularMarketChangePercent ?? null,
volume: r.regularMarketVolume ?? null,
marketCap: r.marketCap ?? null,
name: r.shortName || r.longName || sym,
exchange: r.exchange || r.fullExchangeName || "",
fetched: Date.now()
};
out[sym] = snap;
quoteCache.set(sym, snap);
}
} catch (e) {
console.warn("[VWallMarkets] quote fetch failed for chunk", chunk[0], e?.message || e);
for (const s of chunk) {
if (quoteCache.has(s)) out[s] = quoteCache.get(s);
}
}
if (i + chunkSize < symbols.length) await sleep(240);
}
lastFetchTs = Date.now();
return out;
}
function getCachedQuote(sym) {
return quoteCache.get(sym) || null;
}
function getTickerUniverse(maxCount = 300) {
return TICKER_LIST.slice(0, Math.max(10, maxCount | 0));
}
function clearCaches() {
quoteCache.clear();
lastFetchTs = 0;
}
async function loadTickers(desiredCount = 250, opts = {}) {
const refresh = !!opts.refreshQuotes;
const metas = getTickerUniverse(desiredCount);
const symbols = metas.map((m) => m.symbol);
let quotesMap = {};
if (refresh) {
quotesMap = await fetchQuotes(symbols);
} else {
const missing = symbols.filter((s) => !quoteCache.has(s));
if (missing.length > 0) {
const fresh = await fetchQuotes(missing);
Object.assign(quotesMap, fresh);
}
for (const s of symbols) {
if (!quotesMap[s]) quotesMap[s] = quoteCache.get(s) || {};
}
}
const items = metas.map((meta) => {
const q = quotesMap[meta.symbol] || {};
const price = q.price != null ? Number(q.price) : null;
const ch = q.changePct != null ? Number(q.changePct) : null;
const item = {
symbol: meta.symbol,
mediaType: "ticker",
url: `https://finance.yahoo.com/quote/${meta.symbol}`,
title: `${meta.symbol}${q.name ? " — " + q.name : ""}`,
snippet: `${meta.sector} • ${meta.exchange} • ${meta.region}${price != null ? " • $" + price.toFixed(price > 200 ? 0 : price > 20 ? 1 : 2) : ""}`,
sector: meta.sector,
exchange: meta.exchange,
region: meta.region,
quote: {
price,
changePct: ch,
change: q.change != null ? Number(q.change) : null,
volume: q.volume != null ? Number(q.volume) : null,
marketCap: q.marketCap != null ? Number(q.marketCap) : null,
name: q.name || meta.symbol
}
};
if (global.VWallCatalog && typeof global.VWallCatalog.indexTicker === "function") {
global.VWallCatalog.indexTicker(item);
}
return item;
});
return items;
}
function getLastQuoteTime() {
return lastFetchTs;
}
const api = {
loadTickers,
fetchQuotes,
getTickerUniverse,
clearCaches,
colorForChangePct,
getCachedQuote,
getLastQuoteTime,
SECTORS: SECTORS.slice(),
TICKER_COUNT: TICKER_LIST.length
};
global.VWallMarkets = api;
// Also expose color helper early for scroll-wall + drawer use before full app init
global.colorForChangePct = colorForChangePct;
// For debug / console
global.VWallMarketsList = TICKER_LIST;
})(window);