update pay ui
This commit is contained in:
@@ -2,6 +2,37 @@
|
||||
|
||||
import { logger } from '../utils/logger';
|
||||
|
||||
/**
|
||||
* 格式化股票代码,确保包含交易所后缀
|
||||
* @param {string} code - 股票代码(可能带或不带后缀)
|
||||
* @returns {string} 带后缀的股票代码
|
||||
*/
|
||||
const formatStockCode = (code) => {
|
||||
if (!code) return code;
|
||||
|
||||
// 如果已经有后缀,直接返回
|
||||
if (code.includes('.')) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// 根据股票代码规则添加后缀
|
||||
// 6开头 -> 上海 .SH
|
||||
// 0、3开头 -> 深圳 .SZ
|
||||
// 688开头 -> 科创板(上海).SH
|
||||
// 8开头(北交所)-> .BJ(暂不处理,大部分场景不需要)
|
||||
const firstChar = code.charAt(0);
|
||||
const prefix = code.substring(0, 3);
|
||||
|
||||
if (firstChar === '6' || prefix === '688') {
|
||||
return `${code}.SH`;
|
||||
} else if (firstChar === '0' || firstChar === '3') {
|
||||
return `${code}.SZ`;
|
||||
}
|
||||
|
||||
// 默认返回原代码(可能是指数或其他)
|
||||
return code;
|
||||
};
|
||||
|
||||
const apiRequest = async (url, options = {}) => {
|
||||
const method = options.method || 'GET';
|
||||
const requestData = options.body ? JSON.parse(options.body) : null;
|
||||
@@ -342,8 +373,10 @@ export const stockService = {
|
||||
params.append('event_time', eventTime);
|
||||
}
|
||||
|
||||
const url = `/api/stock/${stockCode}/kline?${params.toString()}`;
|
||||
logger.debug('stockService', '获取K线数据', { stockCode, chartType, eventTime });
|
||||
// 格式化股票代码,确保带交易所后缀
|
||||
const formattedCode = formatStockCode(stockCode);
|
||||
const url = `/api/stock/${formattedCode}/kline?${params.toString()}`;
|
||||
logger.debug('stockService', '获取K线数据', { stockCode: formattedCode, chartType, eventTime });
|
||||
|
||||
const response = await apiRequest(url);
|
||||
|
||||
@@ -371,8 +404,11 @@ export const stockService = {
|
||||
*/
|
||||
getBatchKlineData: async (stockCodes, chartType = 'timeline', eventTime = null, options = {}) => {
|
||||
try {
|
||||
// 格式化所有股票代码,确保带交易所后缀
|
||||
const formattedCodes = stockCodes.map(code => formatStockCode(code));
|
||||
|
||||
const requestBody = {
|
||||
codes: stockCodes,
|
||||
codes: formattedCodes,
|
||||
type: chartType
|
||||
};
|
||||
if (eventTime) {
|
||||
|
||||
Reference in New Issue
Block a user