@barchart/portfolio-api-common 1.0.24 → 1.0.28
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.
- package/lib/formatters/PositionSummaryFormatter.js +71 -0
- package/lib/serialization/PortfolioSchema.js +19 -11
- package/lib/serialization/PositionSchema.js +44 -2
- package/lib/serialization/PositionSummarySchema.js +127 -0
- package/lib/serialization/TransactionSchema.js +174 -55
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const array = require('@barchart/common-js/lang/array')
|
|
2
|
+
assert = require('@barchart/common-js/lang/assert'),
|
|
3
|
+
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
4
|
+
formatter = require('@barchart/common-js/lang/formatter');
|
|
5
|
+
|
|
6
|
+
module.exports = (() => {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Formats Position Summary records into groups based on instrument type
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
class PositionSummaryFormatter{
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The formatter
|
|
16
|
+
*
|
|
17
|
+
* @param {Array} summaries
|
|
18
|
+
* @returns {Object}
|
|
19
|
+
*/
|
|
20
|
+
static format(summaries) {
|
|
21
|
+
assert.argumentIsRequired(summaries, 'summaries', Object);
|
|
22
|
+
|
|
23
|
+
const summaryGroups = array.groupBy(summaries, summary => summary.instrument.type.code);
|
|
24
|
+
|
|
25
|
+
const total = {
|
|
26
|
+
start: Decimal.ZERO,
|
|
27
|
+
change: Decimal.ZERO,
|
|
28
|
+
end: Decimal.ZERO
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const formattedSummaryGroups = Object.keys(summaryGroups).map((group) => {
|
|
32
|
+
const positions = summaryGroups[group];
|
|
33
|
+
|
|
34
|
+
let start = Decimal.ZERO;
|
|
35
|
+
let end = Decimal.ZERO;
|
|
36
|
+
|
|
37
|
+
positions.map((position) => {
|
|
38
|
+
start = start.add(position.start.value);
|
|
39
|
+
end = end.add(position.end.value);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const change = end.subtract(start);
|
|
43
|
+
|
|
44
|
+
total.start = total.start.add(start);
|
|
45
|
+
total.change = total.change.add(change);
|
|
46
|
+
total.end = total.end.add(end);
|
|
47
|
+
|
|
48
|
+
return summaryGroups[group] = {
|
|
49
|
+
name: group,
|
|
50
|
+
start: formatNumber(start.toFloat()),
|
|
51
|
+
end: formatNumber(end.toFloat()),
|
|
52
|
+
change: formatNumber(change.toFloat())
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
Object.keys(total).map(key => total[key] = formatNumber(total[key].toFloat()));
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
groups: formattedSummaryGroups,
|
|
60
|
+
total
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const formatNumber = (float) => {
|
|
66
|
+
return formatter.numberToString(float, 2, ',');
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return PositionSummaryFormatter;
|
|
70
|
+
|
|
71
|
+
})();
|
|
@@ -13,7 +13,7 @@ module.exports = (() => {
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* The schemas which can be used to represent
|
|
16
|
+
* The schemas which can be used to represent portfolio objects.
|
|
17
17
|
*
|
|
18
18
|
* @public
|
|
19
19
|
* @extends {Enum}
|
|
@@ -26,6 +26,8 @@ module.exports = (() => {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
+
* The actual {@link Schema}.
|
|
30
|
+
*
|
|
29
31
|
* @public
|
|
30
32
|
* @returns {Schema}
|
|
31
33
|
*/
|
|
@@ -34,15 +36,19 @@ module.exports = (() => {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|
|
39
|
+
* The complete portfolio schema.
|
|
40
|
+
*
|
|
37
41
|
* @static
|
|
38
42
|
* @public
|
|
39
43
|
* @returns {PortfolioSchema}
|
|
40
44
|
*/
|
|
41
|
-
static get
|
|
42
|
-
return
|
|
45
|
+
static get COMPLETE() {
|
|
46
|
+
return complete;
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
50
|
+
* Portfolio data transmitted to the client, omitting some system data.
|
|
51
|
+
*
|
|
46
52
|
* @static
|
|
47
53
|
* @public
|
|
48
54
|
* @returns {PortfolioSchema}
|
|
@@ -52,15 +58,19 @@ module.exports = (() => {
|
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
/**
|
|
61
|
+
* Data required to create a portfolio.
|
|
62
|
+
*
|
|
55
63
|
* @static
|
|
56
64
|
* @public
|
|
57
65
|
* @returns {PortfolioSchema}
|
|
58
66
|
*/
|
|
59
|
-
static get
|
|
60
|
-
return
|
|
67
|
+
static get CREATE() {
|
|
68
|
+
return create;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
/**
|
|
72
|
+
* Data required to update a portfolio.
|
|
73
|
+
*
|
|
64
74
|
* @static
|
|
65
75
|
* @public
|
|
66
76
|
* @returns {PortfolioSchema}
|
|
@@ -119,20 +129,18 @@ module.exports = (() => {
|
|
|
119
129
|
.withField('name', DataType.STRING)
|
|
120
130
|
.withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
|
|
121
131
|
.withField('dates.cash', DataType.DAY, true)
|
|
122
|
-
.withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
|
|
132
|
+
.withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
123
133
|
.withField('defaults.reinvest', DataType.BOOLEAN, true)
|
|
124
|
-
.withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
|
|
134
|
+
.withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'), true)
|
|
125
135
|
.withField('miscellany', DataType.AD_HOC, true)
|
|
126
136
|
.schema
|
|
127
137
|
);
|
|
128
138
|
|
|
129
139
|
const update = new PortfolioSchema(SchemaBuilder.withName('update')
|
|
130
140
|
.withField('name', DataType.STRING)
|
|
131
|
-
.withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
|
|
132
|
-
.withField('
|
|
133
|
-
.withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
|
|
141
|
+
.withField('timezone', DataType.forEnum(Timezones, 'Timezone'), true)
|
|
142
|
+
.withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
134
143
|
.withField('defaults.reinvest', DataType.BOOLEAN, true)
|
|
135
|
-
.withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
|
|
136
144
|
.withField('miscellany', DataType.AD_HOC, true)
|
|
137
145
|
.schema
|
|
138
146
|
);
|
|
@@ -12,7 +12,7 @@ module.exports = (() => {
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* The schemas which can be used to represent
|
|
15
|
+
* The schemas which can be used to represent position objects.
|
|
16
16
|
*
|
|
17
17
|
* @public
|
|
18
18
|
* @extends {Enum}
|
|
@@ -25,6 +25,8 @@ module.exports = (() => {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
+
* The actual {@link Schema}.
|
|
29
|
+
*
|
|
28
30
|
* @public
|
|
29
31
|
* @returns {Schema}
|
|
30
32
|
*/
|
|
@@ -33,6 +35,8 @@ module.exports = (() => {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/**
|
|
38
|
+
* The complete position schema.
|
|
39
|
+
*
|
|
36
40
|
* @static
|
|
37
41
|
* @public
|
|
38
42
|
* @returns {PositionSchema}
|
|
@@ -41,12 +45,23 @@ module.exports = (() => {
|
|
|
41
45
|
return complete;
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Position data transmitted to the client, omitting some system data.
|
|
50
|
+
*
|
|
51
|
+
* @static
|
|
52
|
+
* @public
|
|
53
|
+
* @returns {PositionSchema}
|
|
54
|
+
*/
|
|
55
|
+
static get CLIENT() {
|
|
56
|
+
return client;
|
|
57
|
+
}
|
|
58
|
+
|
|
44
59
|
toString() {
|
|
45
60
|
return '[PositionSchema]';
|
|
46
61
|
}
|
|
47
62
|
}
|
|
48
63
|
|
|
49
|
-
const complete = new PositionSchema(SchemaBuilder.withName('
|
|
64
|
+
const complete = new PositionSchema(SchemaBuilder.withName('complete')
|
|
50
65
|
.withField('user', DataType.STRING)
|
|
51
66
|
.withField('portfolio', DataType.STRING)
|
|
52
67
|
.withField('sequence', DataType.NUMBER)
|
|
@@ -78,5 +93,32 @@ module.exports = (() => {
|
|
|
78
93
|
.schema
|
|
79
94
|
);
|
|
80
95
|
|
|
96
|
+
const client = new PositionSchema(SchemaBuilder.withName('client')
|
|
97
|
+
.withField('user', DataType.STRING)
|
|
98
|
+
.withField('portfolio', DataType.STRING)
|
|
99
|
+
.withField('sequence', DataType.NUMBER)
|
|
100
|
+
.withField('instrument.id', DataType.STRING)
|
|
101
|
+
.withField('instrument.name', DataType.STRING)
|
|
102
|
+
.withField('instrument.type', DataType.STRING)
|
|
103
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
104
|
+
.withField('instrument.delist', DataType.DAY, true)
|
|
105
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
106
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
107
|
+
.withField('position', DataType.STRING)
|
|
108
|
+
.withField('open', DataType.BOOLEAN, true)
|
|
109
|
+
.withField('transaction', DataType.NUMBER)
|
|
110
|
+
.withField('valuation', DataType.forEnum(ValuationType, 'ValuationType'))
|
|
111
|
+
.withField('reinvest', DataType.BOOLEAN)
|
|
112
|
+
.withField('snapshot.date', DataType.DAY)
|
|
113
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
114
|
+
.withField('snapshot.buys', DataType.DECIMAL)
|
|
115
|
+
.withField('snapshot.sells', DataType.DECIMAL)
|
|
116
|
+
.withField('snapshot.gain', DataType.DECIMAL)
|
|
117
|
+
.withField('snapshot.basis', DataType.DECIMAL)
|
|
118
|
+
.withField('snapshot.income', DataType.DECIMAL)
|
|
119
|
+
.withField('snapshot.value', DataType.DECIMAL)
|
|
120
|
+
.schema
|
|
121
|
+
);
|
|
122
|
+
|
|
81
123
|
return PositionSchema;
|
|
82
124
|
})();
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
|
+
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
|
+
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
+
is = require('@barchart/common-js/lang/is'),
|
|
6
|
+
Schema = require('@barchart/common-js/serialization/json/Schema'),
|
|
7
|
+
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
|
|
8
|
+
|
|
9
|
+
const PositionSummaryFrame = require('./../data/PositionSummaryFrame');
|
|
10
|
+
|
|
11
|
+
module.exports = (() => {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The schemas which can be used to represent position summary objects.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
* @extends {Enum}
|
|
19
|
+
*/
|
|
20
|
+
class PositionSummarySchema extends Enum {
|
|
21
|
+
constructor(schema) {
|
|
22
|
+
super(schema.name, schema.name);
|
|
23
|
+
|
|
24
|
+
this._schema = schema;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The actual {@link Schema}.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
* @returns {Schema}
|
|
32
|
+
*/
|
|
33
|
+
get schema() {
|
|
34
|
+
return this._schema;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The complete position summary schema.
|
|
39
|
+
*
|
|
40
|
+
* @static
|
|
41
|
+
* @public
|
|
42
|
+
* @returns {PositionSummarySchema}
|
|
43
|
+
*/
|
|
44
|
+
static get COMPLETE() {
|
|
45
|
+
return complete;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Position summary data transmitted to the client, omitting some system data.
|
|
50
|
+
*
|
|
51
|
+
* @static
|
|
52
|
+
* @public
|
|
53
|
+
* @returns {PositionSummarySchema}
|
|
54
|
+
*/
|
|
55
|
+
static get CLIENT() {
|
|
56
|
+
return client;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
toString() {
|
|
60
|
+
return '[PositionSummarySchema]';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const complete = new PositionSummarySchema(SchemaBuilder.withName('complete')
|
|
65
|
+
.withField('user', DataType.STRING)
|
|
66
|
+
.withField('portfolio', DataType.STRING)
|
|
67
|
+
.withField('position', DataType.STRING)
|
|
68
|
+
.withField('instrument.id', DataType.STRING)
|
|
69
|
+
.withField('instrument.name', DataType.STRING)
|
|
70
|
+
.withField('instrument.type', DataType.STRING)
|
|
71
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
72
|
+
.withField('instrument.delist', DataType.DAY, true)
|
|
73
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
74
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
75
|
+
.withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
|
|
76
|
+
.withField('start.date', DataType.DAY)
|
|
77
|
+
.withField('start.sequence', DataType.NUMBER)
|
|
78
|
+
.withField('start.open', DataType.DECIMAL)
|
|
79
|
+
.withField('start.basis', DataType.DECIMAL)
|
|
80
|
+
.withField('start.value', DataType.DECIMAL)
|
|
81
|
+
.withField('end.date', DataType.DAY)
|
|
82
|
+
.withField('end.sequence', DataType.NUMBER)
|
|
83
|
+
.withField('end.open', DataType.DECIMAL)
|
|
84
|
+
.withField('end.basis', DataType.DECIMAL)
|
|
85
|
+
.withField('end.value', DataType.DECIMAL)
|
|
86
|
+
.withField('period.buys', DataType.DECIMAL)
|
|
87
|
+
.withField('period.sells', DataType.DECIMAL)
|
|
88
|
+
.withField('period.income', DataType.DECIMAL)
|
|
89
|
+
.withField('period.realized', DataType.DECIMAL)
|
|
90
|
+
.withField('period.unrealized', DataType.DECIMAL)
|
|
91
|
+
.withField('system.sequence', DataType.NUMBER)
|
|
92
|
+
.withField('system.version', DataType.STRING)
|
|
93
|
+
.schema
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const client = new PositionSummarySchema(SchemaBuilder.withName('client')
|
|
97
|
+
.withField('user', DataType.STRING)
|
|
98
|
+
.withField('portfolio', DataType.STRING)
|
|
99
|
+
.withField('position', DataType.STRING)
|
|
100
|
+
.withField('instrument.id', DataType.STRING)
|
|
101
|
+
.withField('instrument.name', DataType.STRING)
|
|
102
|
+
.withField('instrument.type', DataType.STRING)
|
|
103
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
104
|
+
.withField('instrument.delist', DataType.DAY, true)
|
|
105
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
106
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
107
|
+
.withField('frame', DataType.forEnum(PositionSummaryFrame, 'PositionSummaryFrame'))
|
|
108
|
+
.withField('start.date', DataType.DAY)
|
|
109
|
+
.withField('start.sequence', DataType.NUMBER)
|
|
110
|
+
.withField('start.open', DataType.DECIMAL)
|
|
111
|
+
.withField('start.basis', DataType.DECIMAL)
|
|
112
|
+
.withField('start.value', DataType.DECIMAL)
|
|
113
|
+
.withField('end.date', DataType.DAY)
|
|
114
|
+
.withField('end.sequence', DataType.NUMBER)
|
|
115
|
+
.withField('end.open', DataType.DECIMAL)
|
|
116
|
+
.withField('end.basis', DataType.DECIMAL)
|
|
117
|
+
.withField('end.value', DataType.DECIMAL)
|
|
118
|
+
.withField('period.buys', DataType.DECIMAL)
|
|
119
|
+
.withField('period.sells', DataType.DECIMAL)
|
|
120
|
+
.withField('period.income', DataType.DECIMAL)
|
|
121
|
+
.withField('period.realized', DataType.DECIMAL)
|
|
122
|
+
.withField('period.unrealized', DataType.DECIMAL)
|
|
123
|
+
.schema
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return PositionSummarySchema;
|
|
127
|
+
})();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
is = require('@barchart/common-js/lang/is'),
|
|
2
3
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
4
|
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
5
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
@@ -11,7 +12,7 @@ module.exports = (() => {
|
|
|
11
12
|
'use strict';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
* The schemas which can be used to represent
|
|
15
|
+
* The schemas which can be used to represent transaction objects.
|
|
15
16
|
*
|
|
16
17
|
* @public
|
|
17
18
|
* @extends {Enum}
|
|
@@ -24,6 +25,8 @@ module.exports = (() => {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/**
|
|
28
|
+
* The actual {@link Schema}.
|
|
29
|
+
*
|
|
27
30
|
* @public
|
|
28
31
|
* @returns {Schema}
|
|
29
32
|
*/
|
|
@@ -31,10 +34,57 @@ module.exports = (() => {
|
|
|
31
34
|
return this._schema;
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Returns the appropriate schema for creating a transaction of the
|
|
39
|
+
* supplied type.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
* @static
|
|
43
|
+
* @param {String|TransactionType} transactionType
|
|
44
|
+
* @returns {TransactionSchema|null}
|
|
45
|
+
*/
|
|
46
|
+
static forCreate(transactionType) {
|
|
47
|
+
let code;
|
|
48
|
+
|
|
49
|
+
if (transactionType instanceof TransactionType) {
|
|
50
|
+
code = transactionType.code;
|
|
51
|
+
} else {
|
|
52
|
+
code = transactionType;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let schema;
|
|
56
|
+
|
|
57
|
+
if (is.string(code)) {
|
|
58
|
+
schema = Enum.fromCode(TransactionSchema, code);
|
|
59
|
+
} else {
|
|
60
|
+
schema = null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return schema;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The complete transaction schema.
|
|
68
|
+
*
|
|
69
|
+
* @static
|
|
70
|
+
* @public
|
|
71
|
+
* @returns {TransactionSchema}
|
|
72
|
+
*/
|
|
34
73
|
static get COMPLETE() {
|
|
35
74
|
return complete;
|
|
36
75
|
}
|
|
37
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Transaction data transmitted to the client, omitting some system data.
|
|
79
|
+
*
|
|
80
|
+
* @static
|
|
81
|
+
* @public
|
|
82
|
+
* @returns {TransactionSchema}
|
|
83
|
+
*/
|
|
84
|
+
static get CLIENT() {
|
|
85
|
+
return client;
|
|
86
|
+
}
|
|
87
|
+
|
|
38
88
|
static get BUY() {
|
|
39
89
|
return buy;
|
|
40
90
|
}
|
|
@@ -112,7 +162,7 @@ module.exports = (() => {
|
|
|
112
162
|
}
|
|
113
163
|
}
|
|
114
164
|
|
|
115
|
-
const complete = new TransactionSchema(SchemaBuilder.withName('
|
|
165
|
+
const complete = new TransactionSchema(SchemaBuilder.withName('complete')
|
|
116
166
|
.withField('portfolio', DataType.STRING)
|
|
117
167
|
.withField('position', DataType.STRING)
|
|
118
168
|
.withField('sequence', DataType.NUMBER)
|
|
@@ -149,12 +199,51 @@ module.exports = (() => {
|
|
|
149
199
|
.withField('charge.amount', DataType.DECIMAL, true)
|
|
150
200
|
.withField('income.amount', DataType.DECIMAL, true)
|
|
151
201
|
.withField('valuation.value', DataType.DECIMAL, true)
|
|
202
|
+
.withField('system.sequence', DataType.NUMBER)
|
|
203
|
+
.withField('system.version', DataType.STRING)
|
|
204
|
+
.withField('system.timestamp', DataType.TIMESTAMP)
|
|
152
205
|
.schema
|
|
153
206
|
);
|
|
154
207
|
|
|
155
|
-
const
|
|
208
|
+
const client = new TransactionSchema(SchemaBuilder.withName('client')
|
|
209
|
+
.withField('portfolio', DataType.STRING)
|
|
210
|
+
.withField('position', DataType.STRING)
|
|
211
|
+
.withField('sequence', DataType.NUMBER)
|
|
212
|
+
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
213
|
+
.withField('date', DataType.DAY)
|
|
214
|
+
.withField('description', DataType.STRING, true)
|
|
215
|
+
.withField('amount', DataType.DECIMAL)
|
|
216
|
+
.withField('quantity', DataType.DECIMAL)
|
|
217
|
+
.withField('fee', DataType.DECIMAL, true)
|
|
218
|
+
.withField('reference.position', DataType.STRING, true)
|
|
219
|
+
.withField('reference.sequence', DataType.NUMBER, true)
|
|
220
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
221
|
+
.withField('snapshot.buys', DataType.DECIMAL)
|
|
222
|
+
.withField('snapshot.sells', DataType.DECIMAL)
|
|
223
|
+
.withField('snapshot.gain', DataType.DECIMAL)
|
|
224
|
+
.withField('snapshot.basis', DataType.DECIMAL)
|
|
225
|
+
.withField('snapshot.income', DataType.DECIMAL)
|
|
226
|
+
.withField('snapshot.value', DataType.DECIMAL)
|
|
227
|
+
.withField('trade.price', DataType.DECIMAL, true)
|
|
228
|
+
.withField('dividend.rate', DataType.DECIMAL, true)
|
|
229
|
+
.withField('dividend.effective', DataType.DAY, true)
|
|
230
|
+
.withField('dividend.price', DataType.DECIMAL, true)
|
|
231
|
+
.withField('dividend.amount', DataType.DECIMAL, true)
|
|
232
|
+
.withField('dividend.reference', DataType.STRING, true)
|
|
233
|
+
.withField('split.numerator', DataType.DECIMAL, true)
|
|
234
|
+
.withField('split.denominator', DataType.DECIMAL, true)
|
|
235
|
+
.withField('split.effective', DataType.DAY, true)
|
|
236
|
+
.withField('split.reference', DataType.STRING, true)
|
|
237
|
+
.withField('charge.amount', DataType.DECIMAL, true)
|
|
238
|
+
.withField('income.amount', DataType.DECIMAL, true)
|
|
239
|
+
.withField('valuation.value', DataType.DECIMAL, true)
|
|
240
|
+
.schema
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const buy = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY.code)
|
|
244
|
+
.withField('portfolio', DataType.STRING)
|
|
245
|
+
.withField('position', DataType.STRING)
|
|
156
246
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
157
|
-
.withField('position', DataType.STRING, true)
|
|
158
247
|
.withField('instrument.name', DataType.STRING, true)
|
|
159
248
|
.withField('instrument.type', DataType.STRING, true)
|
|
160
249
|
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -168,10 +257,10 @@ module.exports = (() => {
|
|
|
168
257
|
.schema
|
|
169
258
|
);
|
|
170
259
|
|
|
171
|
-
const sell = new TransactionSchema(SchemaBuilder.withName(
|
|
260
|
+
const sell = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL.code)
|
|
261
|
+
.withField('portfolio', DataType.STRING)
|
|
262
|
+
.withField('position', DataType.STRING)
|
|
172
263
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
173
|
-
.withField('position', DataType.STRING, true)
|
|
174
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
175
264
|
.withField('date', DataType.DAY)
|
|
176
265
|
.withField('price', DataType.DECIMAL)
|
|
177
266
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -179,10 +268,10 @@ module.exports = (() => {
|
|
|
179
268
|
.schema
|
|
180
269
|
);
|
|
181
270
|
|
|
182
|
-
const buyShort = new TransactionSchema(SchemaBuilder.withName(
|
|
271
|
+
const buyShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY_SHORT.code)
|
|
272
|
+
.withField('portfolio', DataType.STRING)
|
|
273
|
+
.withField('position', DataType.STRING)
|
|
183
274
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
184
|
-
.withField('position', DataType.STRING, true)
|
|
185
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
186
275
|
.withField('date', DataType.DAY)
|
|
187
276
|
.withField('price', DataType.DECIMAL)
|
|
188
277
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -190,10 +279,15 @@ module.exports = (() => {
|
|
|
190
279
|
.schema
|
|
191
280
|
);
|
|
192
281
|
|
|
193
|
-
const sellShort = new TransactionSchema(SchemaBuilder.withName(
|
|
282
|
+
const sellShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL_SHORT.code)
|
|
283
|
+
.withField('portfolio', DataType.STRING)
|
|
284
|
+
.withField('position', DataType.STRING)
|
|
194
285
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
195
|
-
.withField('
|
|
196
|
-
.withField('
|
|
286
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
287
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
288
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
289
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
290
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
197
291
|
.withField('date', DataType.DAY)
|
|
198
292
|
.withField('price', DataType.DECIMAL)
|
|
199
293
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -201,10 +295,10 @@ module.exports = (() => {
|
|
|
201
295
|
.schema
|
|
202
296
|
);
|
|
203
297
|
|
|
204
|
-
const dividend = new TransactionSchema(SchemaBuilder.withName(
|
|
298
|
+
const dividend = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND.code)
|
|
299
|
+
.withField('portfolio', DataType.STRING)
|
|
300
|
+
.withField('position', DataType.STRING)
|
|
205
301
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
206
|
-
.withField('position', DataType.STRING, true)
|
|
207
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
208
302
|
.withField('date', DataType.DAY)
|
|
209
303
|
.withField('rate', DataType.DECIMAL)
|
|
210
304
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -213,10 +307,10 @@ module.exports = (() => {
|
|
|
213
307
|
.schema
|
|
214
308
|
);
|
|
215
309
|
|
|
216
|
-
const dividendReinvest = new TransactionSchema(SchemaBuilder.withName(
|
|
310
|
+
const dividendReinvest = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_REINVEST.code)
|
|
311
|
+
.withField('portfolio', DataType.STRING)
|
|
312
|
+
.withField('position', DataType.STRING)
|
|
217
313
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
218
|
-
.withField('position', DataType.STRING, true)
|
|
219
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
220
314
|
.withField('date', DataType.DAY)
|
|
221
315
|
.withField('rate', DataType.DECIMAL)
|
|
222
316
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -226,10 +320,10 @@ module.exports = (() => {
|
|
|
226
320
|
.schema
|
|
227
321
|
);
|
|
228
322
|
|
|
229
|
-
const dividendStock = new TransactionSchema(SchemaBuilder.withName(
|
|
323
|
+
const dividendStock = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_STOCK.code)
|
|
324
|
+
.withField('portfolio', DataType.STRING)
|
|
325
|
+
.withField('position', DataType.STRING)
|
|
230
326
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
231
|
-
.withField('position', DataType.STRING, true)
|
|
232
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
233
327
|
.withField('date', DataType.DAY)
|
|
234
328
|
.withField('rate', DataType.DECIMAL)
|
|
235
329
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -239,10 +333,10 @@ module.exports = (() => {
|
|
|
239
333
|
.schema
|
|
240
334
|
);
|
|
241
335
|
|
|
242
|
-
const distributionCash = new TransactionSchema(SchemaBuilder.withName(
|
|
336
|
+
const distributionCash = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_CASH.code)
|
|
337
|
+
.withField('portfolio', DataType.STRING)
|
|
338
|
+
.withField('position', DataType.STRING)
|
|
243
339
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
244
|
-
.withField('position', DataType.STRING, true)
|
|
245
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
246
340
|
.withField('date', DataType.DAY)
|
|
247
341
|
.withField('rate', DataType.DECIMAL)
|
|
248
342
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -251,10 +345,10 @@ module.exports = (() => {
|
|
|
251
345
|
.schema
|
|
252
346
|
);
|
|
253
347
|
|
|
254
|
-
const distributionFund = new TransactionSchema(SchemaBuilder.withName(
|
|
348
|
+
const distributionFund = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_FUND.code)
|
|
349
|
+
.withField('portfolio', DataType.STRING)
|
|
350
|
+
.withField('position', DataType.STRING)
|
|
255
351
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
256
|
-
.withField('position', DataType.STRING, true)
|
|
257
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
258
352
|
.withField('date', DataType.DAY)
|
|
259
353
|
.withField('rate', DataType.DECIMAL)
|
|
260
354
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -263,10 +357,10 @@ module.exports = (() => {
|
|
|
263
357
|
.schema
|
|
264
358
|
);
|
|
265
359
|
|
|
266
|
-
const split = new TransactionSchema(SchemaBuilder.withName(
|
|
360
|
+
const split = new TransactionSchema(SchemaBuilder.withName(TransactionType.SPLIT.code)
|
|
361
|
+
.withField('portfolio', DataType.STRING)
|
|
362
|
+
.withField('position', DataType.STRING)
|
|
267
363
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
268
|
-
.withField('position', DataType.STRING, true)
|
|
269
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
270
364
|
.withField('date', DataType.DAY)
|
|
271
365
|
.withField('numerator', DataType.DECIMAL)
|
|
272
366
|
.withField('denominator', DataType.DECIMAL)
|
|
@@ -275,85 +369,110 @@ module.exports = (() => {
|
|
|
275
369
|
.schema
|
|
276
370
|
);
|
|
277
371
|
|
|
278
|
-
const fee = new TransactionSchema(SchemaBuilder.withName(
|
|
372
|
+
const fee = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE.code)
|
|
373
|
+
.withField('portfolio', DataType.STRING)
|
|
374
|
+
.withField('position', DataType.STRING)
|
|
279
375
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
280
|
-
.withField('position', DataType.STRING, true)
|
|
281
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
282
376
|
.withField('date', DataType.DAY)
|
|
283
377
|
.withField('fee', DataType.DECIMAL)
|
|
284
378
|
.schema
|
|
285
379
|
);
|
|
286
380
|
|
|
287
|
-
const feeUnits = new TransactionSchema(SchemaBuilder.withName(
|
|
381
|
+
const feeUnits = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE_UNITS.code)
|
|
382
|
+
.withField('portfolio', DataType.STRING)
|
|
383
|
+
.withField('position', DataType.STRING)
|
|
288
384
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
289
|
-
.withField('position', DataType.STRING, true)
|
|
290
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
291
385
|
.withField('date', DataType.DAY)
|
|
292
386
|
.withField('fee', DataType.DECIMAL)
|
|
293
387
|
.withField('price', DataType.DECIMAL)
|
|
294
388
|
.schema
|
|
295
389
|
);
|
|
296
390
|
|
|
297
|
-
const deposit = new TransactionSchema(SchemaBuilder.withName(
|
|
391
|
+
const deposit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEPOSIT.code)
|
|
392
|
+
.withField('portfolio', DataType.STRING)
|
|
393
|
+
.withField('position', DataType.STRING)
|
|
298
394
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
299
|
-
.withField('
|
|
300
|
-
.withField('
|
|
395
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
396
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
397
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
398
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
399
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
301
400
|
.withField('date', DataType.DAY)
|
|
302
401
|
.withField('amount', DataType.DECIMAL)
|
|
303
402
|
.withField('fee', DataType.DECIMAL, true)
|
|
304
403
|
.schema
|
|
305
404
|
);
|
|
306
405
|
|
|
307
|
-
const withdrawal = new TransactionSchema(SchemaBuilder.withName(
|
|
406
|
+
const withdrawal = new TransactionSchema(SchemaBuilder.withName(TransactionType.WITHDRAWAL.code)
|
|
407
|
+
.withField('portfolio', DataType.STRING)
|
|
408
|
+
.withField('position', DataType.STRING)
|
|
308
409
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
309
|
-
.withField('position', DataType.STRING, true)
|
|
310
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
311
410
|
.withField('date', DataType.DAY)
|
|
312
411
|
.withField('amount', DataType.DECIMAL)
|
|
313
412
|
.withField('fee', DataType.DECIMAL, true)
|
|
314
413
|
.schema
|
|
315
414
|
);
|
|
316
415
|
|
|
317
|
-
const debit = new TransactionSchema(SchemaBuilder.withName(
|
|
416
|
+
const debit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEBIT.code)
|
|
417
|
+
.withField('portfolio', DataType.STRING)
|
|
418
|
+
.withField('position', DataType.STRING)
|
|
318
419
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
319
|
-
.withField('position', DataType.STRING, true)
|
|
320
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
321
420
|
.withField('date', DataType.DAY)
|
|
322
421
|
.withField('amount', DataType.DECIMAL)
|
|
323
422
|
.withField('fee', DataType.DECIMAL, true)
|
|
324
423
|
.schema
|
|
325
424
|
);
|
|
326
425
|
|
|
327
|
-
const credit = new TransactionSchema(SchemaBuilder.withName(
|
|
426
|
+
const credit = new TransactionSchema(SchemaBuilder.withName(TransactionType.CREDIT.code)
|
|
427
|
+
.withField('portfolio', DataType.STRING)
|
|
428
|
+
.withField('position', DataType.STRING)
|
|
328
429
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
329
|
-
.withField('position', DataType.STRING, true)
|
|
330
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
331
430
|
.withField('date', DataType.DAY)
|
|
332
431
|
.withField('amount', DataType.DECIMAL)
|
|
333
432
|
.withField('fee', DataType.DECIMAL, true)
|
|
334
433
|
.schema
|
|
335
434
|
);
|
|
336
435
|
|
|
337
|
-
const valuation = new TransactionSchema(SchemaBuilder.withName(
|
|
436
|
+
const valuation = new TransactionSchema(SchemaBuilder.withName(TransactionType.VALUATION.code)
|
|
437
|
+
.withField('portfolio', DataType.STRING)
|
|
438
|
+
.withField('position', DataType.STRING)
|
|
338
439
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
339
|
-
.withField('position', DataType.STRING, true)
|
|
340
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
341
440
|
.withField('date', DataType.DAY)
|
|
342
441
|
.withField('value', DataType.DECIMAL)
|
|
343
442
|
.withField('fee', DataType.DECIMAL, true)
|
|
344
443
|
.schema
|
|
345
444
|
);
|
|
346
445
|
|
|
347
|
-
const income = new TransactionSchema(SchemaBuilder.withName(
|
|
446
|
+
const income = new TransactionSchema(SchemaBuilder.withName(TransactionType.INCOME.code)
|
|
447
|
+
.withField('portfolio', DataType.STRING)
|
|
448
|
+
.withField('position', DataType.STRING)
|
|
348
449
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
349
|
-
.withField('position', DataType.STRING, true)
|
|
350
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
351
450
|
.withField('date', DataType.DAY)
|
|
352
451
|
.withField('income', DataType.DECIMAL)
|
|
353
452
|
.withField('fee', DataType.DECIMAL, true)
|
|
354
453
|
.schema
|
|
355
454
|
);
|
|
356
455
|
|
|
456
|
+
const map = { };
|
|
457
|
+
|
|
458
|
+
function addSchemaToMap(type, schema) {
|
|
459
|
+
map[type.code] = schema;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
addSchemaToMap(TransactionType.BUY, buy);
|
|
463
|
+
addSchemaToMap(TransactionType.SELL, sell);
|
|
464
|
+
addSchemaToMap(TransactionType.BUY_SHORT, buyShort);
|
|
465
|
+
addSchemaToMap(TransactionType.SELL_SHORT, sellShort);
|
|
466
|
+
addSchemaToMap(TransactionType.DIVIDEND, dividend);
|
|
467
|
+
addSchemaToMap(TransactionType.DIVIDEND_STOCK, dividendStock);
|
|
468
|
+
addSchemaToMap(TransactionType.DIVIDEND_REINVEST, dividendReinvest);
|
|
469
|
+
addSchemaToMap(TransactionType.SPLIT, split);
|
|
470
|
+
addSchemaToMap(TransactionType.FEE, fee);
|
|
471
|
+
addSchemaToMap(TransactionType.FEE_UNITS, feeUnits);
|
|
472
|
+
addSchemaToMap(TransactionType.DEPOSIT, deposit);
|
|
473
|
+
addSchemaToMap(TransactionType.WITHDRAWAL, withdrawal);
|
|
474
|
+
addSchemaToMap(TransactionType.VALUATION, valuation);
|
|
475
|
+
addSchemaToMap(TransactionType.INCOME, income);
|
|
357
476
|
|
|
358
477
|
return TransactionSchema;
|
|
359
478
|
})();
|