mirror of
https://github.com/zhangxiangliang/stock-api.git
synced 2025-02-02 14:18:44 +08:00
feat: 增加 搜索股票代码中股票代码组去重、增加 获取股票数据组中股票代码组去重
This commit is contained in:
parent
fffaab9d19
commit
0f7d20599f
@ -1,6 +1,6 @@
|
||||
|
||||
// NPM
|
||||
import { uniqBy } from 'lodash';
|
||||
import { uniq } from 'lodash';
|
||||
|
||||
// Stocks
|
||||
import NeteaseStockTransform from "@stocks/netease/transforms/stock";
|
||||
@ -46,6 +46,8 @@ const Netease: StockApi = {
|
||||
* @param codes 股票代码组
|
||||
*/
|
||||
async getStocks(codes: string[]): Promise<Stock[]> {
|
||||
codes = uniq(codes.filter(i => i !== ''));
|
||||
|
||||
// 无股票时返回空数组
|
||||
if (codes.length === 0) {
|
||||
return [];
|
||||
@ -96,9 +98,9 @@ const Netease: StockApi = {
|
||||
}
|
||||
|
||||
return '';
|
||||
}).filter(i => i !== '');
|
||||
});
|
||||
|
||||
return uniqBy(await Netease.getStocks(codes), (code: Stock) => code.name);
|
||||
return await Netease.getStocks(uniq(codes.filter(i => i !== '')));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// NPM
|
||||
import { uniqBy } from 'lodash';
|
||||
import { uniq } from 'lodash';
|
||||
|
||||
// Stocks
|
||||
import SinaStockTransform from "@stocks/sina/transforms/stock";
|
||||
@ -52,6 +52,8 @@ const Sina: StockApi = {
|
||||
* @param codes 股票代码组
|
||||
*/
|
||||
async getStocks(codes: string[]): Promise<Stock[]> {
|
||||
codes = uniq(codes.filter(i => i !== ''));
|
||||
|
||||
// 无股票时返回空数组
|
||||
if (codes.length === 0) {
|
||||
return [];
|
||||
@ -123,7 +125,7 @@ const Sina: StockApi = {
|
||||
}
|
||||
}
|
||||
|
||||
return uniqBy(await Sina.getStocks(codes), (code: Stock) => code.name);
|
||||
return await Sina.getStocks(uniq(codes.filter(i => i !== '')));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
// NPM
|
||||
import { uniq } from "lodash";
|
||||
|
||||
// Stocks
|
||||
import TencentStockTransform from "@stocks/tencent/transforms/stock";
|
||||
import TencentCommonCodeTransform from "@stocks/tencent/transforms/common-code";
|
||||
@ -48,6 +51,8 @@ const Tencent: StockApi = {
|
||||
* @param codes 股票代码组
|
||||
*/
|
||||
async getStocks(codes: string[]): Promise<Stock[]> {
|
||||
codes = uniq(codes.filter(i => i !== ''));
|
||||
|
||||
// 无股票时返回空数组
|
||||
if (codes.length === 0) {
|
||||
return [];
|
||||
@ -103,9 +108,9 @@ const Tencent: StockApi = {
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}).filter(code => code !== '');
|
||||
});
|
||||
|
||||
return await Tencent.getStocks(codes);
|
||||
return await Tencent.getStocks(uniq(codes.filter(i => i !== '')));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,8 @@ const Xueqiu: StockApi & { getToken(): Promise<string> } = {
|
||||
* @param codes 股票代码组
|
||||
*/
|
||||
async getStocks(codes: string[]): Promise<Stock[]> {
|
||||
codes = uniq(codes.filter(i => i !== ''));
|
||||
|
||||
// 无股票时返回空数组
|
||||
if (codes.length === 0) {
|
||||
return [];
|
||||
@ -142,7 +144,7 @@ const Xueqiu: StockApi & { getToken(): Promise<string> } = {
|
||||
codes = [...codes, COMMON_HK + code, COMMON_US + code];
|
||||
}
|
||||
|
||||
return await Xueqiu.getStocks(uniq(codes));
|
||||
return await Xueqiu.getStocks(uniq(codes.filter(i => i !== '')));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user