@barchart/portfolio-api-common 1.0.60 → 1.0.64
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.
|
@@ -6,8 +6,9 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
6
6
|
is = require('@barchart/common-js/lang/is'),
|
|
7
7
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
8
8
|
|
|
9
|
+
const InstrumentType = require('./../data/InstrumentType');
|
|
10
|
+
|
|
9
11
|
const PositionGroup = require('./PositionGroup'),
|
|
10
|
-
PositionGroupDefinition = require('./PositionGroupDefinition'),
|
|
11
12
|
PositionItem = require('./PositionItem');
|
|
12
13
|
|
|
13
14
|
module.exports = (() => {
|
|
@@ -17,7 +18,10 @@ module.exports = (() => {
|
|
|
17
18
|
* @public
|
|
18
19
|
*/
|
|
19
20
|
class PositionContainer {
|
|
20
|
-
constructor(portfolios, positions, summaries, definitions) {
|
|
21
|
+
constructor(portfolios, positions, summaries, definitions, defaultCurrency) {
|
|
22
|
+
this._definitions = definitions;
|
|
23
|
+
this._defaultCurrency = defaultCurrency || Currency.CAD;
|
|
24
|
+
|
|
21
25
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
22
26
|
map[portfolio.portfolio] = portfolio;
|
|
23
27
|
|
|
@@ -49,11 +53,10 @@ module.exports = (() => {
|
|
|
49
53
|
}, [ ]);
|
|
50
54
|
|
|
51
55
|
this._symbols = this._items.reduce((map, item) => {
|
|
52
|
-
|
|
53
|
-
let symbol = null;
|
|
56
|
+
const position = item.position;
|
|
54
57
|
|
|
55
58
|
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
56
|
-
symbol = position.instrument.symbol.barchart;
|
|
59
|
+
const symbol = position.instrument.symbol.barchart;
|
|
57
60
|
|
|
58
61
|
if (!map.hasOwnProperty(symbol)) {
|
|
59
62
|
map[symbol] = [ ];
|
|
@@ -65,7 +68,21 @@ module.exports = (() => {
|
|
|
65
68
|
return map;
|
|
66
69
|
}, { });
|
|
67
70
|
|
|
68
|
-
this.
|
|
71
|
+
this._currencies = this._items.reduce((map, item) => {
|
|
72
|
+
const position = item.position;
|
|
73
|
+
|
|
74
|
+
if (position.instrument && position.instrument.currency) {
|
|
75
|
+
const currency = position.instrument.currency;
|
|
76
|
+
|
|
77
|
+
if (!map.hasOwnProperty(currency)) {
|
|
78
|
+
map[currency] = [ ];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
map[currency].push(item);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return map;
|
|
85
|
+
}, { });
|
|
69
86
|
|
|
70
87
|
this._tree = new Tree();
|
|
71
88
|
|
|
@@ -74,6 +91,8 @@ module.exports = (() => {
|
|
|
74
91
|
return;
|
|
75
92
|
}
|
|
76
93
|
|
|
94
|
+
const parent = tree.getValue() || null;
|
|
95
|
+
|
|
77
96
|
const currentDefinition = definitions[0];
|
|
78
97
|
const additionalDefinitions = array.dropLeft(definitions);
|
|
79
98
|
|
|
@@ -81,13 +100,13 @@ module.exports = (() => {
|
|
|
81
100
|
const populatedGroups = Object.keys(populatedObjects).map(key => populatedObjects[key]).map((items) => {
|
|
82
101
|
const first = items[0];
|
|
83
102
|
|
|
84
|
-
return new PositionGroup(items, currentDefinition.currencySelector(first), currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
103
|
+
return new PositionGroup(parent, items, currentDefinition.currencySelector(first), currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
85
104
|
});
|
|
86
105
|
|
|
87
106
|
const missingGroups = array.difference(currentDefinition.requiredGroups.map(group => group.description), populatedGroups.map(group => group.description));
|
|
88
107
|
|
|
89
108
|
const empty = missingGroups.map((description) => {
|
|
90
|
-
return new PositionGroup([ ], currentDefinition.requiredGroups.find(group => group.description === description).currency, description);
|
|
109
|
+
return new PositionGroup(parent, [ ], currentDefinition.requiredGroups.find(group => group.description === description).currency, description);
|
|
91
110
|
});
|
|
92
111
|
|
|
93
112
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -132,6 +151,10 @@ module.exports = (() => {
|
|
|
132
151
|
createGroups(this._tree, this._items, this._definitions);
|
|
133
152
|
}
|
|
134
153
|
|
|
154
|
+
get defaultCurrency() {
|
|
155
|
+
return this._defaultCurrency;
|
|
156
|
+
}
|
|
157
|
+
|
|
135
158
|
getSymbols() {
|
|
136
159
|
return Object.keys(this._symbols);
|
|
137
160
|
}
|
|
@@ -142,6 +165,22 @@ module.exports = (() => {
|
|
|
142
165
|
}
|
|
143
166
|
}
|
|
144
167
|
|
|
168
|
+
getCurrencySymbols() {
|
|
169
|
+
const codes = Object.keys(this._currencies);
|
|
170
|
+
|
|
171
|
+
return codes.reduce((symbols, code) => {
|
|
172
|
+
if (code !== this._defaultCurrency) {
|
|
173
|
+
symbols.push(`^${this._defaultCurrency}${code}`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return symbols;
|
|
177
|
+
}, [ ]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
setExchangeRage(symbol, price) {
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
145
184
|
getGroup(keys) {
|
|
146
185
|
const node = keys.reduce((tree, key) => {
|
|
147
186
|
tree = tree.findChild(group => group.description === key);
|
|
@@ -11,7 +11,9 @@ module.exports = (() => {
|
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
class PositionGroup {
|
|
14
|
-
constructor(items, currency, description, single) {
|
|
14
|
+
constructor(parent, items, currency, description, single) {
|
|
15
|
+
this._parent = parent || null;
|
|
16
|
+
|
|
15
17
|
this._items = items;
|
|
16
18
|
this._currency = currency;
|
|
17
19
|
|
|
@@ -20,37 +22,40 @@ module.exports = (() => {
|
|
|
20
22
|
this._single = is.boolean(single) && single;
|
|
21
23
|
|
|
22
24
|
this._dataFormat = { };
|
|
23
|
-
this.
|
|
25
|
+
this._dataActual = { };
|
|
24
26
|
|
|
25
27
|
this._dataFormat.description = this._description;
|
|
26
28
|
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
this._dataRaw.basis = null;
|
|
34
|
-
this._dataRaw.market = null;
|
|
29
|
+
this._dataActual.currentPrice = null;
|
|
30
|
+
this._dataActual.previousPrice = null;
|
|
31
|
+
this._dataActual.basis = null;
|
|
32
|
+
this._dataActual.market = null;
|
|
33
|
+
this._dataActual.marketPercent = null;
|
|
34
|
+
this._dataActual.unrealizedToday = null;
|
|
35
35
|
|
|
36
|
+
this._dataFormat.currentPrice = null;
|
|
37
|
+
this._dataFormat.previousPrice = null;
|
|
36
38
|
this._dataFormat.basis = null;
|
|
37
39
|
this._dataFormat.market = null;
|
|
40
|
+
this._dataFormat.marketPercent = null;
|
|
41
|
+
this._dataFormat.unrealizedToday = null;
|
|
38
42
|
|
|
39
43
|
this._items.forEach((item) => {
|
|
40
44
|
item.registerPriceChangeHandler((data, sender) => {
|
|
41
45
|
if (this._single) {
|
|
42
|
-
this.
|
|
43
|
-
this._dataFormat.
|
|
46
|
+
this._dataActual.currentPrice = data.currentPrice;
|
|
47
|
+
this._dataFormat.currentPrice = format(data.currentPrice, sender.position.instrument.currency);
|
|
44
48
|
} else {
|
|
45
|
-
this.
|
|
46
|
-
this._dataFormat.
|
|
49
|
+
this._dataActual.currentPrice = null;
|
|
50
|
+
this._dataFormat.currentPrice = null;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
calculatePriceData(this, sender);
|
|
50
54
|
});
|
|
51
55
|
});
|
|
52
56
|
|
|
53
57
|
calculateStaticData(this);
|
|
58
|
+
calculatePriceData(this);
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
get items() {
|
|
@@ -78,41 +83,91 @@ module.exports = (() => {
|
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
|
|
81
|
-
function
|
|
82
|
-
|
|
86
|
+
function formatNumber(decimal, precision) {
|
|
87
|
+
if (decimal !== null) {
|
|
88
|
+
return formatter.numberToString(decimal.toFloat(), precision, ',', false);
|
|
89
|
+
} else {
|
|
90
|
+
return '--';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function formatPercent(decimal, precision) {
|
|
95
|
+
if (decimal !== null) {
|
|
96
|
+
return formatNumber(decimal.multiply(100));
|
|
97
|
+
} else {
|
|
98
|
+
return '--';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function formatCurrency(decimal, currency) {
|
|
103
|
+
return formatNumber(decimal, currency.precision);
|
|
83
104
|
}
|
|
84
105
|
|
|
85
106
|
function calculateStaticData(group) {
|
|
107
|
+
const actual = group._dataActual;
|
|
108
|
+
const format = group._dataFormat;
|
|
109
|
+
|
|
110
|
+
const currency = group.currency;
|
|
111
|
+
|
|
86
112
|
const items = group._items;
|
|
87
113
|
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
let updates = items.reduce((updates, item) => {
|
|
115
|
+
updates.basis = updates.basis.add(item.data.basis);
|
|
90
116
|
|
|
91
|
-
|
|
117
|
+
return updates;
|
|
118
|
+
}, {
|
|
119
|
+
basis: Decimal.ZERO
|
|
120
|
+
});
|
|
92
121
|
|
|
93
|
-
|
|
94
|
-
|
|
122
|
+
actual.basis = updates.basis;
|
|
123
|
+
|
|
124
|
+
format.basis = formatCurrency(updates.basis, currency);
|
|
125
|
+
}
|
|
95
126
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
127
|
+
function calculatePriceData(group, item) {
|
|
128
|
+
const parent = group._parent;
|
|
129
|
+
|
|
130
|
+
const actual = group._dataActual;
|
|
131
|
+
const format = group._dataFormat;
|
|
132
|
+
|
|
133
|
+
const currency = group.currency;
|
|
134
|
+
|
|
135
|
+
let updates;
|
|
101
136
|
|
|
102
|
-
|
|
137
|
+
if (actual.market === null || actual.unrealizedToday === null) {
|
|
138
|
+
const items = group._items;
|
|
139
|
+
|
|
140
|
+
updates = items.reduce((updates, item) => {
|
|
141
|
+
updates.market = updates.market.add(item.data.market);
|
|
142
|
+
updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
|
|
103
143
|
|
|
104
144
|
return updates;
|
|
105
145
|
}, {
|
|
106
|
-
|
|
146
|
+
market: Decimal.ZERO,
|
|
147
|
+
unrealizedToday: Decimal.ZERO
|
|
107
148
|
});
|
|
149
|
+
} else {
|
|
150
|
+
updates = {
|
|
151
|
+
market: actual.market.add(item.data.marketChange),
|
|
152
|
+
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
|
|
153
|
+
};
|
|
108
154
|
}
|
|
155
|
+
|
|
156
|
+
if (parent !== null) {
|
|
157
|
+
const parentData = parent._dataActual;
|
|
109
158
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
159
|
+
if (parentData.market !== null && !parentData.market.getIsZero()) {
|
|
160
|
+
updates.marketPercent = updates.market.divide(parentData.market);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
actual.market = updates.market;
|
|
165
|
+
actual.marketPercent = updates.marketPercent;
|
|
166
|
+
actual.unrealizedToday = updates.unrealizedToday;
|
|
167
|
+
|
|
168
|
+
format.market = formatCurrency(updates.market, currency);
|
|
169
|
+
format.marketPercent = formatPercent(updates.unrealizedToday, 2);
|
|
170
|
+
format.unrealizedToday = formatCurrency(updates.unrealizedToday, currency);
|
|
116
171
|
}
|
|
117
172
|
|
|
118
173
|
return PositionGroup;
|
|
@@ -3,6 +3,8 @@ const assert = require('@barchart/common-js/lang/assert'),
|
|
|
3
3
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
4
4
|
is = require('@barchart/common-js/lang/is');
|
|
5
5
|
|
|
6
|
+
const InstrumentType = require('./../data/InstrumentType');
|
|
7
|
+
|
|
6
8
|
module.exports = (() => {
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
@@ -17,22 +19,19 @@ module.exports = (() => {
|
|
|
17
19
|
|
|
18
20
|
this._data = { };
|
|
19
21
|
|
|
20
|
-
this._data.
|
|
21
|
-
this._data.previous = position.previous || null;
|
|
22
|
-
|
|
23
|
-
const snapshot = this._position.snapshot;
|
|
22
|
+
this._data.basis = null;
|
|
24
23
|
|
|
25
|
-
this._data.
|
|
24
|
+
this._data.currentPrice = null;
|
|
25
|
+
this._data.previousPrice = null;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
this._data.market = null;
|
|
28
|
+
this._data.marketChange = null;
|
|
29
|
+
|
|
30
|
+
this._data.unrealizedToday = null;
|
|
31
|
+
this._data.unrealizedTodayChange = null;
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} else {
|
|
33
|
-
market = snapshot.value;
|
|
34
|
-
}
|
|
35
|
-
*/
|
|
33
|
+
calculateStaticData(this);
|
|
34
|
+
calculatePriceData(this, null);
|
|
36
35
|
|
|
37
36
|
this._priceChangeEvent = new Event(this);
|
|
38
37
|
}
|
|
@@ -49,9 +48,13 @@ module.exports = (() => {
|
|
|
49
48
|
return this._summaries;
|
|
50
49
|
}
|
|
51
50
|
|
|
51
|
+
get data() {
|
|
52
|
+
return this._data;
|
|
53
|
+
}
|
|
54
|
+
|
|
52
55
|
setPrice(price) {
|
|
53
56
|
if (this._data.price !== price) {
|
|
54
|
-
this._data.
|
|
57
|
+
calculatePriceData(this, this._data.currentPrice = price);
|
|
55
58
|
|
|
56
59
|
this._priceChangeEvent.fire(this._data);
|
|
57
60
|
}
|
|
@@ -68,5 +71,75 @@ module.exports = (() => {
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
function calculateStaticData(item) {
|
|
75
|
+
const position = item.position;
|
|
76
|
+
const snapshot = item.position.snapshot;
|
|
77
|
+
|
|
78
|
+
const data = item._data;
|
|
79
|
+
|
|
80
|
+
data.previousPrice = position.previousPrice || null;
|
|
81
|
+
|
|
82
|
+
let basis;
|
|
83
|
+
|
|
84
|
+
if (snapshot.basis) {
|
|
85
|
+
basis = snapshot.basis.opposite();
|
|
86
|
+
} else {
|
|
87
|
+
basis = Decimal.ZERO;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
data.basis = basis;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function calculatePriceData(item, price) {
|
|
94
|
+
const position = item.position;
|
|
95
|
+
const snapshot = item.position.snapshot;
|
|
96
|
+
|
|
97
|
+
const data = item._data;
|
|
98
|
+
|
|
99
|
+
let market;
|
|
100
|
+
|
|
101
|
+
if (position.instrument.type === InstrumentType.OTHER) {
|
|
102
|
+
market = snapshot.value;
|
|
103
|
+
} else if (position.instrument.type === InstrumentType.CASH) {
|
|
104
|
+
market = snapshot.open;
|
|
105
|
+
} else {
|
|
106
|
+
if (price) {
|
|
107
|
+
market = snapshot.open.multiply(price);
|
|
108
|
+
} else {
|
|
109
|
+
market = snapshot.value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let marketChange;
|
|
114
|
+
|
|
115
|
+
if (data.market === null) {
|
|
116
|
+
marketChange = market;
|
|
117
|
+
} else {
|
|
118
|
+
marketChange = market.subtract(data.market);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
data.market = market;
|
|
122
|
+
data.marketChange = marketChange;
|
|
123
|
+
|
|
124
|
+
let unrealizedToday;
|
|
125
|
+
let unrealizedTodayChange;
|
|
126
|
+
|
|
127
|
+
if (data.previousPrice && price) {
|
|
128
|
+
unrealizedToday = market.subtract(snapshot.open.multiply(data.previousPrice));
|
|
129
|
+
|
|
130
|
+
if (data.unrealizedToday !== null) {
|
|
131
|
+
unrealizedTodayChange = unrealizedToday.subtract(data.unrealizedToday);
|
|
132
|
+
} else {
|
|
133
|
+
unrealizedTodayChange = unrealizedToday;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
unrealizedToday = Decimal.ZERO;
|
|
137
|
+
unrealizedTodayChange = Decimal.ZERO;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
data.unrealizedToday = unrealizedToday;
|
|
141
|
+
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
142
|
+
}
|
|
143
|
+
|
|
71
144
|
return PositionItem;
|
|
72
145
|
})();
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1,4 +1,95 @@
|
|
|
1
1
|
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
|
|
2
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
3
|
+
Enum = require('@barchart/common-js/lang/Enum');
|
|
4
|
+
|
|
5
|
+
module.exports = (() => {
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An enumeration used to classify instruments.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
* @extends {Enum}
|
|
13
|
+
* @param {String} description
|
|
14
|
+
* @param {String} alternateDescription
|
|
15
|
+
* @param {String} code
|
|
16
|
+
* @param {Boolean} canReinvest
|
|
17
|
+
*/
|
|
18
|
+
class InstrumentType extends Enum {
|
|
19
|
+
constructor(code, description, alternateDescription, canReinvest) {
|
|
20
|
+
super(code, description);
|
|
21
|
+
|
|
22
|
+
this._alternateDescription = alternateDescription;
|
|
23
|
+
this._canReinvest = canReinvest;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get alternateDescription() {
|
|
27
|
+
return this._alternateDescription;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Indicates if the instrument type allows automatic reinvestment.
|
|
32
|
+
*
|
|
33
|
+
* @returns {Boolean}
|
|
34
|
+
*/
|
|
35
|
+
get canReinvest() {
|
|
36
|
+
return this._canReinvest;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Cash.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
* @returns {InstrumentType}
|
|
44
|
+
*/
|
|
45
|
+
static get CASH() {
|
|
46
|
+
return cash;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* An equity issue.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
* @returns {InstrumentType}
|
|
54
|
+
*/
|
|
55
|
+
static get EQUITY() {
|
|
56
|
+
return equity;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A mutual fund.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
* @returns {InstrumentType}
|
|
64
|
+
*/
|
|
65
|
+
static get FUND() {
|
|
66
|
+
return fund;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* An undefined asset (e.g. a house, or a collectible, or a salvaged alien spaceship).
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
* @returns {InstrumentType}
|
|
74
|
+
*/
|
|
75
|
+
static get OTHER() {
|
|
76
|
+
return other;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
toString() {
|
|
80
|
+
return '[InstrumentType]';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false);
|
|
85
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true);
|
|
86
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true);
|
|
87
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false);
|
|
88
|
+
|
|
89
|
+
return InstrumentType;
|
|
90
|
+
})();
|
|
91
|
+
|
|
92
|
+
},{"@barchart/common-js/lang/Enum":15,"@barchart/common-js/lang/assert":17}],2:[function(require,module,exports){
|
|
2
93
|
const array = require('@barchart/common-js/lang/array'),
|
|
3
94
|
assert = require('@barchart/common-js/lang/assert'),
|
|
4
95
|
Day = require('@barchart/common-js/lang/Day'),
|
|
@@ -185,7 +276,7 @@ module.exports = (() => {
|
|
|
185
276
|
return PositionSummaryFrame;
|
|
186
277
|
})();
|
|
187
278
|
|
|
188
|
-
},{"@barchart/common-js/lang/Day":
|
|
279
|
+
},{"@barchart/common-js/lang/Day":12,"@barchart/common-js/lang/Enum":15,"@barchart/common-js/lang/array":16,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],3:[function(require,module,exports){
|
|
189
280
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
190
281
|
Enum = require('@barchart/common-js/lang/Enum');
|
|
191
282
|
|
|
@@ -512,7 +603,7 @@ module.exports = (() => {
|
|
|
512
603
|
return TransactionType;
|
|
513
604
|
})();
|
|
514
605
|
|
|
515
|
-
},{"@barchart/common-js/lang/Enum":
|
|
606
|
+
},{"@barchart/common-js/lang/Enum":15,"@barchart/common-js/lang/assert":17}],4:[function(require,module,exports){
|
|
516
607
|
const array = require('@barchart/common-js/lang/array'),
|
|
517
608
|
ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
|
|
518
609
|
comparators = require('@barchart/common-js/collections/sorting/comparators'),
|
|
@@ -521,8 +612,9 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
521
612
|
is = require('@barchart/common-js/lang/is'),
|
|
522
613
|
Tree = require('@barchart/common-js/collections/Tree');
|
|
523
614
|
|
|
615
|
+
const InstrumentType = require('./../data/InstrumentType');
|
|
616
|
+
|
|
524
617
|
const PositionGroup = require('./PositionGroup'),
|
|
525
|
-
PositionGroupDefinition = require('./PositionGroupDefinition'),
|
|
526
618
|
PositionItem = require('./PositionItem');
|
|
527
619
|
|
|
528
620
|
module.exports = (() => {
|
|
@@ -532,7 +624,10 @@ module.exports = (() => {
|
|
|
532
624
|
* @public
|
|
533
625
|
*/
|
|
534
626
|
class PositionContainer {
|
|
535
|
-
constructor(portfolios, positions, summaries, definitions) {
|
|
627
|
+
constructor(portfolios, positions, summaries, definitions, defaultCurrency) {
|
|
628
|
+
this._definitions = definitions;
|
|
629
|
+
this._defaultCurrency = defaultCurrency || Currency.CAD;
|
|
630
|
+
|
|
536
631
|
this._portfolios = portfolios.reduce((map, portfolio) => {
|
|
537
632
|
map[portfolio.portfolio] = portfolio;
|
|
538
633
|
|
|
@@ -564,11 +659,10 @@ module.exports = (() => {
|
|
|
564
659
|
}, [ ]);
|
|
565
660
|
|
|
566
661
|
this._symbols = this._items.reduce((map, item) => {
|
|
567
|
-
|
|
568
|
-
let symbol = null;
|
|
662
|
+
const position = item.position;
|
|
569
663
|
|
|
570
664
|
if (position.instrument && position.instrument.symbol && position.instrument.symbol.barchart) {
|
|
571
|
-
symbol = position.instrument.symbol.barchart;
|
|
665
|
+
const symbol = position.instrument.symbol.barchart;
|
|
572
666
|
|
|
573
667
|
if (!map.hasOwnProperty(symbol)) {
|
|
574
668
|
map[symbol] = [ ];
|
|
@@ -580,7 +674,21 @@ module.exports = (() => {
|
|
|
580
674
|
return map;
|
|
581
675
|
}, { });
|
|
582
676
|
|
|
583
|
-
this.
|
|
677
|
+
this._currencies = this._items.reduce((map, item) => {
|
|
678
|
+
const position = item.position;
|
|
679
|
+
|
|
680
|
+
if (position.instrument && position.instrument.currency) {
|
|
681
|
+
const currency = position.instrument.currency;
|
|
682
|
+
|
|
683
|
+
if (!map.hasOwnProperty(currency)) {
|
|
684
|
+
map[currency] = [ ];
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
map[currency].push(item);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return map;
|
|
691
|
+
}, { });
|
|
584
692
|
|
|
585
693
|
this._tree = new Tree();
|
|
586
694
|
|
|
@@ -589,6 +697,8 @@ module.exports = (() => {
|
|
|
589
697
|
return;
|
|
590
698
|
}
|
|
591
699
|
|
|
700
|
+
const parent = tree.getValue() || null;
|
|
701
|
+
|
|
592
702
|
const currentDefinition = definitions[0];
|
|
593
703
|
const additionalDefinitions = array.dropLeft(definitions);
|
|
594
704
|
|
|
@@ -596,13 +706,13 @@ module.exports = (() => {
|
|
|
596
706
|
const populatedGroups = Object.keys(populatedObjects).map(key => populatedObjects[key]).map((items) => {
|
|
597
707
|
const first = items[0];
|
|
598
708
|
|
|
599
|
-
return new PositionGroup(items, currentDefinition.currencySelector(first), currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
709
|
+
return new PositionGroup(parent, items, currentDefinition.currencySelector(first), currentDefinition.descriptionSelector(first), currentDefinition.single && items.length === 1);
|
|
600
710
|
});
|
|
601
711
|
|
|
602
712
|
const missingGroups = array.difference(currentDefinition.requiredGroups.map(group => group.description), populatedGroups.map(group => group.description));
|
|
603
713
|
|
|
604
714
|
const empty = missingGroups.map((description) => {
|
|
605
|
-
return new PositionGroup([ ], currentDefinition.requiredGroups.find(group => group.description === description).currency, description);
|
|
715
|
+
return new PositionGroup(parent, [ ], currentDefinition.requiredGroups.find(group => group.description === description).currency, description);
|
|
606
716
|
});
|
|
607
717
|
|
|
608
718
|
const compositeGroups = populatedGroups.concat(empty);
|
|
@@ -647,6 +757,10 @@ module.exports = (() => {
|
|
|
647
757
|
createGroups(this._tree, this._items, this._definitions);
|
|
648
758
|
}
|
|
649
759
|
|
|
760
|
+
get defaultCurrency() {
|
|
761
|
+
return this._defaultCurrency;
|
|
762
|
+
}
|
|
763
|
+
|
|
650
764
|
getSymbols() {
|
|
651
765
|
return Object.keys(this._symbols);
|
|
652
766
|
}
|
|
@@ -657,6 +771,22 @@ module.exports = (() => {
|
|
|
657
771
|
}
|
|
658
772
|
}
|
|
659
773
|
|
|
774
|
+
getCurrencySymbols() {
|
|
775
|
+
const codes = Object.keys(this._currencies);
|
|
776
|
+
|
|
777
|
+
return codes.reduce((symbols, code) => {
|
|
778
|
+
if (code !== this._defaultCurrency) {
|
|
779
|
+
symbols.push(`^${this._defaultCurrency}${code}`);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
return symbols;
|
|
783
|
+
}, [ ]);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
setExchangeRage(symbol, price) {
|
|
787
|
+
|
|
788
|
+
}
|
|
789
|
+
|
|
660
790
|
getGroup(keys) {
|
|
661
791
|
const node = keys.reduce((tree, key) => {
|
|
662
792
|
tree = tree.findChild(group => group.description === key);
|
|
@@ -685,7 +815,7 @@ module.exports = (() => {
|
|
|
685
815
|
return PositionContainer;
|
|
686
816
|
})();
|
|
687
817
|
|
|
688
|
-
},{"
|
|
818
|
+
},{"./../data/InstrumentType":1,"./PositionGroup":5,"./PositionItem":7,"@barchart/common-js/collections/Tree":8,"@barchart/common-js/collections/sorting/ComparatorBuilder":9,"@barchart/common-js/collections/sorting/comparators":10,"@barchart/common-js/lang/Currency":11,"@barchart/common-js/lang/array":16,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],5:[function(require,module,exports){
|
|
689
819
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
690
820
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
691
821
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
@@ -699,7 +829,9 @@ module.exports = (() => {
|
|
|
699
829
|
* @public
|
|
700
830
|
*/
|
|
701
831
|
class PositionGroup {
|
|
702
|
-
constructor(items, currency, description, single) {
|
|
832
|
+
constructor(parent, items, currency, description, single) {
|
|
833
|
+
this._parent = parent || null;
|
|
834
|
+
|
|
703
835
|
this._items = items;
|
|
704
836
|
this._currency = currency;
|
|
705
837
|
|
|
@@ -708,37 +840,40 @@ module.exports = (() => {
|
|
|
708
840
|
this._single = is.boolean(single) && single;
|
|
709
841
|
|
|
710
842
|
this._dataFormat = { };
|
|
711
|
-
this.
|
|
843
|
+
this._dataActual = { };
|
|
712
844
|
|
|
713
845
|
this._dataFormat.description = this._description;
|
|
714
846
|
|
|
715
|
-
this.
|
|
716
|
-
this.
|
|
717
|
-
|
|
718
|
-
this.
|
|
719
|
-
this.
|
|
720
|
-
|
|
721
|
-
this._dataRaw.basis = null;
|
|
722
|
-
this._dataRaw.market = null;
|
|
847
|
+
this._dataActual.currentPrice = null;
|
|
848
|
+
this._dataActual.previousPrice = null;
|
|
849
|
+
this._dataActual.basis = null;
|
|
850
|
+
this._dataActual.market = null;
|
|
851
|
+
this._dataActual.marketPercent = null;
|
|
852
|
+
this._dataActual.unrealizedToday = null;
|
|
723
853
|
|
|
854
|
+
this._dataFormat.currentPrice = null;
|
|
855
|
+
this._dataFormat.previousPrice = null;
|
|
724
856
|
this._dataFormat.basis = null;
|
|
725
857
|
this._dataFormat.market = null;
|
|
858
|
+
this._dataFormat.marketPercent = null;
|
|
859
|
+
this._dataFormat.unrealizedToday = null;
|
|
726
860
|
|
|
727
861
|
this._items.forEach((item) => {
|
|
728
862
|
item.registerPriceChangeHandler((data, sender) => {
|
|
729
863
|
if (this._single) {
|
|
730
|
-
this.
|
|
731
|
-
this._dataFormat.
|
|
864
|
+
this._dataActual.currentPrice = data.currentPrice;
|
|
865
|
+
this._dataFormat.currentPrice = format(data.currentPrice, sender.position.instrument.currency);
|
|
732
866
|
} else {
|
|
733
|
-
this.
|
|
734
|
-
this._dataFormat.
|
|
867
|
+
this._dataActual.currentPrice = null;
|
|
868
|
+
this._dataFormat.currentPrice = null;
|
|
735
869
|
}
|
|
736
870
|
|
|
737
|
-
|
|
871
|
+
calculatePriceData(this, sender);
|
|
738
872
|
});
|
|
739
873
|
});
|
|
740
874
|
|
|
741
875
|
calculateStaticData(this);
|
|
876
|
+
calculatePriceData(this);
|
|
742
877
|
}
|
|
743
878
|
|
|
744
879
|
get items() {
|
|
@@ -766,47 +901,97 @@ module.exports = (() => {
|
|
|
766
901
|
}
|
|
767
902
|
}
|
|
768
903
|
|
|
769
|
-
function
|
|
770
|
-
|
|
904
|
+
function formatNumber(decimal, precision) {
|
|
905
|
+
if (decimal !== null) {
|
|
906
|
+
return formatter.numberToString(decimal.toFloat(), precision, ',', false);
|
|
907
|
+
} else {
|
|
908
|
+
return '--';
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function formatPercent(decimal, precision) {
|
|
913
|
+
if (decimal !== null) {
|
|
914
|
+
return formatNumber(decimal.multiply(100));
|
|
915
|
+
} else {
|
|
916
|
+
return '--';
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function formatCurrency(decimal, currency) {
|
|
921
|
+
return formatNumber(decimal, currency.precision);
|
|
771
922
|
}
|
|
772
923
|
|
|
773
924
|
function calculateStaticData(group) {
|
|
925
|
+
const actual = group._dataActual;
|
|
926
|
+
const format = group._dataFormat;
|
|
927
|
+
|
|
928
|
+
const currency = group.currency;
|
|
929
|
+
|
|
774
930
|
const items = group._items;
|
|
775
931
|
|
|
776
|
-
|
|
777
|
-
|
|
932
|
+
let updates = items.reduce((updates, item) => {
|
|
933
|
+
updates.basis = updates.basis.add(item.data.basis);
|
|
778
934
|
|
|
779
|
-
|
|
935
|
+
return updates;
|
|
936
|
+
}, {
|
|
937
|
+
basis: Decimal.ZERO
|
|
938
|
+
});
|
|
780
939
|
|
|
781
|
-
|
|
782
|
-
|
|
940
|
+
actual.basis = updates.basis;
|
|
941
|
+
|
|
942
|
+
format.basis = formatCurrency(updates.basis, currency);
|
|
943
|
+
}
|
|
783
944
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
945
|
+
function calculatePriceData(group, item) {
|
|
946
|
+
const parent = group._parent;
|
|
947
|
+
|
|
948
|
+
const actual = group._dataActual;
|
|
949
|
+
const format = group._dataFormat;
|
|
950
|
+
|
|
951
|
+
const currency = group.currency;
|
|
952
|
+
|
|
953
|
+
let updates;
|
|
789
954
|
|
|
790
|
-
|
|
955
|
+
if (actual.market === null || actual.unrealizedToday === null) {
|
|
956
|
+
const items = group._items;
|
|
957
|
+
|
|
958
|
+
updates = items.reduce((updates, item) => {
|
|
959
|
+
updates.market = updates.market.add(item.data.market);
|
|
960
|
+
updates.unrealizedToday = updates.unrealizedToday.add(item.data.unrealizedToday);
|
|
791
961
|
|
|
792
962
|
return updates;
|
|
793
963
|
}, {
|
|
794
|
-
|
|
964
|
+
market: Decimal.ZERO,
|
|
965
|
+
unrealizedToday: Decimal.ZERO
|
|
795
966
|
});
|
|
967
|
+
} else {
|
|
968
|
+
updates = {
|
|
969
|
+
market: actual.market.add(item.data.marketChange),
|
|
970
|
+
unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
|
|
971
|
+
};
|
|
796
972
|
}
|
|
973
|
+
|
|
974
|
+
if (parent !== null) {
|
|
975
|
+
const parentData = parent._dataActual;
|
|
797
976
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
977
|
+
if (parentData.market !== null && !parentData.market.getIsZero()) {
|
|
978
|
+
updates.marketPercent = updates.market.divide(parentData.market);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
actual.market = updates.market;
|
|
983
|
+
actual.marketPercent = updates.marketPercent;
|
|
984
|
+
actual.unrealizedToday = updates.unrealizedToday;
|
|
985
|
+
|
|
986
|
+
format.market = formatCurrency(updates.market, currency);
|
|
987
|
+
format.marketPercent = formatPercent(updates.unrealizedToday, 2);
|
|
988
|
+
format.unrealizedToday = formatCurrency(updates.unrealizedToday, currency);
|
|
804
989
|
}
|
|
805
990
|
|
|
806
991
|
return PositionGroup;
|
|
807
992
|
})();
|
|
808
993
|
|
|
809
|
-
},{"@barchart/common-js/lang/Currency":
|
|
994
|
+
},{"@barchart/common-js/lang/Currency":11,"@barchart/common-js/lang/Decimal":13,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/formatter":18,"@barchart/common-js/lang/is":19}],6:[function(require,module,exports){
|
|
810
995
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
811
996
|
is = require('@barchart/common-js/lang/is');
|
|
812
997
|
|
|
@@ -856,12 +1041,14 @@ module.exports = (() => {
|
|
|
856
1041
|
return PositionGroupDefinition;
|
|
857
1042
|
})();
|
|
858
1043
|
|
|
859
|
-
},{"@barchart/common-js/lang/assert":
|
|
1044
|
+
},{"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],7:[function(require,module,exports){
|
|
860
1045
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
861
1046
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
862
1047
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
863
1048
|
is = require('@barchart/common-js/lang/is');
|
|
864
1049
|
|
|
1050
|
+
const InstrumentType = require('./../data/InstrumentType');
|
|
1051
|
+
|
|
865
1052
|
module.exports = (() => {
|
|
866
1053
|
'use strict';
|
|
867
1054
|
|
|
@@ -876,22 +1063,19 @@ module.exports = (() => {
|
|
|
876
1063
|
|
|
877
1064
|
this._data = { };
|
|
878
1065
|
|
|
879
|
-
this._data.
|
|
880
|
-
this._data.previous = position.previous || null;
|
|
881
|
-
|
|
882
|
-
const snapshot = this._position.snapshot;
|
|
1066
|
+
this._data.basis = null;
|
|
883
1067
|
|
|
884
|
-
this._data.
|
|
1068
|
+
this._data.currentPrice = null;
|
|
1069
|
+
this._data.previousPrice = null;
|
|
885
1070
|
|
|
886
|
-
|
|
887
|
-
|
|
1071
|
+
this._data.market = null;
|
|
1072
|
+
this._data.marketChange = null;
|
|
1073
|
+
|
|
1074
|
+
this._data.unrealizedToday = null;
|
|
1075
|
+
this._data.unrealizedTodayChange = null;
|
|
888
1076
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
} else {
|
|
892
|
-
market = snapshot.value;
|
|
893
|
-
}
|
|
894
|
-
*/
|
|
1077
|
+
calculateStaticData(this);
|
|
1078
|
+
calculatePriceData(this, null);
|
|
895
1079
|
|
|
896
1080
|
this._priceChangeEvent = new Event(this);
|
|
897
1081
|
}
|
|
@@ -908,9 +1092,13 @@ module.exports = (() => {
|
|
|
908
1092
|
return this._summaries;
|
|
909
1093
|
}
|
|
910
1094
|
|
|
1095
|
+
get data() {
|
|
1096
|
+
return this._data;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
911
1099
|
setPrice(price) {
|
|
912
1100
|
if (this._data.price !== price) {
|
|
913
|
-
this._data.
|
|
1101
|
+
calculatePriceData(this, this._data.currentPrice = price);
|
|
914
1102
|
|
|
915
1103
|
this._priceChangeEvent.fire(this._data);
|
|
916
1104
|
}
|
|
@@ -927,10 +1115,80 @@ module.exports = (() => {
|
|
|
927
1115
|
}
|
|
928
1116
|
}
|
|
929
1117
|
|
|
1118
|
+
function calculateStaticData(item) {
|
|
1119
|
+
const position = item.position;
|
|
1120
|
+
const snapshot = item.position.snapshot;
|
|
1121
|
+
|
|
1122
|
+
const data = item._data;
|
|
1123
|
+
|
|
1124
|
+
data.previousPrice = position.previousPrice || null;
|
|
1125
|
+
|
|
1126
|
+
let basis;
|
|
1127
|
+
|
|
1128
|
+
if (snapshot.basis) {
|
|
1129
|
+
basis = snapshot.basis.opposite();
|
|
1130
|
+
} else {
|
|
1131
|
+
basis = Decimal.ZERO;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
data.basis = basis;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
function calculatePriceData(item, price) {
|
|
1138
|
+
const position = item.position;
|
|
1139
|
+
const snapshot = item.position.snapshot;
|
|
1140
|
+
|
|
1141
|
+
const data = item._data;
|
|
1142
|
+
|
|
1143
|
+
let market;
|
|
1144
|
+
|
|
1145
|
+
if (position.instrument.type === InstrumentType.OTHER) {
|
|
1146
|
+
market = snapshot.value;
|
|
1147
|
+
} else if (position.instrument.type === InstrumentType.CASH) {
|
|
1148
|
+
market = snapshot.open;
|
|
1149
|
+
} else {
|
|
1150
|
+
if (price) {
|
|
1151
|
+
market = snapshot.open.multiply(price);
|
|
1152
|
+
} else {
|
|
1153
|
+
market = snapshot.value;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
let marketChange;
|
|
1158
|
+
|
|
1159
|
+
if (data.market === null) {
|
|
1160
|
+
marketChange = market;
|
|
1161
|
+
} else {
|
|
1162
|
+
marketChange = market.subtract(data.market);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
data.market = market;
|
|
1166
|
+
data.marketChange = marketChange;
|
|
1167
|
+
|
|
1168
|
+
let unrealizedToday;
|
|
1169
|
+
let unrealizedTodayChange;
|
|
1170
|
+
|
|
1171
|
+
if (data.previousPrice && price) {
|
|
1172
|
+
unrealizedToday = market.subtract(snapshot.open.multiply(data.previousPrice));
|
|
1173
|
+
|
|
1174
|
+
if (data.unrealizedToday !== null) {
|
|
1175
|
+
unrealizedTodayChange = unrealizedToday.subtract(data.unrealizedToday);
|
|
1176
|
+
} else {
|
|
1177
|
+
unrealizedTodayChange = unrealizedToday;
|
|
1178
|
+
}
|
|
1179
|
+
} else {
|
|
1180
|
+
unrealizedToday = Decimal.ZERO;
|
|
1181
|
+
unrealizedTodayChange = Decimal.ZERO;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
data.unrealizedToday = unrealizedToday;
|
|
1185
|
+
data.unrealizedTodayChange = unrealizedTodayChange;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
930
1188
|
return PositionItem;
|
|
931
1189
|
})();
|
|
932
1190
|
|
|
933
|
-
},{"@barchart/common-js/lang/Decimal":
|
|
1191
|
+
},{"./../data/InstrumentType":1,"@barchart/common-js/lang/Decimal":13,"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19,"@barchart/common-js/messaging/Event":20}],8:[function(require,module,exports){
|
|
934
1192
|
'use strict';
|
|
935
1193
|
|
|
936
1194
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -1239,7 +1497,7 @@ module.exports = function () {
|
|
|
1239
1497
|
return Tree;
|
|
1240
1498
|
}();
|
|
1241
1499
|
|
|
1242
|
-
},{"./../lang/is":
|
|
1500
|
+
},{"./../lang/is":19}],9:[function(require,module,exports){
|
|
1243
1501
|
'use strict';
|
|
1244
1502
|
|
|
1245
1503
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -1383,7 +1641,7 @@ module.exports = function () {
|
|
|
1383
1641
|
return ComparatorBuilder;
|
|
1384
1642
|
}();
|
|
1385
1643
|
|
|
1386
|
-
},{"./../../lang/assert":
|
|
1644
|
+
},{"./../../lang/assert":17,"./comparators":10}],10:[function(require,module,exports){
|
|
1387
1645
|
'use strict';
|
|
1388
1646
|
|
|
1389
1647
|
var assert = require('./../../lang/assert');
|
|
@@ -1458,7 +1716,7 @@ module.exports = function () {
|
|
|
1458
1716
|
};
|
|
1459
1717
|
}();
|
|
1460
1718
|
|
|
1461
|
-
},{"./../../lang/assert":
|
|
1719
|
+
},{"./../../lang/assert":17}],11:[function(require,module,exports){
|
|
1462
1720
|
'use strict';
|
|
1463
1721
|
|
|
1464
1722
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -1601,7 +1859,7 @@ module.exports = function () {
|
|
|
1601
1859
|
return Currency;
|
|
1602
1860
|
}();
|
|
1603
1861
|
|
|
1604
|
-
},{"./Enum":
|
|
1862
|
+
},{"./Enum":15,"./assert":17,"./is":19}],12:[function(require,module,exports){
|
|
1605
1863
|
'use strict';
|
|
1606
1864
|
|
|
1607
1865
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -2154,7 +2412,7 @@ module.exports = function () {
|
|
|
2154
2412
|
return Day;
|
|
2155
2413
|
}();
|
|
2156
2414
|
|
|
2157
|
-
},{"./../collections/sorting/ComparatorBuilder":
|
|
2415
|
+
},{"./../collections/sorting/ComparatorBuilder":9,"./../collections/sorting/comparators":10,"./assert":17,"./is":19}],13:[function(require,module,exports){
|
|
2158
2416
|
'use strict';
|
|
2159
2417
|
|
|
2160
2418
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -2734,7 +2992,7 @@ module.exports = function () {
|
|
|
2734
2992
|
return Decimal;
|
|
2735
2993
|
}();
|
|
2736
2994
|
|
|
2737
|
-
},{"./Enum":
|
|
2995
|
+
},{"./Enum":15,"./assert":17,"./is":19,"big.js":21}],14:[function(require,module,exports){
|
|
2738
2996
|
'use strict';
|
|
2739
2997
|
|
|
2740
2998
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -2883,7 +3141,7 @@ module.exports = function () {
|
|
|
2883
3141
|
return Disposable;
|
|
2884
3142
|
}();
|
|
2885
3143
|
|
|
2886
|
-
},{"./assert":
|
|
3144
|
+
},{"./assert":17}],15:[function(require,module,exports){
|
|
2887
3145
|
'use strict';
|
|
2888
3146
|
|
|
2889
3147
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -3025,7 +3283,7 @@ module.exports = function () {
|
|
|
3025
3283
|
return Enum;
|
|
3026
3284
|
}();
|
|
3027
3285
|
|
|
3028
|
-
},{"./assert":
|
|
3286
|
+
},{"./assert":17}],16:[function(require,module,exports){
|
|
3029
3287
|
'use strict';
|
|
3030
3288
|
|
|
3031
3289
|
var assert = require('./assert'),
|
|
@@ -3406,7 +3664,7 @@ module.exports = function () {
|
|
|
3406
3664
|
};
|
|
3407
3665
|
}();
|
|
3408
3666
|
|
|
3409
|
-
},{"./assert":
|
|
3667
|
+
},{"./assert":17,"./is":19}],17:[function(require,module,exports){
|
|
3410
3668
|
'use strict';
|
|
3411
3669
|
|
|
3412
3670
|
var is = require('./is');
|
|
@@ -3554,7 +3812,7 @@ module.exports = function () {
|
|
|
3554
3812
|
};
|
|
3555
3813
|
}();
|
|
3556
3814
|
|
|
3557
|
-
},{"./is":
|
|
3815
|
+
},{"./is":19}],18:[function(require,module,exports){
|
|
3558
3816
|
'use strict';
|
|
3559
3817
|
|
|
3560
3818
|
module.exports = function () {
|
|
@@ -3619,7 +3877,7 @@ module.exports = function () {
|
|
|
3619
3877
|
};
|
|
3620
3878
|
}();
|
|
3621
3879
|
|
|
3622
|
-
},{}],
|
|
3880
|
+
},{}],19:[function(require,module,exports){
|
|
3623
3881
|
'use strict';
|
|
3624
3882
|
|
|
3625
3883
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
@@ -3842,7 +4100,7 @@ module.exports = function () {
|
|
|
3842
4100
|
};
|
|
3843
4101
|
}();
|
|
3844
4102
|
|
|
3845
|
-
},{}],
|
|
4103
|
+
},{}],20:[function(require,module,exports){
|
|
3846
4104
|
'use strict';
|
|
3847
4105
|
|
|
3848
4106
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
@@ -4014,7 +4272,7 @@ module.exports = function () {
|
|
|
4014
4272
|
return Event;
|
|
4015
4273
|
}();
|
|
4016
4274
|
|
|
4017
|
-
},{"./../lang/Disposable":
|
|
4275
|
+
},{"./../lang/Disposable":14,"./../lang/assert":17}],21:[function(require,module,exports){
|
|
4018
4276
|
/*
|
|
4019
4277
|
* big.js v5.0.3
|
|
4020
4278
|
* A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
|
|
@@ -4955,7 +5213,7 @@ module.exports = function () {
|
|
|
4955
5213
|
}
|
|
4956
5214
|
})(this);
|
|
4957
5215
|
|
|
4958
|
-
},{}],
|
|
5216
|
+
},{}],22:[function(require,module,exports){
|
|
4959
5217
|
const Day = require('@barchart/common-js/lang/Day'),
|
|
4960
5218
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
4961
5219
|
|
|
@@ -5312,10 +5570,12 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
5312
5570
|
});
|
|
5313
5571
|
});
|
|
5314
5572
|
|
|
5315
|
-
},{"./../../../lib/data/PositionSummaryFrame":
|
|
5573
|
+
},{"./../../../lib/data/PositionSummaryFrame":2,"./../../../lib/data/TransactionType":3,"@barchart/common-js/lang/Day":12,"@barchart/common-js/lang/Decimal":13}],23:[function(require,module,exports){
|
|
5316
5574
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
5317
5575
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
5318
5576
|
|
|
5577
|
+
const InstrumentType = require('./../../../lib/data/InstrumentType');
|
|
5578
|
+
|
|
5319
5579
|
const PositionContainer = require('./../../../lib/processing/PositionContainer'),
|
|
5320
5580
|
PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
|
|
5321
5581
|
|
|
@@ -5330,12 +5590,15 @@ describe('When a position container data is gathered', () => {
|
|
|
5330
5590
|
position: (positionCounter++).toString(),
|
|
5331
5591
|
instrument: {
|
|
5332
5592
|
symbol: {
|
|
5333
|
-
barchart: symbol
|
|
5334
|
-
|
|
5335
|
-
|
|
5593
|
+
barchart: symbol
|
|
5594
|
+
},
|
|
5595
|
+
currency: currency || Currency.USD,
|
|
5596
|
+
type: InstrumentType.EQUITY
|
|
5336
5597
|
},
|
|
5337
5598
|
snapshot: {
|
|
5338
|
-
basis: new Decimal(123)
|
|
5599
|
+
basis: new Decimal(123),
|
|
5600
|
+
value: new Decimal(456),
|
|
5601
|
+
open: new Decimal(1)
|
|
5339
5602
|
}
|
|
5340
5603
|
}
|
|
5341
5604
|
}
|
|
@@ -5410,4 +5673,4 @@ describe('When a position container data is gathered', () => {
|
|
|
5410
5673
|
});
|
|
5411
5674
|
});
|
|
5412
5675
|
|
|
5413
|
-
},{"./../../../lib/processing/PositionContainer":
|
|
5676
|
+
},{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":4,"./../../../lib/processing/PositionGroupDefinition":6,"@barchart/common-js/lang/Currency":11,"@barchart/common-js/lang/Decimal":13}]},{},[22,23]);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
2
2
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
3
3
|
|
|
4
|
+
const InstrumentType = require('./../../../lib/data/InstrumentType');
|
|
5
|
+
|
|
4
6
|
const PositionContainer = require('./../../../lib/processing/PositionContainer'),
|
|
5
7
|
PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
|
|
6
8
|
|
|
@@ -15,12 +17,15 @@ describe('When a position container data is gathered', () => {
|
|
|
15
17
|
position: (positionCounter++).toString(),
|
|
16
18
|
instrument: {
|
|
17
19
|
symbol: {
|
|
18
|
-
barchart: symbol
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
barchart: symbol
|
|
21
|
+
},
|
|
22
|
+
currency: currency || Currency.USD,
|
|
23
|
+
type: InstrumentType.EQUITY
|
|
21
24
|
},
|
|
22
25
|
snapshot: {
|
|
23
|
-
basis: new Decimal(123)
|
|
26
|
+
basis: new Decimal(123),
|
|
27
|
+
value: new Decimal(456),
|
|
28
|
+
open: new Decimal(1)
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
}
|