feat(portfolio): CSV 导出增加市场分类维度,支持 A股/美股/港股/虚拟币精准识别
This commit is contained in:
+14
-1
@@ -66,11 +66,24 @@ function exportToCSV(positions: any[]) {
|
||||
return str;
|
||||
};
|
||||
|
||||
const headers = ["资产名称", "代码", "持仓量", "成本价", "现价", "总市值", "浮动盈亏", "累计盈亏"];
|
||||
const getMarketName = (item: any): string => {
|
||||
if (item.type === 'CRYPTO' || item.assetType === 'CRYPTO') return '虚拟币';
|
||||
const currency = (item.baseCurrency || '').toUpperCase();
|
||||
if (currency === 'USD') return '美股';
|
||||
if (currency === 'HKD') return '港股';
|
||||
if (currency === 'CNY' || currency === 'RMB') return 'A股';
|
||||
const symbol = (item.symbol || '').toLowerCase();
|
||||
if (/^\d{5}$/.test(symbol)) return '港股';
|
||||
if (/^(60|00|30)\d{4}$/.test(symbol) || symbol.startsWith('sh') || symbol.startsWith('sz')) return 'A股';
|
||||
return '其他市场';
|
||||
};
|
||||
|
||||
const headers = ["资产名称", "代码", "市场", "持仓量", "成本价", "现价", "总市值", "浮动盈亏", "累计盈亏"];
|
||||
|
||||
const rows = positions.map(item => [
|
||||
item.name || item.symbol,
|
||||
item.symbol,
|
||||
getMarketName(item),
|
||||
item.quantity || '0',
|
||||
stripTrailingZeros(new Big(item.avgCostNative || '0').toFixed(2)),
|
||||
stripTrailingZeros(item.latestPrice || '0'),
|
||||
|
||||
Reference in New Issue
Block a user