@barchart/portfolio-api-common 1.0.204 → 1.0.208
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/api/failures/PortfolioFailureType.js +1 -1
- package/lib/data/InstrumentType.js +46 -5
- package/lib/formatters/TransactionFormatter.js +2 -1
- package/lib/processing/PositionContainer.js +17 -0
- package/lib/processing/PositionGroup.js +43 -0
- package/package.json +3 -2
- package/test/SpecRunner.js +334 -11
|
@@ -71,7 +71,7 @@ module.exports = (() => {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const positionCreateFailedNoPortfolio = new FailureType('
|
|
74
|
+
const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The referenced portfolio does not exist. Has it been deleted?');
|
|
75
75
|
|
|
76
76
|
const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to create transaction, because the transaction date is out-of-sequence. In other words, it would occur before an existing transaction. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
77
77
|
const transactionCreateFailedDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH', 'Unable to create transaction, because the position direction would be switched (from long to short or vice versa). Please close the position (to a zero balance) first, then enter a second transaction.');
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const uuid = require('uuid');
|
|
2
|
+
|
|
1
3
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
4
|
Enum = require('@barchart/common-js/lang/Enum');
|
|
3
5
|
|
|
@@ -16,16 +18,19 @@ module.exports = (() => {
|
|
|
16
18
|
* @param {Boolean} usesSymbols
|
|
17
19
|
*/
|
|
18
20
|
class InstrumentType extends Enum {
|
|
19
|
-
constructor(code, description, alternateDescription, canReinvest, usesSymbols) {
|
|
21
|
+
constructor(code, description, alternateDescription, canReinvest, usesSymbols, generator) {
|
|
20
22
|
super(code, description);
|
|
21
23
|
|
|
22
24
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
23
25
|
assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
|
|
24
26
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
27
|
+
assert.argumentIsRequired(generator, 'generator', Function);
|
|
25
28
|
|
|
26
29
|
this._alternateDescription = alternateDescription;
|
|
27
30
|
this._canReinvest = canReinvest;
|
|
28
31
|
this._usesSymbols = usesSymbols;
|
|
32
|
+
|
|
33
|
+
this._generator = generator;
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
/**
|
|
@@ -58,6 +63,23 @@ module.exports = (() => {
|
|
|
58
63
|
return this._usesSymbols;
|
|
59
64
|
}
|
|
60
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Generates an identifier for the instrument.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
* @param {Object} instrument
|
|
71
|
+
* @returns {String}
|
|
72
|
+
*/
|
|
73
|
+
generateIdentifier(instrument) {
|
|
74
|
+
assert.argumentIsRequired(instrument, 'instrument');
|
|
75
|
+
|
|
76
|
+
if (instrument.type !== this) {
|
|
77
|
+
throw new Error('Unable to generate instrument identifier for incompatible type.');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return this._generator(instrument);
|
|
81
|
+
}
|
|
82
|
+
|
|
61
83
|
/**
|
|
62
84
|
* Cash.
|
|
63
85
|
*
|
|
@@ -102,15 +124,34 @@ module.exports = (() => {
|
|
|
102
124
|
return other;
|
|
103
125
|
}
|
|
104
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Generates an identifier for the instrument.
|
|
129
|
+
*
|
|
130
|
+
* @static
|
|
131
|
+
* @public
|
|
132
|
+
* @param {Object} instrument
|
|
133
|
+
* @returns {String}
|
|
134
|
+
*/
|
|
135
|
+
static generateIdentifier(instrument) {
|
|
136
|
+
return map[instrument.type.code].generateIdentifier(instrument);
|
|
137
|
+
}
|
|
138
|
+
|
|
105
139
|
toString() {
|
|
106
140
|
return '[InstrumentType]';
|
|
107
141
|
}
|
|
108
142
|
}
|
|
109
143
|
|
|
110
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false);
|
|
111
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true);
|
|
112
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, true);
|
|
113
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false);
|
|
144
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
145
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
146
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
147
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
148
|
+
|
|
149
|
+
const map = { };
|
|
150
|
+
|
|
151
|
+
map[cash.code] = cash;
|
|
152
|
+
map[equity.code] = equity;
|
|
153
|
+
map[fund.code] = fund;
|
|
154
|
+
map[other.code] = other;
|
|
114
155
|
|
|
115
156
|
return InstrumentType;
|
|
116
157
|
})();
|
|
@@ -142,6 +142,8 @@ module.exports = (() => {
|
|
|
142
142
|
|
|
143
143
|
return map;
|
|
144
144
|
}, { });
|
|
145
|
+
|
|
146
|
+
Object.keys(this._portfolios).forEach(key => updateEmptyPortfolioGroups.call(this, this._portfolios[key]));
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
/**
|
|
@@ -203,6 +205,8 @@ module.exports = (() => {
|
|
|
203
205
|
});
|
|
204
206
|
}
|
|
205
207
|
});
|
|
208
|
+
|
|
209
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
|
|
@@ -218,6 +222,8 @@ module.exports = (() => {
|
|
|
218
222
|
|
|
219
223
|
this.startTransaction(() => {
|
|
220
224
|
getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => item.updatePortfolio(portfolio));
|
|
225
|
+
|
|
226
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
221
227
|
});
|
|
222
228
|
}
|
|
223
229
|
|
|
@@ -754,6 +760,17 @@ module.exports = (() => {
|
|
|
754
760
|
});
|
|
755
761
|
}
|
|
756
762
|
|
|
763
|
+
|
|
764
|
+
function updateEmptyPortfolioGroups(portfolio) {
|
|
765
|
+
Object.keys(this._trees).forEach((key) => {
|
|
766
|
+
this._trees[key].walk((group) => {
|
|
767
|
+
if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) && group.getIsEmpty()) {
|
|
768
|
+
group.updatePortfolio(portfolio);
|
|
769
|
+
}
|
|
770
|
+
}, true, false);
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
|
|
757
774
|
function getPositionItemsForPortfolio(items, portfolio) {
|
|
758
775
|
return items.reduce((positionItems, item) => {
|
|
759
776
|
if (item.position.portfolio === portfolio) {
|
|
@@ -11,6 +11,9 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
11
11
|
|
|
12
12
|
const InstrumentType = require('./../data/InstrumentType');
|
|
13
13
|
|
|
14
|
+
const PositionLevelDefinition = require('./definitions/PositionLevelDefinition'),
|
|
15
|
+
PositionLevelType = require('./definitions/PositionLevelType');
|
|
16
|
+
|
|
14
17
|
module.exports = (() => {
|
|
15
18
|
'use strict';
|
|
16
19
|
|
|
@@ -354,6 +357,36 @@ module.exports = (() => {
|
|
|
354
357
|
}
|
|
355
358
|
}
|
|
356
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Updates the portfolio data. For example, a portfolio's name might change. This
|
|
362
|
+
* function only affects {@link PositionLevelType.PORTFOLIO} groups.
|
|
363
|
+
*
|
|
364
|
+
* @public
|
|
365
|
+
* @param {Object} portfolio
|
|
366
|
+
*/
|
|
367
|
+
updatePortfolio(portfolio) {
|
|
368
|
+
if (this._definition.type !== PositionLevelType.PORTFOLIO || this._key !== PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) || !this.getIsEmpty()) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const descriptionSelector = this._definition.descriptionSelector;
|
|
373
|
+
|
|
374
|
+
this._description = descriptionSelector(this._items[0]);
|
|
375
|
+
|
|
376
|
+
this._dataActual.description = this._description;
|
|
377
|
+
this._dataFormat.description = this._description;
|
|
378
|
+
|
|
379
|
+
let portfolioType;
|
|
380
|
+
|
|
381
|
+
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
382
|
+
portfolioType = portfolio.miscellany.data.type.value;
|
|
383
|
+
} else {
|
|
384
|
+
portfolioType = null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
this._dataFormat.portfolioType = portfolioType;
|
|
388
|
+
}
|
|
389
|
+
|
|
357
390
|
/**
|
|
358
391
|
* Causes all aggregated data to be recalculated (assuming the group has not
|
|
359
392
|
* been suspended).
|
|
@@ -381,6 +414,16 @@ module.exports = (() => {
|
|
|
381
414
|
calculateMarketPercent(this, this._container.getForexQuotes(), true);
|
|
382
415
|
}
|
|
383
416
|
|
|
417
|
+
/**
|
|
418
|
+
* Indicates if the group contains any items.
|
|
419
|
+
*
|
|
420
|
+
* @public
|
|
421
|
+
* @returns {boolean}
|
|
422
|
+
*/
|
|
423
|
+
getIsEmpty() {
|
|
424
|
+
return this._items.length === 0;
|
|
425
|
+
}
|
|
426
|
+
|
|
384
427
|
/**
|
|
385
428
|
* Adds an observer for change in the market percentage of the group.
|
|
386
429
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barchart/portfolio-api-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.208",
|
|
4
4
|
"description": "Common classes used by the Portfolio system",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bryan Ingle",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@barchart/common-js": "~3.2.0"
|
|
12
|
+
"@barchart/common-js": "~3.2.0",
|
|
13
|
+
"uuid": "3.1.0"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"babel-core": "^6.26.0",
|
package/test/SpecRunner.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
|
2
|
+
const uuid = require('uuid');
|
|
3
|
+
|
|
2
4
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
3
5
|
Enum = require('@barchart/common-js/lang/Enum');
|
|
4
6
|
|
|
@@ -17,16 +19,19 @@ module.exports = (() => {
|
|
|
17
19
|
* @param {Boolean} usesSymbols
|
|
18
20
|
*/
|
|
19
21
|
class InstrumentType extends Enum {
|
|
20
|
-
constructor(code, description, alternateDescription, canReinvest, usesSymbols) {
|
|
22
|
+
constructor(code, description, alternateDescription, canReinvest, usesSymbols, generator) {
|
|
21
23
|
super(code, description);
|
|
22
24
|
|
|
23
25
|
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
24
26
|
assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
|
|
25
27
|
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
28
|
+
assert.argumentIsRequired(generator, 'generator', Function);
|
|
26
29
|
|
|
27
30
|
this._alternateDescription = alternateDescription;
|
|
28
31
|
this._canReinvest = canReinvest;
|
|
29
32
|
this._usesSymbols = usesSymbols;
|
|
33
|
+
|
|
34
|
+
this._generator = generator;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
/**
|
|
@@ -59,6 +64,23 @@ module.exports = (() => {
|
|
|
59
64
|
return this._usesSymbols;
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Generates an identifier for the instrument.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
* @param {Object} instrument
|
|
72
|
+
* @returns {String}
|
|
73
|
+
*/
|
|
74
|
+
generateIdentifier(instrument) {
|
|
75
|
+
assert.argumentIsRequired(instrument, 'instrument');
|
|
76
|
+
|
|
77
|
+
if (instrument.type !== this) {
|
|
78
|
+
throw new Error('Unable to generate instrument identifier for incompatible type.');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return this._generator(instrument);
|
|
82
|
+
}
|
|
83
|
+
|
|
62
84
|
/**
|
|
63
85
|
* Cash.
|
|
64
86
|
*
|
|
@@ -103,20 +125,39 @@ module.exports = (() => {
|
|
|
103
125
|
return other;
|
|
104
126
|
}
|
|
105
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Generates an identifier for the instrument.
|
|
130
|
+
*
|
|
131
|
+
* @static
|
|
132
|
+
* @public
|
|
133
|
+
* @param {Object} instrument
|
|
134
|
+
* @returns {String}
|
|
135
|
+
*/
|
|
136
|
+
static generateIdentifier(instrument) {
|
|
137
|
+
return map[instrument.type.code].generateIdentifier(instrument);
|
|
138
|
+
}
|
|
139
|
+
|
|
106
140
|
toString() {
|
|
107
141
|
return '[InstrumentType]';
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
144
|
|
|
111
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false);
|
|
112
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true);
|
|
113
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, true);
|
|
114
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false, false);
|
|
145
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
146
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
147
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
148
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
|
|
149
|
+
|
|
150
|
+
const map = { };
|
|
151
|
+
|
|
152
|
+
map[cash.code] = cash;
|
|
153
|
+
map[equity.code] = equity;
|
|
154
|
+
map[fund.code] = fund;
|
|
155
|
+
map[other.code] = other;
|
|
115
156
|
|
|
116
157
|
return InstrumentType;
|
|
117
158
|
})();
|
|
118
159
|
|
|
119
|
-
},{"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/assert":22}],2:[function(require,module,exports){
|
|
160
|
+
},{"@barchart/common-js/lang/Enum":19,"@barchart/common-js/lang/assert":22,"uuid":28}],2:[function(require,module,exports){
|
|
120
161
|
const array = require('@barchart/common-js/lang/array'),
|
|
121
162
|
assert = require('@barchart/common-js/lang/assert'),
|
|
122
163
|
Day = require('@barchart/common-js/lang/Day'),
|
|
@@ -858,6 +899,8 @@ module.exports = (() => {
|
|
|
858
899
|
|
|
859
900
|
return map;
|
|
860
901
|
}, { });
|
|
902
|
+
|
|
903
|
+
Object.keys(this._portfolios).forEach(key => updateEmptyPortfolioGroups.call(this, this._portfolios[key]));
|
|
861
904
|
}
|
|
862
905
|
|
|
863
906
|
/**
|
|
@@ -919,6 +962,8 @@ module.exports = (() => {
|
|
|
919
962
|
});
|
|
920
963
|
}
|
|
921
964
|
});
|
|
965
|
+
|
|
966
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
922
967
|
}
|
|
923
968
|
}
|
|
924
969
|
|
|
@@ -934,6 +979,8 @@ module.exports = (() => {
|
|
|
934
979
|
|
|
935
980
|
this.startTransaction(() => {
|
|
936
981
|
getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => item.updatePortfolio(portfolio));
|
|
982
|
+
|
|
983
|
+
updateEmptyPortfolioGroups.call(this, portfolio);
|
|
937
984
|
});
|
|
938
985
|
}
|
|
939
986
|
|
|
@@ -1470,6 +1517,17 @@ module.exports = (() => {
|
|
|
1470
1517
|
});
|
|
1471
1518
|
}
|
|
1472
1519
|
|
|
1520
|
+
|
|
1521
|
+
function updateEmptyPortfolioGroups(portfolio) {
|
|
1522
|
+
Object.keys(this._trees).forEach((key) => {
|
|
1523
|
+
this._trees[key].walk((group) => {
|
|
1524
|
+
if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) && group.getIsEmpty()) {
|
|
1525
|
+
group.updatePortfolio(portfolio);
|
|
1526
|
+
}
|
|
1527
|
+
}, true, false);
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1473
1531
|
function getPositionItemsForPortfolio(items, portfolio) {
|
|
1474
1532
|
return items.reduce((positionItems, item) => {
|
|
1475
1533
|
if (item.position.portfolio === portfolio) {
|
|
@@ -1605,6 +1663,9 @@ const array = require('@barchart/common-js/lang/array'),
|
|
|
1605
1663
|
|
|
1606
1664
|
const InstrumentType = require('./../data/InstrumentType');
|
|
1607
1665
|
|
|
1666
|
+
const PositionLevelDefinition = require('./definitions/PositionLevelDefinition'),
|
|
1667
|
+
PositionLevelType = require('./definitions/PositionLevelType');
|
|
1668
|
+
|
|
1608
1669
|
module.exports = (() => {
|
|
1609
1670
|
'use strict';
|
|
1610
1671
|
|
|
@@ -1948,6 +2009,36 @@ module.exports = (() => {
|
|
|
1948
2009
|
}
|
|
1949
2010
|
}
|
|
1950
2011
|
|
|
2012
|
+
/**
|
|
2013
|
+
* Updates the portfolio data. For example, a portfolio's name might change. This
|
|
2014
|
+
* function only affects {@link PositionLevelType.PORTFOLIO} groups.
|
|
2015
|
+
*
|
|
2016
|
+
* @public
|
|
2017
|
+
* @param {Object} portfolio
|
|
2018
|
+
*/
|
|
2019
|
+
updatePortfolio(portfolio) {
|
|
2020
|
+
if (this._definition.type !== PositionLevelType.PORTFOLIO || this._key !== PositionLevelDefinition.getKeyForPortfolioGroup(portfolio) || !this.getIsEmpty()) {
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
const descriptionSelector = this._definition.descriptionSelector;
|
|
2025
|
+
|
|
2026
|
+
this._description = descriptionSelector(this._items[0]);
|
|
2027
|
+
|
|
2028
|
+
this._dataActual.description = this._description;
|
|
2029
|
+
this._dataFormat.description = this._description;
|
|
2030
|
+
|
|
2031
|
+
let portfolioType;
|
|
2032
|
+
|
|
2033
|
+
if (portfolio.miscellany && portfolio.miscellany.data.type && portfolio.miscellany.data.type.value) {
|
|
2034
|
+
portfolioType = portfolio.miscellany.data.type.value;
|
|
2035
|
+
} else {
|
|
2036
|
+
portfolioType = null;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
this._dataFormat.portfolioType = portfolioType;
|
|
2040
|
+
}
|
|
2041
|
+
|
|
1951
2042
|
/**
|
|
1952
2043
|
* Causes all aggregated data to be recalculated (assuming the group has not
|
|
1953
2044
|
* been suspended).
|
|
@@ -1975,6 +2066,16 @@ module.exports = (() => {
|
|
|
1975
2066
|
calculateMarketPercent(this, this._container.getForexQuotes(), true);
|
|
1976
2067
|
}
|
|
1977
2068
|
|
|
2069
|
+
/**
|
|
2070
|
+
* Indicates if the group contains any items.
|
|
2071
|
+
*
|
|
2072
|
+
* @public
|
|
2073
|
+
* @returns {boolean}
|
|
2074
|
+
*/
|
|
2075
|
+
getIsEmpty() {
|
|
2076
|
+
return this._items.length === 0;
|
|
2077
|
+
}
|
|
2078
|
+
|
|
1978
2079
|
/**
|
|
1979
2080
|
* Adds an observer for change in the market percentage of the group.
|
|
1980
2081
|
*
|
|
@@ -2359,7 +2460,7 @@ module.exports = (() => {
|
|
|
2359
2460
|
return PositionGroup;
|
|
2360
2461
|
})();
|
|
2361
2462
|
|
|
2362
|
-
},{"./../data/InstrumentType":1,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/formatter":23,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],6:[function(require,module,exports){
|
|
2463
|
+
},{"./../data/InstrumentType":1,"./definitions/PositionLevelDefinition":7,"./definitions/PositionLevelType":8,"@barchart/common-js/collections/specialized/DisposableStack":14,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17,"@barchart/common-js/lang/Disposable":18,"@barchart/common-js/lang/Rate":20,"@barchart/common-js/lang/array":21,"@barchart/common-js/lang/assert":22,"@barchart/common-js/lang/formatter":23,"@barchart/common-js/lang/is":24,"@barchart/common-js/messaging/Event":26}],6:[function(require,module,exports){
|
|
2363
2464
|
const array = require('@barchart/common-js/lang/array'),
|
|
2364
2465
|
assert = require('@barchart/common-js/lang/assert'),
|
|
2365
2466
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
@@ -3350,14 +3451,31 @@ module.exports = function () {
|
|
|
3350
3451
|
}
|
|
3351
3452
|
|
|
3352
3453
|
/**
|
|
3353
|
-
*
|
|
3454
|
+
* Gets the root node.
|
|
3354
3455
|
*
|
|
3355
3456
|
* @public
|
|
3356
|
-
* @returns {Tree
|
|
3457
|
+
* @returns {Tree}
|
|
3357
3458
|
*/
|
|
3358
3459
|
|
|
3359
3460
|
|
|
3360
3461
|
_createClass(Tree, [{
|
|
3462
|
+
key: 'getRoot',
|
|
3463
|
+
value: function getRoot() {
|
|
3464
|
+
if (this.getIsRoot()) {
|
|
3465
|
+
return this;
|
|
3466
|
+
} else {
|
|
3467
|
+
return this._parent.getRoot();
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
|
|
3471
|
+
/**
|
|
3472
|
+
* Returns the parent node. If this is the root node, a null value is returned.
|
|
3473
|
+
*
|
|
3474
|
+
* @public
|
|
3475
|
+
* @returns {Tree|null}
|
|
3476
|
+
*/
|
|
3477
|
+
|
|
3478
|
+
}, {
|
|
3361
3479
|
key: 'getParent',
|
|
3362
3480
|
value: function getParent() {
|
|
3363
3481
|
return this._parent;
|
|
@@ -7844,6 +7962,211 @@ module.exports = function () {
|
|
|
7844
7962
|
})(this);
|
|
7845
7963
|
|
|
7846
7964
|
},{}],28:[function(require,module,exports){
|
|
7965
|
+
var v1 = require('./v1');
|
|
7966
|
+
var v4 = require('./v4');
|
|
7967
|
+
|
|
7968
|
+
var uuid = v4;
|
|
7969
|
+
uuid.v1 = v1;
|
|
7970
|
+
uuid.v4 = v4;
|
|
7971
|
+
|
|
7972
|
+
module.exports = uuid;
|
|
7973
|
+
|
|
7974
|
+
},{"./v1":31,"./v4":32}],29:[function(require,module,exports){
|
|
7975
|
+
/**
|
|
7976
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
7977
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
7978
|
+
*/
|
|
7979
|
+
var byteToHex = [];
|
|
7980
|
+
for (var i = 0; i < 256; ++i) {
|
|
7981
|
+
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
7982
|
+
}
|
|
7983
|
+
|
|
7984
|
+
function bytesToUuid(buf, offset) {
|
|
7985
|
+
var i = offset || 0;
|
|
7986
|
+
var bth = byteToHex;
|
|
7987
|
+
return bth[buf[i++]] + bth[buf[i++]] +
|
|
7988
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
7989
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
7990
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
7991
|
+
bth[buf[i++]] + bth[buf[i++]] + '-' +
|
|
7992
|
+
bth[buf[i++]] + bth[buf[i++]] +
|
|
7993
|
+
bth[buf[i++]] + bth[buf[i++]] +
|
|
7994
|
+
bth[buf[i++]] + bth[buf[i++]];
|
|
7995
|
+
}
|
|
7996
|
+
|
|
7997
|
+
module.exports = bytesToUuid;
|
|
7998
|
+
|
|
7999
|
+
},{}],30:[function(require,module,exports){
|
|
8000
|
+
(function (global){
|
|
8001
|
+
// Unique ID creation requires a high quality random # generator. In the
|
|
8002
|
+
// browser this is a little complicated due to unknown quality of Math.random()
|
|
8003
|
+
// and inconsistent support for the `crypto` API. We do the best we can via
|
|
8004
|
+
// feature-detection
|
|
8005
|
+
var rng;
|
|
8006
|
+
|
|
8007
|
+
var crypto = global.crypto || global.msCrypto; // for IE 11
|
|
8008
|
+
if (crypto && crypto.getRandomValues) {
|
|
8009
|
+
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
|
|
8010
|
+
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
|
|
8011
|
+
rng = function whatwgRNG() {
|
|
8012
|
+
crypto.getRandomValues(rnds8);
|
|
8013
|
+
return rnds8;
|
|
8014
|
+
};
|
|
8015
|
+
}
|
|
8016
|
+
|
|
8017
|
+
if (!rng) {
|
|
8018
|
+
// Math.random()-based (RNG)
|
|
8019
|
+
//
|
|
8020
|
+
// If all else fails, use Math.random(). It's fast, but is of unspecified
|
|
8021
|
+
// quality.
|
|
8022
|
+
var rnds = new Array(16);
|
|
8023
|
+
rng = function() {
|
|
8024
|
+
for (var i = 0, r; i < 16; i++) {
|
|
8025
|
+
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
|
8026
|
+
rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
|
8027
|
+
}
|
|
8028
|
+
|
|
8029
|
+
return rnds;
|
|
8030
|
+
};
|
|
8031
|
+
}
|
|
8032
|
+
|
|
8033
|
+
module.exports = rng;
|
|
8034
|
+
|
|
8035
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
8036
|
+
},{}],31:[function(require,module,exports){
|
|
8037
|
+
var rng = require('./lib/rng');
|
|
8038
|
+
var bytesToUuid = require('./lib/bytesToUuid');
|
|
8039
|
+
|
|
8040
|
+
// **`v1()` - Generate time-based UUID**
|
|
8041
|
+
//
|
|
8042
|
+
// Inspired by https://github.com/LiosK/UUID.js
|
|
8043
|
+
// and http://docs.python.org/library/uuid.html
|
|
8044
|
+
|
|
8045
|
+
// random #'s we need to init node and clockseq
|
|
8046
|
+
var _seedBytes = rng();
|
|
8047
|
+
|
|
8048
|
+
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
8049
|
+
var _nodeId = [
|
|
8050
|
+
_seedBytes[0] | 0x01,
|
|
8051
|
+
_seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
|
|
8052
|
+
];
|
|
8053
|
+
|
|
8054
|
+
// Per 4.2.2, randomize (14 bit) clockseq
|
|
8055
|
+
var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
|
|
8056
|
+
|
|
8057
|
+
// Previous uuid creation time
|
|
8058
|
+
var _lastMSecs = 0, _lastNSecs = 0;
|
|
8059
|
+
|
|
8060
|
+
// See https://github.com/broofa/node-uuid for API details
|
|
8061
|
+
function v1(options, buf, offset) {
|
|
8062
|
+
var i = buf && offset || 0;
|
|
8063
|
+
var b = buf || [];
|
|
8064
|
+
|
|
8065
|
+
options = options || {};
|
|
8066
|
+
|
|
8067
|
+
var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
|
|
8068
|
+
|
|
8069
|
+
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
|
|
8070
|
+
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
|
|
8071
|
+
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
8072
|
+
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
8073
|
+
var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
|
|
8074
|
+
|
|
8075
|
+
// Per 4.2.1.2, use count of uuid's generated during the current clock
|
|
8076
|
+
// cycle to simulate higher resolution clock
|
|
8077
|
+
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
|
|
8078
|
+
|
|
8079
|
+
// Time since last uuid creation (in msecs)
|
|
8080
|
+
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
|
|
8081
|
+
|
|
8082
|
+
// Per 4.2.1.2, Bump clockseq on clock regression
|
|
8083
|
+
if (dt < 0 && options.clockseq === undefined) {
|
|
8084
|
+
clockseq = clockseq + 1 & 0x3fff;
|
|
8085
|
+
}
|
|
8086
|
+
|
|
8087
|
+
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
|
8088
|
+
// time interval
|
|
8089
|
+
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
|
8090
|
+
nsecs = 0;
|
|
8091
|
+
}
|
|
8092
|
+
|
|
8093
|
+
// Per 4.2.1.2 Throw error if too many uuids are requested
|
|
8094
|
+
if (nsecs >= 10000) {
|
|
8095
|
+
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
|
8096
|
+
}
|
|
8097
|
+
|
|
8098
|
+
_lastMSecs = msecs;
|
|
8099
|
+
_lastNSecs = nsecs;
|
|
8100
|
+
_clockseq = clockseq;
|
|
8101
|
+
|
|
8102
|
+
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
|
8103
|
+
msecs += 12219292800000;
|
|
8104
|
+
|
|
8105
|
+
// `time_low`
|
|
8106
|
+
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
8107
|
+
b[i++] = tl >>> 24 & 0xff;
|
|
8108
|
+
b[i++] = tl >>> 16 & 0xff;
|
|
8109
|
+
b[i++] = tl >>> 8 & 0xff;
|
|
8110
|
+
b[i++] = tl & 0xff;
|
|
8111
|
+
|
|
8112
|
+
// `time_mid`
|
|
8113
|
+
var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
|
8114
|
+
b[i++] = tmh >>> 8 & 0xff;
|
|
8115
|
+
b[i++] = tmh & 0xff;
|
|
8116
|
+
|
|
8117
|
+
// `time_high_and_version`
|
|
8118
|
+
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
|
|
8119
|
+
b[i++] = tmh >>> 16 & 0xff;
|
|
8120
|
+
|
|
8121
|
+
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
|
8122
|
+
b[i++] = clockseq >>> 8 | 0x80;
|
|
8123
|
+
|
|
8124
|
+
// `clock_seq_low`
|
|
8125
|
+
b[i++] = clockseq & 0xff;
|
|
8126
|
+
|
|
8127
|
+
// `node`
|
|
8128
|
+
var node = options.node || _nodeId;
|
|
8129
|
+
for (var n = 0; n < 6; ++n) {
|
|
8130
|
+
b[i + n] = node[n];
|
|
8131
|
+
}
|
|
8132
|
+
|
|
8133
|
+
return buf ? buf : bytesToUuid(b);
|
|
8134
|
+
}
|
|
8135
|
+
|
|
8136
|
+
module.exports = v1;
|
|
8137
|
+
|
|
8138
|
+
},{"./lib/bytesToUuid":29,"./lib/rng":30}],32:[function(require,module,exports){
|
|
8139
|
+
var rng = require('./lib/rng');
|
|
8140
|
+
var bytesToUuid = require('./lib/bytesToUuid');
|
|
8141
|
+
|
|
8142
|
+
function v4(options, buf, offset) {
|
|
8143
|
+
var i = buf && offset || 0;
|
|
8144
|
+
|
|
8145
|
+
if (typeof(options) == 'string') {
|
|
8146
|
+
buf = options == 'binary' ? new Array(16) : null;
|
|
8147
|
+
options = null;
|
|
8148
|
+
}
|
|
8149
|
+
options = options || {};
|
|
8150
|
+
|
|
8151
|
+
var rnds = options.random || (options.rng || rng)();
|
|
8152
|
+
|
|
8153
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
8154
|
+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
8155
|
+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
8156
|
+
|
|
8157
|
+
// Copy bytes to buffer, if provided
|
|
8158
|
+
if (buf) {
|
|
8159
|
+
for (var ii = 0; ii < 16; ++ii) {
|
|
8160
|
+
buf[i + ii] = rnds[ii];
|
|
8161
|
+
}
|
|
8162
|
+
}
|
|
8163
|
+
|
|
8164
|
+
return buf || bytesToUuid(rnds);
|
|
8165
|
+
}
|
|
8166
|
+
|
|
8167
|
+
module.exports = v4;
|
|
8168
|
+
|
|
8169
|
+
},{"./lib/bytesToUuid":29,"./lib/rng":30}],33:[function(require,module,exports){
|
|
7847
8170
|
const Day = require('@barchart/common-js/lang/Day'),
|
|
7848
8171
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
7849
8172
|
|
|
@@ -8200,7 +8523,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
8200
8523
|
});
|
|
8201
8524
|
});
|
|
8202
8525
|
|
|
8203
|
-
},{"./../../../lib/data/PositionSummaryFrame":2,"./../../../lib/data/TransactionType":3,"@barchart/common-js/lang/Day":16,"@barchart/common-js/lang/Decimal":17}],
|
|
8526
|
+
},{"./../../../lib/data/PositionSummaryFrame":2,"./../../../lib/data/TransactionType":3,"@barchart/common-js/lang/Day":16,"@barchart/common-js/lang/Decimal":17}],34:[function(require,module,exports){
|
|
8204
8527
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
8205
8528
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
8206
8529
|
|
|
@@ -8310,4 +8633,4 @@ describe('When a position container data is gathered', () => {
|
|
|
8310
8633
|
});
|
|
8311
8634
|
});
|
|
8312
8635
|
|
|
8313
|
-
},{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":4,"./../../../lib/processing/definitions/PositionLevelDefinition":7,"./../../../lib/processing/definitions/PositionLevelType":8,"./../../../lib/processing/definitions/PositionTreeDefinition":9,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17}]},{},[
|
|
8636
|
+
},{"./../../../lib/data/InstrumentType":1,"./../../../lib/processing/PositionContainer":4,"./../../../lib/processing/definitions/PositionLevelDefinition":7,"./../../../lib/processing/definitions/PositionLevelType":8,"./../../../lib/processing/definitions/PositionTreeDefinition":9,"@barchart/common-js/lang/Currency":15,"@barchart/common-js/lang/Decimal":17}]},{},[33,34]);
|