@barchart/portfolio-api-common 1.0.59 → 1.0.63
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
|
|
|
@@ -132,6 +149,10 @@ module.exports = (() => {
|
|
|
132
149
|
createGroups(this._tree, this._items, this._definitions);
|
|
133
150
|
}
|
|
134
151
|
|
|
152
|
+
get defaultCurrency() {
|
|
153
|
+
return this._defaultCurrency;
|
|
154
|
+
}
|
|
155
|
+
|
|
135
156
|
getSymbols() {
|
|
136
157
|
return Object.keys(this._symbols);
|
|
137
158
|
}
|
|
@@ -142,6 +163,22 @@ module.exports = (() => {
|
|
|
142
163
|
}
|
|
143
164
|
}
|
|
144
165
|
|
|
166
|
+
getCurrencySymbols() {
|
|
167
|
+
const codes = Object.keys(this._currencies);
|
|
168
|
+
|
|
169
|
+
return codes.reduce((symbols, code) => {
|
|
170
|
+
if (code !== this._defaultCurrency) {
|
|
171
|
+
symbols.push(`^${this._defaultCurrency}${code}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return symbols;
|
|
175
|
+
}, [ ]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
setExchangeRage(symbol, price) {
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
145
182
|
getGroup(keys) {
|
|
146
183
|
const node = keys.reduce((tree, key) => {
|
|
147
184
|
tree = tree.findChild(group => group.description === key);
|
|
@@ -46,11 +46,12 @@ module.exports = (() => {
|
|
|
46
46
|
this._dataFormat.current = null;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
calculatePriceData(this, item);
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
calculateStaticData(this);
|
|
54
|
+
calculatePriceData(this);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
get items() {
|
|
@@ -85,21 +86,17 @@ module.exports = (() => {
|
|
|
85
86
|
function calculateStaticData(group) {
|
|
86
87
|
const items = group._items;
|
|
87
88
|
|
|
88
|
-
const raw = group._dataRaw;
|
|
89
|
-
const formatted = group._dataFormat;
|
|
90
|
-
|
|
91
89
|
let updates;
|
|
92
90
|
|
|
93
91
|
if (group.single) {
|
|
94
92
|
const item = items[0];
|
|
95
93
|
|
|
94
|
+
updates = { };
|
|
95
|
+
|
|
96
96
|
updates.basis = item.basis;
|
|
97
97
|
} else {
|
|
98
98
|
updates = items.reduce(function(updates, item) {
|
|
99
|
-
|
|
100
|
-
const snapshot = item.position.snapshot;
|
|
101
|
-
|
|
102
|
-
updates.basis = updates.basis.add(snapshot.basis);
|
|
99
|
+
updates.basis = updates.basis.add(item.data.basis);
|
|
103
100
|
|
|
104
101
|
return updates;
|
|
105
102
|
}, {
|
|
@@ -107,12 +104,39 @@ module.exports = (() => {
|
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
106
|
|
|
107
|
+
const raw = group._dataRaw;
|
|
108
|
+
const formatted = group._dataFormat;
|
|
109
|
+
|
|
110
110
|
raw.basis = updates.basis;
|
|
111
111
|
formatted.basis = format(updates.basis, Currency.USD);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
function
|
|
114
|
+
function calculatePriceData(group) {
|
|
115
|
+
const items = group._items;
|
|
116
|
+
|
|
117
|
+
let updates;
|
|
118
|
+
|
|
119
|
+
if (group.single) {
|
|
120
|
+
updates = { };
|
|
121
|
+
|
|
122
|
+
let item = items[0];
|
|
123
|
+
|
|
124
|
+
updates.market = item.market;
|
|
125
|
+
} else {
|
|
126
|
+
updates = items.reduce(function(updates, item) {
|
|
127
|
+
updates.market = updates.market.add(item.data.market);
|
|
128
|
+
|
|
129
|
+
return updates;
|
|
130
|
+
}, {
|
|
131
|
+
market: Decimal.ZERO
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const raw = group._dataRaw;
|
|
136
|
+
const formatted = group._dataFormat;
|
|
115
137
|
|
|
138
|
+
raw.market = updates.market;
|
|
139
|
+
formatted.market = format(updates.market, Currency.USD);
|
|
116
140
|
}
|
|
117
141
|
|
|
118
142
|
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
|
|
|
@@ -18,21 +20,11 @@ module.exports = (() => {
|
|
|
18
20
|
this._data = { };
|
|
19
21
|
|
|
20
22
|
this._data.current = null;
|
|
21
|
-
this._data.previous =
|
|
22
|
-
|
|
23
|
-
const snapshot = this._position.snapshot;
|
|
24
|
-
|
|
25
|
-
this._data.basis = snapshot.basis || Decimal.ZERO;
|
|
26
|
-
|
|
27
|
-
/*
|
|
28
|
-
let market;
|
|
23
|
+
this._data.previous = null;
|
|
24
|
+
this._data.basis = null;
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} else {
|
|
33
|
-
market = snapshot.value;
|
|
34
|
-
}
|
|
35
|
-
*/
|
|
26
|
+
calculateStaticData(this);
|
|
27
|
+
calculatePriceData(this, null);
|
|
36
28
|
|
|
37
29
|
this._priceChangeEvent = new Event(this);
|
|
38
30
|
}
|
|
@@ -49,9 +41,13 @@ module.exports = (() => {
|
|
|
49
41
|
return this._summaries;
|
|
50
42
|
}
|
|
51
43
|
|
|
44
|
+
get data() {
|
|
45
|
+
return this._data;
|
|
46
|
+
}
|
|
47
|
+
|
|
52
48
|
setPrice(price) {
|
|
53
49
|
if (this._data.price !== price) {
|
|
54
|
-
this._data.price = price;
|
|
50
|
+
calculatePriceData(this, this._data.price = price);
|
|
55
51
|
|
|
56
52
|
this._priceChangeEvent.fire(this._data);
|
|
57
53
|
}
|
|
@@ -68,5 +64,47 @@ module.exports = (() => {
|
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
|
|
67
|
+
function calculateStaticData(item) {
|
|
68
|
+
const position = item.position;
|
|
69
|
+
const snapshot = item.position.snapshot;
|
|
70
|
+
|
|
71
|
+
const data = item._data;
|
|
72
|
+
|
|
73
|
+
data.previous = position.previous || null;
|
|
74
|
+
|
|
75
|
+
let basis;
|
|
76
|
+
|
|
77
|
+
if (snapshot.basis) {
|
|
78
|
+
basis = snapshot.basis.opposite();
|
|
79
|
+
} else {
|
|
80
|
+
basis = Decimal.ZERO;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
data.basis = basis;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function calculatePriceData(item, price) {
|
|
87
|
+
const position = item.position;
|
|
88
|
+
const snapshot = item.position.snapshot;
|
|
89
|
+
|
|
90
|
+
const data = item._data;
|
|
91
|
+
|
|
92
|
+
let market;
|
|
93
|
+
|
|
94
|
+
if (position.instrument.type === InstrumentType.OTHER) {
|
|
95
|
+
market = snapshot.value;
|
|
96
|
+
} else if (position.instrument.type === InstrumentType.CASH) {
|
|
97
|
+
market = snapshot.open;
|
|
98
|
+
} else {
|
|
99
|
+
if (price) {
|
|
100
|
+
market = snapshot.open.multiply(price);
|
|
101
|
+
} else {
|
|
102
|
+
market = snapshot.value;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
data.market = market;
|
|
107
|
+
}
|
|
108
|
+
|
|
71
109
|
return PositionItem;
|
|
72
110
|
})();
|
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
|
|
|
@@ -647,6 +755,10 @@ module.exports = (() => {
|
|
|
647
755
|
createGroups(this._tree, this._items, this._definitions);
|
|
648
756
|
}
|
|
649
757
|
|
|
758
|
+
get defaultCurrency() {
|
|
759
|
+
return this._defaultCurrency;
|
|
760
|
+
}
|
|
761
|
+
|
|
650
762
|
getSymbols() {
|
|
651
763
|
return Object.keys(this._symbols);
|
|
652
764
|
}
|
|
@@ -657,6 +769,22 @@ module.exports = (() => {
|
|
|
657
769
|
}
|
|
658
770
|
}
|
|
659
771
|
|
|
772
|
+
getCurrencySymbols() {
|
|
773
|
+
const codes = Object.keys(this._currencies);
|
|
774
|
+
|
|
775
|
+
return codes.reduce((symbols, code) => {
|
|
776
|
+
if (code !== this._defaultCurrency) {
|
|
777
|
+
symbols.push(`^${this._defaultCurrency}${code}`);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
return symbols;
|
|
781
|
+
}, [ ]);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
setExchangeRage(symbol, price) {
|
|
785
|
+
|
|
786
|
+
}
|
|
787
|
+
|
|
660
788
|
getGroup(keys) {
|
|
661
789
|
const node = keys.reduce((tree, key) => {
|
|
662
790
|
tree = tree.findChild(group => group.description === key);
|
|
@@ -685,7 +813,7 @@ module.exports = (() => {
|
|
|
685
813
|
return PositionContainer;
|
|
686
814
|
})();
|
|
687
815
|
|
|
688
|
-
},{"
|
|
816
|
+
},{"./../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
817
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
690
818
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
691
819
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
@@ -734,11 +862,12 @@ module.exports = (() => {
|
|
|
734
862
|
this._dataFormat.current = null;
|
|
735
863
|
}
|
|
736
864
|
|
|
737
|
-
|
|
865
|
+
calculatePriceData(this, item);
|
|
738
866
|
});
|
|
739
867
|
});
|
|
740
868
|
|
|
741
869
|
calculateStaticData(this);
|
|
870
|
+
calculatePriceData(this);
|
|
742
871
|
}
|
|
743
872
|
|
|
744
873
|
get items() {
|
|
@@ -773,21 +902,17 @@ module.exports = (() => {
|
|
|
773
902
|
function calculateStaticData(group) {
|
|
774
903
|
const items = group._items;
|
|
775
904
|
|
|
776
|
-
const raw = group._dataRaw;
|
|
777
|
-
const formatted = group._dataFormat;
|
|
778
|
-
|
|
779
905
|
let updates;
|
|
780
906
|
|
|
781
907
|
if (group.single) {
|
|
782
908
|
const item = items[0];
|
|
783
909
|
|
|
910
|
+
updates = { };
|
|
911
|
+
|
|
784
912
|
updates.basis = item.basis;
|
|
785
913
|
} else {
|
|
786
914
|
updates = items.reduce(function(updates, item) {
|
|
787
|
-
|
|
788
|
-
const snapshot = item.position.snapshot;
|
|
789
|
-
|
|
790
|
-
updates.basis = updates.basis.add(snapshot.basis);
|
|
915
|
+
updates.basis = updates.basis.add(item.data.basis);
|
|
791
916
|
|
|
792
917
|
return updates;
|
|
793
918
|
}, {
|
|
@@ -795,18 +920,45 @@ module.exports = (() => {
|
|
|
795
920
|
});
|
|
796
921
|
}
|
|
797
922
|
|
|
923
|
+
const raw = group._dataRaw;
|
|
924
|
+
const formatted = group._dataFormat;
|
|
925
|
+
|
|
798
926
|
raw.basis = updates.basis;
|
|
799
927
|
formatted.basis = format(updates.basis, Currency.USD);
|
|
800
928
|
}
|
|
801
929
|
|
|
802
|
-
function
|
|
930
|
+
function calculatePriceData(group) {
|
|
931
|
+
const items = group._items;
|
|
932
|
+
|
|
933
|
+
let updates;
|
|
934
|
+
|
|
935
|
+
if (group.single) {
|
|
936
|
+
updates = { };
|
|
937
|
+
|
|
938
|
+
let item = items[0];
|
|
939
|
+
|
|
940
|
+
updates.market = item.market;
|
|
941
|
+
} else {
|
|
942
|
+
updates = items.reduce(function(updates, item) {
|
|
943
|
+
updates.market = updates.market.add(item.data.market);
|
|
803
944
|
|
|
945
|
+
return updates;
|
|
946
|
+
}, {
|
|
947
|
+
market: Decimal.ZERO
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
const raw = group._dataRaw;
|
|
952
|
+
const formatted = group._dataFormat;
|
|
953
|
+
|
|
954
|
+
raw.market = updates.market;
|
|
955
|
+
formatted.market = format(updates.market, Currency.USD);
|
|
804
956
|
}
|
|
805
957
|
|
|
806
958
|
return PositionGroup;
|
|
807
959
|
})();
|
|
808
960
|
|
|
809
|
-
},{"@barchart/common-js/lang/Currency":
|
|
961
|
+
},{"@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
962
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
811
963
|
is = require('@barchart/common-js/lang/is');
|
|
812
964
|
|
|
@@ -856,12 +1008,14 @@ module.exports = (() => {
|
|
|
856
1008
|
return PositionGroupDefinition;
|
|
857
1009
|
})();
|
|
858
1010
|
|
|
859
|
-
},{"@barchart/common-js/lang/assert":
|
|
1011
|
+
},{"@barchart/common-js/lang/assert":17,"@barchart/common-js/lang/is":19}],7:[function(require,module,exports){
|
|
860
1012
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
861
1013
|
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
862
1014
|
Event = require('@barchart/common-js/messaging/Event'),
|
|
863
1015
|
is = require('@barchart/common-js/lang/is');
|
|
864
1016
|
|
|
1017
|
+
const InstrumentType = require('./../data/InstrumentType');
|
|
1018
|
+
|
|
865
1019
|
module.exports = (() => {
|
|
866
1020
|
'use strict';
|
|
867
1021
|
|
|
@@ -877,21 +1031,11 @@ module.exports = (() => {
|
|
|
877
1031
|
this._data = { };
|
|
878
1032
|
|
|
879
1033
|
this._data.current = null;
|
|
880
|
-
this._data.previous =
|
|
1034
|
+
this._data.previous = null;
|
|
1035
|
+
this._data.basis = null;
|
|
881
1036
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
this._data.basis = snapshot.basis || Decimal.ZERO;
|
|
885
|
-
|
|
886
|
-
/*
|
|
887
|
-
let market;
|
|
888
|
-
|
|
889
|
-
if (position.previous) {
|
|
890
|
-
market = snapshot.open.multiply(position.previous);
|
|
891
|
-
} else {
|
|
892
|
-
market = snapshot.value;
|
|
893
|
-
}
|
|
894
|
-
*/
|
|
1037
|
+
calculateStaticData(this);
|
|
1038
|
+
calculatePriceData(this, null);
|
|
895
1039
|
|
|
896
1040
|
this._priceChangeEvent = new Event(this);
|
|
897
1041
|
}
|
|
@@ -908,9 +1052,13 @@ module.exports = (() => {
|
|
|
908
1052
|
return this._summaries;
|
|
909
1053
|
}
|
|
910
1054
|
|
|
1055
|
+
get data() {
|
|
1056
|
+
return this._data;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
911
1059
|
setPrice(price) {
|
|
912
1060
|
if (this._data.price !== price) {
|
|
913
|
-
this._data.price = price;
|
|
1061
|
+
calculatePriceData(this, this._data.price = price);
|
|
914
1062
|
|
|
915
1063
|
this._priceChangeEvent.fire(this._data);
|
|
916
1064
|
}
|
|
@@ -927,10 +1075,52 @@ module.exports = (() => {
|
|
|
927
1075
|
}
|
|
928
1076
|
}
|
|
929
1077
|
|
|
1078
|
+
function calculateStaticData(item) {
|
|
1079
|
+
const position = item.position;
|
|
1080
|
+
const snapshot = item.position.snapshot;
|
|
1081
|
+
|
|
1082
|
+
const data = item._data;
|
|
1083
|
+
|
|
1084
|
+
data.previous = position.previous || null;
|
|
1085
|
+
|
|
1086
|
+
let basis;
|
|
1087
|
+
|
|
1088
|
+
if (snapshot.basis) {
|
|
1089
|
+
basis = snapshot.basis.opposite();
|
|
1090
|
+
} else {
|
|
1091
|
+
basis = Decimal.ZERO;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
data.basis = basis;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
function calculatePriceData(item, price) {
|
|
1098
|
+
const position = item.position;
|
|
1099
|
+
const snapshot = item.position.snapshot;
|
|
1100
|
+
|
|
1101
|
+
const data = item._data;
|
|
1102
|
+
|
|
1103
|
+
let market;
|
|
1104
|
+
|
|
1105
|
+
if (position.instrument.type === InstrumentType.OTHER) {
|
|
1106
|
+
market = snapshot.value;
|
|
1107
|
+
} else if (position.instrument.type === InstrumentType.CASH) {
|
|
1108
|
+
market = snapshot.open;
|
|
1109
|
+
} else {
|
|
1110
|
+
if (price) {
|
|
1111
|
+
market = snapshot.open.multiply(price);
|
|
1112
|
+
} else {
|
|
1113
|
+
market = snapshot.value;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
data.market = market;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
930
1120
|
return PositionItem;
|
|
931
1121
|
})();
|
|
932
1122
|
|
|
933
|
-
},{"@barchart/common-js/lang/Decimal":
|
|
1123
|
+
},{"./../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
1124
|
'use strict';
|
|
935
1125
|
|
|
936
1126
|
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 +1429,7 @@ module.exports = function () {
|
|
|
1239
1429
|
return Tree;
|
|
1240
1430
|
}();
|
|
1241
1431
|
|
|
1242
|
-
},{"./../lang/is":
|
|
1432
|
+
},{"./../lang/is":19}],9:[function(require,module,exports){
|
|
1243
1433
|
'use strict';
|
|
1244
1434
|
|
|
1245
1435
|
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 +1573,7 @@ module.exports = function () {
|
|
|
1383
1573
|
return ComparatorBuilder;
|
|
1384
1574
|
}();
|
|
1385
1575
|
|
|
1386
|
-
},{"./../../lang/assert":
|
|
1576
|
+
},{"./../../lang/assert":17,"./comparators":10}],10:[function(require,module,exports){
|
|
1387
1577
|
'use strict';
|
|
1388
1578
|
|
|
1389
1579
|
var assert = require('./../../lang/assert');
|
|
@@ -1458,7 +1648,7 @@ module.exports = function () {
|
|
|
1458
1648
|
};
|
|
1459
1649
|
}();
|
|
1460
1650
|
|
|
1461
|
-
},{"./../../lang/assert":
|
|
1651
|
+
},{"./../../lang/assert":17}],11:[function(require,module,exports){
|
|
1462
1652
|
'use strict';
|
|
1463
1653
|
|
|
1464
1654
|
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 +1791,7 @@ module.exports = function () {
|
|
|
1601
1791
|
return Currency;
|
|
1602
1792
|
}();
|
|
1603
1793
|
|
|
1604
|
-
},{"./Enum":
|
|
1794
|
+
},{"./Enum":15,"./assert":17,"./is":19}],12:[function(require,module,exports){
|
|
1605
1795
|
'use strict';
|
|
1606
1796
|
|
|
1607
1797
|
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 +2344,7 @@ module.exports = function () {
|
|
|
2154
2344
|
return Day;
|
|
2155
2345
|
}();
|
|
2156
2346
|
|
|
2157
|
-
},{"./../collections/sorting/ComparatorBuilder":
|
|
2347
|
+
},{"./../collections/sorting/ComparatorBuilder":9,"./../collections/sorting/comparators":10,"./assert":17,"./is":19}],13:[function(require,module,exports){
|
|
2158
2348
|
'use strict';
|
|
2159
2349
|
|
|
2160
2350
|
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 +2924,7 @@ module.exports = function () {
|
|
|
2734
2924
|
return Decimal;
|
|
2735
2925
|
}();
|
|
2736
2926
|
|
|
2737
|
-
},{"./Enum":
|
|
2927
|
+
},{"./Enum":15,"./assert":17,"./is":19,"big.js":21}],14:[function(require,module,exports){
|
|
2738
2928
|
'use strict';
|
|
2739
2929
|
|
|
2740
2930
|
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 +3073,7 @@ module.exports = function () {
|
|
|
2883
3073
|
return Disposable;
|
|
2884
3074
|
}();
|
|
2885
3075
|
|
|
2886
|
-
},{"./assert":
|
|
3076
|
+
},{"./assert":17}],15:[function(require,module,exports){
|
|
2887
3077
|
'use strict';
|
|
2888
3078
|
|
|
2889
3079
|
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 +3215,7 @@ module.exports = function () {
|
|
|
3025
3215
|
return Enum;
|
|
3026
3216
|
}();
|
|
3027
3217
|
|
|
3028
|
-
},{"./assert":
|
|
3218
|
+
},{"./assert":17}],16:[function(require,module,exports){
|
|
3029
3219
|
'use strict';
|
|
3030
3220
|
|
|
3031
3221
|
var assert = require('./assert'),
|
|
@@ -3406,7 +3596,7 @@ module.exports = function () {
|
|
|
3406
3596
|
};
|
|
3407
3597
|
}();
|
|
3408
3598
|
|
|
3409
|
-
},{"./assert":
|
|
3599
|
+
},{"./assert":17,"./is":19}],17:[function(require,module,exports){
|
|
3410
3600
|
'use strict';
|
|
3411
3601
|
|
|
3412
3602
|
var is = require('./is');
|
|
@@ -3554,7 +3744,7 @@ module.exports = function () {
|
|
|
3554
3744
|
};
|
|
3555
3745
|
}();
|
|
3556
3746
|
|
|
3557
|
-
},{"./is":
|
|
3747
|
+
},{"./is":19}],18:[function(require,module,exports){
|
|
3558
3748
|
'use strict';
|
|
3559
3749
|
|
|
3560
3750
|
module.exports = function () {
|
|
@@ -3619,7 +3809,7 @@ module.exports = function () {
|
|
|
3619
3809
|
};
|
|
3620
3810
|
}();
|
|
3621
3811
|
|
|
3622
|
-
},{}],
|
|
3812
|
+
},{}],19:[function(require,module,exports){
|
|
3623
3813
|
'use strict';
|
|
3624
3814
|
|
|
3625
3815
|
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 +4032,7 @@ module.exports = function () {
|
|
|
3842
4032
|
};
|
|
3843
4033
|
}();
|
|
3844
4034
|
|
|
3845
|
-
},{}],
|
|
4035
|
+
},{}],20:[function(require,module,exports){
|
|
3846
4036
|
'use strict';
|
|
3847
4037
|
|
|
3848
4038
|
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 +4204,7 @@ module.exports = function () {
|
|
|
4014
4204
|
return Event;
|
|
4015
4205
|
}();
|
|
4016
4206
|
|
|
4017
|
-
},{"./../lang/Disposable":
|
|
4207
|
+
},{"./../lang/Disposable":14,"./../lang/assert":17}],21:[function(require,module,exports){
|
|
4018
4208
|
/*
|
|
4019
4209
|
* big.js v5.0.3
|
|
4020
4210
|
* A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
|
|
@@ -4955,7 +5145,7 @@ module.exports = function () {
|
|
|
4955
5145
|
}
|
|
4956
5146
|
})(this);
|
|
4957
5147
|
|
|
4958
|
-
},{}],
|
|
5148
|
+
},{}],22:[function(require,module,exports){
|
|
4959
5149
|
const Day = require('@barchart/common-js/lang/Day'),
|
|
4960
5150
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
4961
5151
|
|
|
@@ -5312,10 +5502,12 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
5312
5502
|
});
|
|
5313
5503
|
});
|
|
5314
5504
|
|
|
5315
|
-
},{"./../../../lib/data/PositionSummaryFrame":
|
|
5505
|
+
},{"./../../../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
5506
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
5317
5507
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
5318
5508
|
|
|
5509
|
+
const InstrumentType = require('./../../../lib/data/InstrumentType');
|
|
5510
|
+
|
|
5319
5511
|
const PositionContainer = require('./../../../lib/processing/PositionContainer'),
|
|
5320
5512
|
PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
|
|
5321
5513
|
|
|
@@ -5330,12 +5522,15 @@ describe('When a position container data is gathered', () => {
|
|
|
5330
5522
|
position: (positionCounter++).toString(),
|
|
5331
5523
|
instrument: {
|
|
5332
5524
|
symbol: {
|
|
5333
|
-
barchart: symbol
|
|
5334
|
-
|
|
5335
|
-
|
|
5525
|
+
barchart: symbol
|
|
5526
|
+
},
|
|
5527
|
+
currency: currency || Currency.USD,
|
|
5528
|
+
type: InstrumentType.EQUITY
|
|
5336
5529
|
},
|
|
5337
5530
|
snapshot: {
|
|
5338
|
-
basis: new Decimal(123)
|
|
5531
|
+
basis: new Decimal(123),
|
|
5532
|
+
value: new Decimal(456),
|
|
5533
|
+
open: new Decimal(1)
|
|
5339
5534
|
}
|
|
5340
5535
|
}
|
|
5341
5536
|
}
|
|
@@ -5410,4 +5605,4 @@ describe('When a position container data is gathered', () => {
|
|
|
5410
5605
|
});
|
|
5411
5606
|
});
|
|
5412
5607
|
|
|
5413
|
-
},{"./../../../lib/processing/PositionContainer":
|
|
5608
|
+
},{"./../../../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
|
}
|