Skip to content

Commit

Permalink
Merge pull request #487 from enzheng128/master
Browse files Browse the repository at this point in the history
fix: 修正腾讯自选股港股接口数据延迟问题
  • Loading branch information
giscafer authored Oct 14, 2024
2 parents 0f11b4a + 45acd46 commit d61c6e8
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/shared/tencentStock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,38 @@ export const getTencentHKStockData = async (codes: string[]) => {
// Log.info('before getStockData codes: ', codes);
const stockDataResponse = await Axios.get(stockDataUrl, {
responseType: 'arraybuffer',
params: {
q: codes.map((code) => `r_${code}`).join(','),
fmt: 'json',
},
transformResponse: [
(data) => {
const body = decode(data, 'GB18030');
return body;
const body = decode(data, 'GBK');
return JSON.parse(body);
},
],
params: {
q: codes.join(','),
},
});
// Log.info('stockDataResponse: ', stockDataResponse.data);
const stockDataList = (stockDataResponse.data || '').split(';').slice(0,codes.length).map((stockItemStr: string) => {
const stockItemArr = stockItemStr.split('~');
return {
code: 'hk' + stockItemArr[2],
name: stockItemArr[1],
price: stockItemArr[3],
yestclose: stockItemArr[4],
open: stockItemArr[5],
high: stockItemArr[33],
low: stockItemArr[34],
volume: stockItemArr[36],
amount: stockItemArr[37],
buy1: stockItemArr[9],
sell1: stockItemArr[19],
time: stockItemArr[30],
};
});

const stockDataList = codes
.filter((code) => stockDataResponse.data[`r_${code}`])
.map((code: string) => {
const rCode = `r_${code}`;
const stockItemArr = stockDataResponse.data[rCode];
return {
code,
name: stockItemArr[1],
price: stockItemArr[3],
yestclose: stockItemArr[4],
open: stockItemArr[5],
high: stockItemArr[33],
low: stockItemArr[34],
volume: stockItemArr[36],
amount: stockItemArr[37],
buy1: stockItemArr[9],
sell1: stockItemArr[19],
time: stockItemArr[30],
};
});
// Log.info('stockDataList: ', stockDataList, codes);
return stockDataList;
};

0 comments on commit d61c6e8

Please sign in to comment.