// US 交易所股票代码获取脚本 // 数据源: NASDAQ Trader (官方, 每日更新, 免费) const nasdaqUrl = 'https://www.nasdaqtrader.com/dynamic/symdir/nasdaqlisted.txt'; const otherUrl = 'https://www.nasdaqtrader.com/dynamic/symdir/otherlisted.txt'; const stocks = []; // 1. NASDAQ const nasRes = await fetch(nasdaqUrl); const nasCsv = await nasRes.text(); for (const line of nasCsv.split('\n')) { if (!line || line.startsWith('Symbol|')) continue; const cols = line.split('|'); if (cols.length < 8) continue; if (cols[3] === 'Y') continue; const sym = cols[0].trim(); const name = cols[1].trim(); if (!sym || !name) continue; stocks.push({ c: sym, n: name }); } // 2. NYSE / AMEX / ARCA / BATS const othRes = await fetch(otherUrl); const othCsv = await othRes.text(); for (const line of othCsv.split('\n')) { if (!line || line.startsWith('ACT Symbol|')) continue; const cols = line.split('|'); if (cols.length < 8) continue; if (cols[6] === 'Y') continue; const sym = cols[0].trim(); const name = cols[1].trim(); if (!sym || !name) continue; stocks.push({ c: sym, n: name }); } // 去重 const seen = new Set(); const unique = []; for (const s of stocks) { if (!seen.has(s.c)) { seen.add(s.c); unique.push(s); } } // 输出 process.stdout.write(`var s = new Array();\n`); for (let i = 0; i < unique.length; i++) { process.stdout.write(`s[${i}] = { c: "${unique[i].c}", n: "${unique[i].n}" };\n`); } console.error(`\n总计: ${unique.length} 只 US 股票`);