@barchart/portfolio-api-common 1.0.3 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
-
is = require('@barchart/common-js/lang/is')
|
|
2
|
+
is = require('@barchart/common-js/lang/is'),
|
|
3
|
+
numberFormatter = require('@barchart/common-js/lang/formatter');
|
|
3
4
|
|
|
4
5
|
const TransactionType = require('./../data/TransactionType');
|
|
5
6
|
|
|
@@ -36,7 +37,7 @@ module.exports = (() => {
|
|
|
36
37
|
|
|
37
38
|
positions.map((p) => positionMap[p.position] = p.instrument);
|
|
38
39
|
|
|
39
|
-
return transactions.map((transaction) => {
|
|
40
|
+
return transactions.filter((t) => positionMap[t.position]).map((transaction) => {
|
|
40
41
|
transaction.instrument = positionMap[transaction.position];
|
|
41
42
|
|
|
42
43
|
let formatted = getBasicTransaction(transaction);
|
|
@@ -44,16 +45,26 @@ module.exports = (() => {
|
|
|
44
45
|
if (formatters.has(transaction.type)) {
|
|
45
46
|
const formatterFunction = formatters.get(transaction.type);
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
const formattedTransaction = formatterFunction(transaction);
|
|
49
|
+
|
|
50
|
+
Object.keys(formattedTransaction).map((key) => {
|
|
51
|
+
if (!is.undefined(formattedTransaction[key]) && is.fn(formattedTransaction[key].toFloat)) {
|
|
52
|
+
const precision = transaction.instrument.currency.precision;
|
|
53
|
+
|
|
54
|
+
formattedTransaction[key] = numberFormatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
formatted = Object.assign({}, formatted, formattedTransaction);
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
if (returnType === 'append') {
|
|
51
62
|
transaction.formatted = formatted;
|
|
52
63
|
|
|
53
64
|
return transaction;
|
|
65
|
+
} else {
|
|
66
|
+
return formatted;
|
|
54
67
|
}
|
|
55
|
-
|
|
56
|
-
return formatted;
|
|
57
68
|
});
|
|
58
69
|
}
|
|
59
70
|
|
|
@@ -63,12 +74,18 @@ module.exports = (() => {
|
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
const getBasicTransaction = (t) => {
|
|
66
|
-
|
|
77
|
+
const basic = {
|
|
67
78
|
date: t.date,
|
|
68
79
|
type: t.type,
|
|
69
80
|
sequence: t.sequence,
|
|
70
81
|
instrument: t.instrument
|
|
71
82
|
};
|
|
83
|
+
|
|
84
|
+
if (basic.instrument) {
|
|
85
|
+
delete basic.instrument.id;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return basic;
|
|
72
89
|
};
|
|
73
90
|
|
|
74
91
|
const formatters = new Map();
|
|
@@ -120,14 +137,14 @@ module.exports = (() => {
|
|
|
120
137
|
fee: t.fee,
|
|
121
138
|
total: t.quantity,
|
|
122
139
|
rate: t.dividend.rate
|
|
123
|
-
}
|
|
140
|
+
};
|
|
124
141
|
});
|
|
125
142
|
|
|
126
143
|
formatters.set(TransactionType.DISTRIBUTION_FUND, (t) => {
|
|
127
144
|
return {
|
|
128
145
|
shares: t.snapshot.open.subtract(t.quantity),
|
|
129
146
|
fee: t.fee
|
|
130
|
-
}
|
|
147
|
+
};
|
|
131
148
|
});
|
|
132
149
|
|
|
133
150
|
formatters.set(TransactionType.INCOME, (t) => {
|
|
@@ -52,10 +52,42 @@ module.exports = (() => {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
const complete = new TransactionSchema(SchemaBuilder.withName('Complete')
|
|
55
|
+
.withField('portfolio', DataType.STRING)
|
|
56
|
+
.withField('position', DataType.STRING)
|
|
55
57
|
.withField('sequence', DataType.NUMBER)
|
|
58
|
+
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
56
59
|
.withField('date', DataType.DAY)
|
|
57
|
-
.withField('description', DataType.STRING)
|
|
60
|
+
.withField('description', DataType.STRING, true)
|
|
58
61
|
.withField('amount', DataType.DECIMAL)
|
|
62
|
+
.withField('quantity', DataType.DECIMAL)
|
|
63
|
+
.withField('fee', DataType.DECIMAL, true)
|
|
64
|
+
.withField('reference.position', DataType.STRING, true)
|
|
65
|
+
.withField('reference.sequence', DataType.NUMBER, true)
|
|
66
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
67
|
+
.withField('snapshot.buys', DataType.DECIMAL)
|
|
68
|
+
.withField('snapshot.sells', DataType.DECIMAL)
|
|
69
|
+
.withField('snapshot.gain', DataType.DECIMAL)
|
|
70
|
+
.withField('snapshot.basis', DataType.DECIMAL)
|
|
71
|
+
.withField('snapshot.income', DataType.DECIMAL)
|
|
72
|
+
.withField('snapshot.value', DataType.DECIMAL)
|
|
73
|
+
.withField('legacy.system', DataType.STRING, true)
|
|
74
|
+
.withField('legacy.user', DataType.STRING, true)
|
|
75
|
+
.withField('legacy.portfolio', DataType.STRING)
|
|
76
|
+
.withField('legacy.position', DataType.STRING, true)
|
|
77
|
+
.withField('legacy.transaction', DataType.STRING, true)
|
|
78
|
+
.withField('trade.price', DataType.DECIMAL, true)
|
|
79
|
+
.withField('dividend.rate', DataType.DECIMAL, true)
|
|
80
|
+
.withField('dividend.effective', DataType.DAY, true)
|
|
81
|
+
.withField('dividend.price', DataType.DECIMAL, true)
|
|
82
|
+
.withField('dividend.amount', DataType.DECIMAL, true)
|
|
83
|
+
.withField('dividend.reference', DataType.STRING, true)
|
|
84
|
+
.withField('split.numerator', DataType.DECIMAL, true)
|
|
85
|
+
.withField('split.denominator', DataType.DECIMAL, true)
|
|
86
|
+
.withField('split.effective', DataType.DAY, true)
|
|
87
|
+
.withField('split.reference', DataType.STRING, true)
|
|
88
|
+
.withField('charge.amount', DataType.DECIMAL, true)
|
|
89
|
+
.withField('income.amount', DataType.DECIMAL, true)
|
|
90
|
+
.withField('valuation.value', DataType.DECIMAL, true)
|
|
59
91
|
.schema
|
|
60
92
|
);
|
|
61
93
|
|