@barchart/portfolio-api-common 1.0.2 → 1.0.7
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,7 +45,17 @@ 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') {
|
|
@@ -63,12 +74,16 @@ 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
|
+
delete basic.instrument.id;
|
|
85
|
+
|
|
86
|
+
return instrument;
|
|
72
87
|
};
|
|
73
88
|
|
|
74
89
|
const formatters = new Map();
|
|
@@ -120,14 +135,14 @@ module.exports = (() => {
|
|
|
120
135
|
fee: t.fee,
|
|
121
136
|
total: t.quantity,
|
|
122
137
|
rate: t.dividend.rate
|
|
123
|
-
}
|
|
138
|
+
};
|
|
124
139
|
});
|
|
125
140
|
|
|
126
141
|
formatters.set(TransactionType.DISTRIBUTION_FUND, (t) => {
|
|
127
142
|
return {
|
|
128
143
|
shares: t.snapshot.open.subtract(t.quantity),
|
|
129
144
|
fee: t.fee
|
|
130
|
-
}
|
|
145
|
+
};
|
|
131
146
|
});
|
|
132
147
|
|
|
133
148
|
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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barchart/portfolio-api-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Common classes used by the Portfolio system",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bryan Ingle",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@barchart/common-js": "3.2.
|
|
12
|
+
"@barchart/common-js": "~3.2.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"babel-core": "^6.26.0",
|