fix(api): 升级行情解析器正则规则,兼容 BRK.B 等包含特殊字符的股票代码

This commit is contained in:
2026-05-01 23:35:31 +08:00
parent f059aeb08f
commit 9ff48f37d1
3 changed files with 10 additions and 4 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ import { revalidatePath } from 'next/cache';
import { onConflictDoUpdate } from 'drizzle-orm/pg-core';
function getTencentSymbol(asset: { symbol: string; exchange: string | null }): string {
const cleanSymbol = asset.symbol.trim().toUpperCase().replace(/[^0-9A-Z]/g, '');
const cleanSymbol = asset.symbol.trim().toUpperCase().replace(/[^0-9A-Z.\-]/g, '');
switch (asset.exchange) {
case 'SSE': return 'sh' + cleanSymbol;
@@ -36,7 +36,7 @@ export async function syncAllMarketPrices() {
try {
if (asset.type === 'STOCK') {
const tCode = getTencentSymbol(asset);
const response = await fetch(`https://qt.gtimg.cn/q=${tCode}`, { cache: 'no-store' });
const response = await fetch(`https://sqt.gtimg.cn/q=${tCode}`, { cache: 'no-store' });
const arrayBuffer = await response.arrayBuffer();
const decoder = new TextDecoder('gbk');
const text = decoder.decode(arrayBuffer);