这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/1-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1802,9 +1802,10 @@ describe('API', () => {
'symbol',
'buyingWeightedPrice',
'buyingAmount',
'cost',
'sellingWeightedPrice',
'sellingAmount',
'cumulativeWeightedPrice',
'sale',
'cumulativeAmount',
'firstTradeMts',
'lastTradeMts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = (
wStream.setMaxListeners(50)

const headerStringifier = stringify(
{ columns: ['empty', 'buy', 'empty', 'sell', 'empty', 'cumulative', 'empty'] }
{ columns: ['empty', 'buy', 'empty', 'empty', 'sell', 'empty', 'empty', 'cumulative', 'empty'] }
)
const resStringifier = stringify({
header: true,
Expand Down
3 changes: 2 additions & 1 deletion workers/loc.api/generate-csv/csv.job.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,9 +1061,10 @@ class CsvJobData {
symbol: 'PAIR',
buyingWeightedPrice: 'WEIGHTED PRICE',
buyingAmount: 'AMOUNT',
cost: 'COST',
sellingWeightedPrice: 'WEIGHTED PRICE',
sellingAmount: 'AMOUNT',
cumulativeWeightedPrice: 'WEIGHTED PRICE',
sale: 'SALE',
cumulativeAmount: 'AMOUNT',
firstTradeMts: 'First Trade',
lastTradeMts: 'Last Trade'
Expand Down
36 changes: 19 additions & 17 deletions workers/loc.api/weighted.averages.report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ class WeightedAveragesReport {

const {
tradeCount,
sumBuyingSpent = 0,
sumBuyingAmount = 0,
sumSellingSpent = 0,
sumSellingAmount = 0,
buyingWeightedPrice = 0,
sellingWeightedPrice = 0,
Expand All @@ -128,17 +126,17 @@ class WeightedAveragesReport {
}

const cumulativeAmount = sumBuyingAmount + sumSellingAmount
const cumulativeWeightedPrice = cumulativeAmount === 0
? 0
: (sumBuyingSpent + sumSellingSpent) / cumulativeAmount
const cost = buyingWeightedPrice * sumBuyingAmount
const sale = sellingWeightedPrice * sumSellingAmount

weightedAverages.push({
symbol,
buyingWeightedPrice,
buyingAmount: sumBuyingAmount,
cost,
sellingWeightedPrice,
sellingAmount: sumSellingAmount,
cumulativeWeightedPrice,
sale,
cumulativeAmount,
firstTradeMts,
lastTradeMts
Expand Down Expand Up @@ -312,6 +310,13 @@ class WeightedAveragesReport {
? _sumSellingAmount + execAmount
: _sumSellingAmount

const buyingWeightedPrice = sumBuyingAmount === 0
? 0
: sumBuyingSpent / sumBuyingAmount
const sellingWeightedPrice = sumSellingAmount === 0
? 0
: sumSellingSpent / sumSellingAmount

symbResMap.set(symbol, {
sumSpent,
sumAmount,
Expand All @@ -320,17 +325,12 @@ class WeightedAveragesReport {
sumSellingSpent,
sumSellingAmount,

buyingWeightedPrice: sumBuyingAmount === 0
? 0
: sumBuyingSpent / sumBuyingAmount,
buyingWeightedPrice,
buyingAmount: sumBuyingAmount,
sellingWeightedPrice: sumSellingAmount === 0
? 0
: sumSellingSpent / sumSellingAmount,
cost: buyingWeightedPrice * sumBuyingAmount,
sellingWeightedPrice,
sellingAmount: sumSellingAmount,
cumulativeWeightedPrice: sumAmount === 0
? 0
: sumSpent / sumAmount,
sale: sellingWeightedPrice * sumSellingAmount,
cumulativeAmount: sumAmount
})
}
Expand All @@ -339,9 +339,10 @@ class WeightedAveragesReport {
const {
buyingWeightedPrice = 0,
buyingAmount = 0,
cost = 0,
sellingWeightedPrice = 0,
sellingAmount = 0,
cumulativeWeightedPrice = 0,
sale = 0,
cumulativeAmount = 0
} = val ?? {}

Expand All @@ -355,9 +356,10 @@ class WeightedAveragesReport {
symbol,
buyingWeightedPrice,
buyingAmount,
cost,
sellingWeightedPrice,
sellingAmount,
cumulativeWeightedPrice,
sale,
cumulativeAmount,
firstTradeMts,
lastTradeMts
Expand Down