fix(api): 修复 portfolio 计算中漏写 new Big() 包装导致的 TypeError
This commit is contained in:
parent
b9186d4699
commit
746be06840
@ -54,7 +54,7 @@ function calculateCnyValueFromPrice(
|
||||
|
||||
const directRate = getRate(rateMap, baseCurrency, 'CNY');
|
||||
if (directRate) {
|
||||
return quantity.times(price).times(directRate);
|
||||
return quantity.times(price).times(new Big(directRate));
|
||||
}
|
||||
|
||||
const usdToCny = getRate(rateMap, 'USD', 'CNY');
|
||||
@ -64,7 +64,7 @@ function calculateCnyValueFromPrice(
|
||||
|
||||
const usdRate = getRate(rateMap, baseCurrency, 'USD');
|
||||
if (usdRate) {
|
||||
return quantity.times(price).times(usdRate).times(usdToCny);
|
||||
return quantity.times(price).times(new Big(usdRate)).times(new Big(usdToCny));
|
||||
}
|
||||
|
||||
return new Big('0');
|
||||
@ -116,16 +116,16 @@ export async function getPortfolioPositions(): Promise<Position[]> {
|
||||
const holding = holdings.get(tx.assetId)!;
|
||||
|
||||
if (tx.txType === 'BUY') {
|
||||
holding.quantity = holding.quantity.plus(tx.quantity);
|
||||
const costPerUnit = tx.quantity.times(tx.price);
|
||||
const costCny = costPerUnit.times(tx.exchangeRate || '1');
|
||||
holding.quantity = holding.quantity.plus(new Big(tx.quantity));
|
||||
const costPerUnit = new Big(tx.quantity).times(new Big(tx.price));
|
||||
const costCny = costPerUnit.times(new Big(tx.exchangeRate || '1'));
|
||||
holding.totalCostCny = holding.totalCostCny.plus(costCny);
|
||||
} else if (tx.txType === 'SELL') {
|
||||
holding.quantity = holding.quantity.minus(tx.quantity);
|
||||
holding.quantity = holding.quantity.minus(new Big(tx.quantity));
|
||||
} else if (tx.txType === 'AIRDROP') {
|
||||
holding.quantity = holding.quantity.plus(tx.quantity);
|
||||
holding.quantity = holding.quantity.plus(new Big(tx.quantity));
|
||||
} else if (tx.txType === 'DIVIDEND') {
|
||||
holding.quantity = holding.quantity.plus(tx.quantity);
|
||||
holding.quantity = holding.quantity.plus(new Big(tx.quantity));
|
||||
}
|
||||
|
||||
if (tx.assetLatestPrice) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user