refactor(marketService): 移除 apiRequest 包装函数,统一使用 axios.get
- getMarketSummary, getTradeData, getFundingData, getPledgeData, getRiseAnalysis 改为直接使用 axios.get - 删除 apiRequest<T> 包装函数 - 代码风格与 getBigDealData, getUnusualData, getMinuteData 保持一致 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -23,19 +23,6 @@ interface ApiResponse<T> {
|
|||||||
message?: string;
|
message?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用 API 请求函数
|
|
||||||
*/
|
|
||||||
const apiRequest = async <T>(url: string): Promise<ApiResponse<T>> => {
|
|
||||||
try {
|
|
||||||
const { data } = await axios.get<ApiResponse<T>>(url);
|
|
||||||
return data;
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('marketService', 'apiRequest', error, { url });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 市场数据服务
|
* 市场数据服务
|
||||||
*/
|
*/
|
||||||
@@ -45,7 +32,8 @@ export const marketService = {
|
|||||||
* @param stockCode 股票代码
|
* @param stockCode 股票代码
|
||||||
*/
|
*/
|
||||||
async getMarketSummary(stockCode: string): Promise<ApiResponse<MarketSummary>> {
|
async getMarketSummary(stockCode: string): Promise<ApiResponse<MarketSummary>> {
|
||||||
return apiRequest<MarketSummary>(`/api/market/summary/${stockCode}`);
|
const { data } = await axios.get<ApiResponse<MarketSummary>>(`/api/market/summary/${stockCode}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +42,8 @@ export const marketService = {
|
|||||||
* @param days 天数,默认 60 天
|
* @param days 天数,默认 60 天
|
||||||
*/
|
*/
|
||||||
async getTradeData(stockCode: string, days: number = 60): Promise<ApiResponse<TradeDayData[]>> {
|
async getTradeData(stockCode: string, days: number = 60): Promise<ApiResponse<TradeDayData[]>> {
|
||||||
return apiRequest<TradeDayData[]>(`/api/market/trade/${stockCode}?days=${days}`);
|
const { data } = await axios.get<ApiResponse<TradeDayData[]>>(`/api/market/trade/${stockCode}?days=${days}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +52,8 @@ export const marketService = {
|
|||||||
* @param days 天数,默认 30 天
|
* @param days 天数,默认 30 天
|
||||||
*/
|
*/
|
||||||
async getFundingData(stockCode: string, days: number = 30): Promise<ApiResponse<FundingDayData[]>> {
|
async getFundingData(stockCode: string, days: number = 30): Promise<ApiResponse<FundingDayData[]>> {
|
||||||
return apiRequest<FundingDayData[]>(`/api/market/funding/${stockCode}?days=${days}`);
|
const { data } = await axios.get<ApiResponse<FundingDayData[]>>(`/api/market/funding/${stockCode}?days=${days}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +81,8 @@ export const marketService = {
|
|||||||
* @param stockCode 股票代码
|
* @param stockCode 股票代码
|
||||||
*/
|
*/
|
||||||
async getPledgeData(stockCode: string): Promise<ApiResponse<PledgeData[]>> {
|
async getPledgeData(stockCode: string): Promise<ApiResponse<PledgeData[]>> {
|
||||||
return apiRequest<PledgeData[]>(`/api/market/pledge/${stockCode}`);
|
const { data } = await axios.get<ApiResponse<PledgeData[]>>(`/api/market/pledge/${stockCode}`);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,7 +100,8 @@ export const marketService = {
|
|||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
url += `?start_date=${startDate}&end_date=${endDate}`;
|
url += `?start_date=${startDate}&end_date=${endDate}`;
|
||||||
}
|
}
|
||||||
return apiRequest<RiseAnalysis[]>(url);
|
const { data } = await axios.get<ApiResponse<RiseAnalysis[]>>(url);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user